|
|
|
Posted
15 days
ago
Free Hacking night:11.06.2013, Utrecht JavaEE 7 Meets HTML 5 and AngularJS Workshops: 24.06-26.06.13, Munich Java EE Summit Conference: JayDay, 02.07.2013, Munich Nothing Compares To …Java EE 7 Jug Session: 02.07.2013, Nürnberg JavaEE
... [More]
7 And Why There Is No More Room For Overengineering (Livehacking) JavaEE Tribe Gathering :-) 22.7-26.7.2013 Modular Java EE 7 Workshops--Airhacks From "absolute beginning" over JavaEE 7 architectures to User Interfaces and HTML 5
See you at Java EE Workshops at MUC Airport!
Real World Java EE Workshops [Airport Munich]> [Less]
|
|
Posted
15 days
ago
<p><i style="line-height: 18px;">This blog post has been contributed by our NetBeans PHP user </i><i style="line-height: 18px;"><b>Junichi Yamamoto</b></i><i style="line-height: 18px;"> who has created
... [More]
several plugins for NetBeans PHP support.</i><span style="line-height: 18px;"><i> H</i></span><em style="line-height: 18px;">e would like to tell you a few words about one of his NetBeans plugin. Thanks, a lot Junichi!</em></p><hr /> <p> Hi all, I have created a plugin for <a href="https://github.com/fabpot/PHP-CS-Fixer">PHP CS Fixer</a>. Today, I introduce features of this plugin briefly. Now, this plugin is available on Plugin Portal and it works with <b>NetBeans 7.3</b>. Please <a href="http://plugins.netbeans.org/plugin/49042/php-cs-fixer">download</a> if you are interested in this. </p> <p> At first, we have to set the path of PHP CS Fixer to Options(Tools > Options > PHP > PHP CS Fixer). </p> <p><img src="https://blogs.oracle.com/netbeansphp/resource/article_images/php-cs-fixer-options.png" alt="options" /></p> <p> Then, if we would like to change settings in each projects, we can use project settings.(open the project properties, and we can find PHP CS Fixer category) </p> <p><img src="https://blogs.oracle.com/netbeansphp/resource/article_images/php-cs-fixer-project-properties.png" alt="project properties" /></p> <p> Available commands are the followings: <b>fix</b>, <b>fix --dry-run</b>, <b>self-update</b> <br /> We can run these with context menu. (Right-click file, directory) </p> <p><img src="https://blogs.oracle.com/netbeansphp/resource/article_images/php-cs-fixer-commands.png" alt="commands" /></p> <p><img src="https://blogs.oracle.com/netbeansphp/resource/article_images/php-cs-fixer-output-window.png" alt="output window" /></p> <p> If you have some issues, please let me know via <a href="https://bitbucket.org/junichi11/netbeans-php-cs-fixer/issues?status=new&status=open">issue tracker</a>. (Don't submit to bugzilla in NetBeans) </p> <p> Thanks,<br /> Junichi </p> [Less]
|
|
Posted
15 days
ago
OOliba Modeler, by Ooliba, enables insurance companies to build financial risk models in an intuitive way with a graphic interface. Its modular architecture enables modeling for risk life, non-life, and health. It is created on the NetBeans Platform.
|
|
Posted
16 days
ago
Frontiersman, by B6 Sigma, enables companies to continuously monitor their manufacturing processes, allowing them to identify flaws early on and eliminating costly final inspections. It is created on the NetBeans Platform.
|
|
Posted
17 days
ago
Recently there was a question on the NetBeans Platform mailing list (if you're creating NetBeans Platform applications and are not on the mailing list, you're missing a lot of good discussions and code samples) about custom DataObjects, Navigators
... [More]
, and Visual Library satellite views.
So I started with the code in the NetBeans File Type Integration tutorial. I added a Navigator, in a separate module, just to prove the point that it can work that way. Rather than the Navigator somehow finding the MultiViewElement, and then getting the Scene from it, the DataObject has the Scene in its Lookup. That enables the MultiViewElement to get the Scene from the DataObject, while the Navigator gets it from the selection.
Also, a requirement is that when the Source is open, i.e., the Source toggle button has been clicked, the Navigator should be emptied, i.e., the satellite view should not show anything. To achieve that, I add/remove the Scene from the DataObject's Lookup in the MultiViewElement's componentShowing/componentHidden. That's possible because I put the DataObject's InstanceContent into its own Lookup (maybe unorthodox or plain wrong but it works), then retrieve the InstanceContent in the MultiViewElement and add/remove the Scene from it.
The code is here:
https://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.3/misc/ABCFileTypeNavigator [Less]
|
|
Posted
18 days
ago
Global Information Solutions is a value added services provider that specializes in content delivery via USSD, SMS, and MMS. Based on their experience, the company saw that it was crucial to deploy stable services quickly to market, especially in a
... [More]
climate where multiple providers and operators already exist. If this is not achieved, there is a risk of competition gaining market share because of better first-to-market approaches. To help meet these needs, the company has developed a Product Delivery Platform and a Product Designer.
The Product Designer is a tool created on the NetBeans Platform. It helps design and develop services to be launched to the customer. It is a product flow designer geared towards the quick and easy development and deployment of telecom value added services, enabling telecom operators to create products/services triggered by SMS/USSD and related protocols.
When completed, the product is deployed to the Product Delivery Platform. The platform and designer are developed around the concept of a service as a collection of products, accessible via unified service codes from multiple sources.
NetBeans Platform Initially, the idea was to create a web application or a from-scratch Swing application, but there were too many limitations and complexities in order to get the application out quickly. There was a need for an application that the user could take home and continue working on, regardless of what they were doing. In addition, there was a need to develop components from scratch.
Most developers were already familiar with NetBeans IDE and its API comes with an array of easy to use frameworks and components. So, the decision was made to go in this direction. The NetBeans Platform update mechanism is also great, especially when there are releases that need to be pushed to clients.
Currently, the solution is used internally in the company, while an external VAS provider is also using it. The total software package is targeted towards VAS providers and telecom operators but is not limited to them. [Less]
|
|
Posted
18 days
ago
The question of the day comes from Winston Dehaney: Is there any way to handle what happens whenever I try to open a file. The file is a serialised ArrayList. when I open the file, it is de-serialised to an array then the
... [More]
information from the array is opened. The functionality for the actions to perform when opening this file and how to show it in an editor is already complete. I just wanted to be able to override the functionality in opening a file. I started by simulating the problem using the code found here, i.e., I created a new Action that creates a serialized file consisting of a list of Patients:
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle.Messages;
@ActionID( category = "Tools", id = "org.patients.ser.SerializeAction") @ActionRegistration( displayName = "#CTL_SerializeAction") @ActionReference( path = "Menu/File", position = -100) @Messages("CTL_SerializeAction=Serialize") public final class SerializeAction implements ActionListener {
List<Patient> pList = new ArrayList<>();
@Override public void actionPerformed(ActionEvent e) { pList.add(new Patient("Tom")); pList.add(new Patient("Dick")); pList.add(new Patient("Harry")); try { savePatientList(); } catch (FileNotFoundException ex) { } }
private void savePatientList() throws FileNotFoundException { try { ObjectOutputStream os; //I created a "Serialized" folder in the layer, //so I know that the "Serialized" folder exists here: try (FileOutputStream fs = new FileOutputStream( FileUtil.toFile(FileUtil.getConfigFile("Serialized"). createData("Patients.ser")))) { os = new ObjectOutputStream(fs); os.writeObject(pList); } os.close(); System.out.println("Saved!"); } catch (IOException ex) { } }
} This leaves me with a "Patients.ser" file. And here is another Action, for deserializing the file and doing something with its content. Here, a TopComponent is created for each Patient in the List, but anything else could be done, of course.
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.util.ArrayList; import java.util.List; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; import org.openide.windows.TopComponent;
@ActionID( category = "Build", id = "org.patients.ser.DeserializeAction") @ActionRegistration( displayName = "#CTL_DeserializeAction") @ActionReference( path = "Menu/File", position = 0) @Messages("CTL_DeserializeAction=Deserialize") public final class DeserializeAction implements ActionListener {
private List<Patient> pList = new ArrayList<>();
@Override public void actionPerformed(ActionEvent e) { //Do some checking here to make sure the Serialized folder exists //and that it contains the ser files you're interested in: for (FileObject serialized : FileUtil.getConfigRoot().getFileObject("Serialized").getChildren()) { try { loadPatientList(serialized.getInputStream()); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } } }
private void loadPatientList(InputStream fs) { ObjectInputStream is; try { is = new ObjectInputStream(fs); pList = (List<Patient>) is.readObject(); for (Patient p : pList) { //As an example, //you can see that one TopComponent //is created for each Patient found in the List: TopComponent tc = new TopComponent(); tc.setDisplayName(p.getName()); tc.open(); tc.requestActive(); } fs.close(); is.close(); } catch (IOException | ClassNotFoundException ex) { } }
} Finally, to complete the scenario, here is the Patient class used by both Actions above.
public class Patient implements Serializable {
String name;
public Patient(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
} A different approach is to create new File Type support (there's a tutorial and a wizard to help you do that) for SER files, using any MIME Type name you prefer, e.g., "application/x-ser". Then define the DataObject such that a text editor is not opened, assuming you don't want a text editor, while implementing Openable so that when the file is opened (via the "Open" action or by double-clicking on it), the same result as the above is produced:
public class SerDataObject extends MultiDataObject implements Openable {
private List<Patient> pList = new ArrayList<>();
public SerDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { super(pf, loader); }
@Override public void open() { try { loadPatientList(getPrimaryFile().getInputStream()); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } }
private void loadPatientList(InputStream fs) { ObjectInputStream is; try { is = new ObjectInputStream(fs); pList = (List<Patient>) is.readObject(); for (Patient p : pList) { //As an example, //you can see that one TopComponent //is created for each Patient found in the List: TopComponent tc = new TopComponent(); tc.setDisplayName(p.getName()); tc.open(); tc.requestActive(); } fs.close(); is.close(); } catch (IOException | ClassNotFoundException ex) { } }
} [Less]
|
|
Posted
20 days
ago
If a CloneableTopComponent has a DataObject in its Lookup, the DataObject will be added to "File | Open Recent File", after the CloneableTopComponent has closed. The relevant classes are in the "org.netbeans.modules.openfile" package in the
... [More]
NetBeans sources. To include the package in your application, put a checkmark next to "User Utilities" in the "ide" cluster, in the Project Properties dialog of your application.
The RecentFiles class, in the "org.netbeans.modules.openfile" package, maintains a list of recently closed files. In the Installer class of the module, a call is made to RecentFiles.init(), which adds a WindowListener to the TopComponent.Registry. Whenever a TopComponent closes, its DataObject is added to the recent files list, while it is removed when the TopComponent opens.
However, here's the catch:
private static void addFile(TopComponent tc) { if (tc instanceof CloneableTopComponent) { addFile(obtainPath(tc)); } } Let's say that you're creating a GUI editor (i.e., not a text editor). You have a TopComponent, within which you have GUI components, on top of a DataObject. I.e., there's an actual file beneath the TopComponent but you don't want a text editor to be available to the user. The above code shows that if you want your DataObject to be included in "File | Open Recent File", you need to extend CloneableTopComponent, rather than simply TopComponent.
Next, make very sure that there's a DataObject in the Lookup of the TopComponent. Otherwise the code below, again in the RecentFiles class, will fail:
private static String obtainPath(TopComponent tc) { DataObject dObj = tc.getLookup().lookup(DataObject.class); if (dObj != null) { FileObject fo = dObj.getPrimaryFile(); if (fo != null) { return convertFile2Path(fo); } } return null; } So, now you have a CloneableTopComponent with a DataObject in its Lookup and, when the CloneableTopComponent closes, its DataObject is added to "File | Open Recent File". All seems to be well and good at this point. However, there's still a catch. Because you're extending CloneableTopComponent, the Clone action in the tab of your CloneableTopComponent is automatically enabled. When the user invokes that action, you need to be sure to have a no-arg constructor in your CloneableTopComponent, because that's what the Clone action invokes. The solution to this is simply to get the current DataObject from the Lookup and pass that into the constructor that receives the DataObject.
At the same time, though, another problem is that you need to make sure that when the user opens your CloneableTopComponent a subsequent time for the same file, the same CloneableTopComponent should be opened, rather than creating a new one. And possibly the reopening is done from the Favorites window, which automatically has the DataObject in its Lookup when you select the file. Hence, you need to put a new Object, I've named it Reopenable, into the Lookup of the CloneableTopComponent, so that when a new attempt is made to open it, the correct one is found.
In short, I end up with a file editor as follows:
@TopComponent.Description( preferredID = "MyFileEditor", iconBase = "com/example/singleview/filetype/myImageIcon.png", persistenceType = TopComponent.PERSISTENCE_NEVER) @TopComponent.Registration( mode = "editor", openAtStartup = false) @ActionID( category = "Window", id = "org.example.singleview.filetype.MyFileEditor") @ActionReferences({ @ActionReference( path = "Menu/Window", position = 0), @ActionReference( path = "Toolbars/File", position = 0) }) @Messages({ "CTL_OpenMyImageAction=My Image Data"}) public class MyFileEditor extends CloneableTopComponent {
public MyFileEditor() { this(Utilities.actionsGlobalContext().lookup(MyCustomDataObject.class)); }
public MyFileEditor(final MyCustomDataObject mcdo) { initComponents(); setDisplayName(mcdo.getPrimaryFile().getNameExt()); associateLookup(Lookups.fixed(mcdo, new Reopenable() { @Override public MyCustomDataObject reopen() { return mcdo; } })); }
... ... ... And here's the related DataObject (minus all the annotations at the top):
public class MyCustomDataObject extends MultiDataObject implements Openable {
public MyCustomDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { super(pf, loader); }
@Override public void open() { TopComponent tc = findTopComponent(); if (tc == null) { tc = new MyFileEditor(this); tc.open(); } tc.requestActive(); }
private TopComponent findTopComponent() { Set<TopComponent> openTopComponents = WindowManager.getDefault().getRegistry().getOpened(); for (TopComponent tc : openTopComponents) { if (tc.getLookup().lookup(Reopenable.class) != null && tc.getLookup().lookup(Reopenable.class).reopen() == this.getLookup().lookup(MyCustomDataObject.class)) { return tc; } } return null; }
} [Less]
|
|
Posted
20 days
ago
A field denoted with the javax.persistence.Version annotation represents the state of the database at read (select) time. At the end of transaction the actual value of the entity is compared with the current value in the database and the entity is
... [More]
only going to be written back to the database in case both values are matching. If both are not equal the update "fails" (no rows are going to be updated) and javax.persistence.OptimisticLockException is thrown at the end of transactions. The unchecked OptimisticLockException causes transaction's rollback.
@Entity public class SomeEntity {
@Id private String name;
private String description;
@Version private long version;
Each database write operation also changes the version column in the DB, entity manipulations on the other hand, do not change the @Version JPA-entity field. Optimistic locking effectively prevents overriding changed columns in the database with stale values.
An occurrence of OptimisticLockException usually is an indicator of "process bottlenecks". Several users compete for the same data set, the first update will succeed, all other attempts will raise exceptions. This is very similar to merge conflicts in a source code management tool like svn, git or hg. Although there is a strategy to automatically resolve conflicts called "Override and Commit", it is not considered as best practice.
The only feasible strategy in the SCM case is manual merging and testing. Use cases in enterprise applications have a more narrow scope, so you could choose from several strategies:
First update wins Last update wins Manual merging
Each choice has a big impact on the business logic, so domain experts, end users or someone with business knowledge needs to be involved. Handling javax.persistence.OptimisticLockException generically (with e.g. repeating and reloading) is only viable for simple technical use cases (e.g. primary key generation).
Retrying business transactions as a generic recovery strategy for the OptimisticLockException is only feasible for simplistic cases. Sophisticated use cases usually require merging and so User Interface adjustments.
[See also an in-depth discussion in the "Real World Java EE Patterns--Rethinking Best Practices" book (Second Iteration, "Green Book"), page 21 in, chapter "Locking for Consistency"]
See you at Java EE Workshops at MUC Airport (particularly the Effective and Architecture Days)!
Thanks Johny Newald for his comment and so idea for this post.
Real World Java EE Workshops [Airport Munich]> [Less]
|
|
Posted
21 days
ago
The introduction of Java EE 7 is a free online event where you can connect with Java users from all over the world as you learn about the power and capabilities of Java EE 7. Join us for presentations from Oracle technical leaders and Java users from
... [More]
both large and small enterprises, deep dives into the new JSRs, and scheduled chats with Java experts.
Plus, the highlights of NetBeans IDE support for Java EE 7 will be demonstrated during the event! [Less]
|