Search Results

Search found 227 results on 10 pages for 'geertjan'.

Page 8/10 | < Previous Page | 4 5 6 7 8 9 10  | Next Page >

  • Showing an Action on a TopComponent Node

    - by Geertjan
    Let's say you want to extend the tools in NetBeans IDE, specifically for TopComponents. When the user right-clicks in the Projects window (or Files window or Favorites window) on a Java class that extends TopComponent, a menu item should be available for branding the TopComponent. What "branding" entails is, at this stage, a secondary question. The primary question, from an implementation point of view, is "how do I create an action that is only shown when the user right-clicks on a TopComponent?" Here's the solution, in NetBeans IDE 7.2 (the "lazy" attribute, here set to false, is new in 7.2): import com.sun.source.tree.ClassTree; import com.sun.source.util.TreePathScanner; import java.awt.event.ActionEvent; import java.io.IOException; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JOptionPane; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.Task; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionReferences; import org.openide.awt.ActionRegistration; import org.openide.awt.DynamicMenuContent; import org.openide.loaders.DataObject; import org.openide.util.ContextAwareAction; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; import org.openide.util.Utilities; @ActionID(     category = "Tools", id = "org.tc.customizer.BrandTopComponentAction") @ActionRegistration(     displayName = "#CTL_BrandTopComponentAction",     lazy = false) @ActionReferences({     @ActionReference(path = "Loaders/text/x-java/Actions", position = 150) }) @Messages("CTL_BrandTopComponentAction=Brand") public final class BrandTopComponentAction extends AbstractAction implements ContextAwareAction {     private final DataObject dobj;     public BrandTopComponentAction() {         this(Utilities.actionsGlobalContext());     }     public BrandTopComponentAction(Lookup context) {         super(Bundle.CTL_BrandTopComponentAction());         this.dobj = context.lookup(DataObject.class);         //Enable the menu item only if we're dealing with a TopComponent         JavaSource javaSource = JavaSource.forFileObject(dobj.getPrimaryFile());         try {             javaSource.runUserActionTask(new ScanForTopComponentTask(this), true);         } catch (IOException ex) {             Exceptions.printStackTrace(ex);         }         //Hide the menu item if it isn't enabled:         putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);     }     @Override     public void actionPerformed(ActionEvent ev) {         JOptionPane.showMessageDialog(null, "Hurray, I am a TopComponent!");         //Now add your code for showing a dialog,         //where the dialog will display UI for branding the TopComponent somehow         //and retrieve those branding values         //and then change the TopComponent class accordingly.     }     @Override     public Action createContextAwareInstance(Lookup actionContext) {         return new BrandTopComponentAction(actionContext);     }     private static class ScanForTopComponentTask implements Task<CompilationController> {         private final BrandTopComponentAction action;         private ScanForTopComponentTask(BrandTopComponentAction action) {             this.action = action;         }         @Override         public void run(CompilationController compilationController) throws Exception {             compilationController.toPhase(Phase.ELEMENTS_RESOLVED);             new MemberVisitor(compilationController, action).scan(                     compilationController.getCompilationUnit(), null);         }     }     private static class MemberVisitor extends TreePathScanner<Void, Void> {         private CompilationInfo info;         private final AbstractAction action;         public MemberVisitor(CompilationInfo info, AbstractAction action) {             this.info = info;             this.action = action;         }         @Override         public Void visitClass(ClassTree t, Void v) {             Element el = info.getTrees().getElement(getCurrentPath());             if (el != null) {                 TypeElement te = (TypeElement) el;                 if (te.getSuperclass().toString().equals("org.openide.windows.TopComponent")){                     action.setEnabled(true);                 } else {                     action.setEnabled(false);                 }             }             return null;         }     } } The code above is the result of combining various tutorials found on the NetBeans Platform Learning Trail.

    Read the article

  • HTML Tidy for NetBeans IDE 7.4

    - by Geertjan
    The NetBeans HTML5 editor is pretty amazing, working on an extensive screencast on that right now, to be published soon. One thing missing is HTML Tidy integration, until now: As you can see, in this particular file, HTML Tidy finds 6 times more problems (OK, some of them maybe false negatives) than the standard NetBeans HTML hint infrastructure does. You can also run the scanner across the whole project or all projects. Only HTML files will be scanned by HTML Tidy (via JTidy) and you can click on items in the window above to jump to the line. Future enhancements will include error annotations and hint integration, some of which has already been addressed in this blog over the years. Download it from here: http://plugins.netbeans.org/plugin/51066/?show=true Sources are here. Contributions more than welcome: https://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.4/misc/HTMLTidy

    Read the article

  • Integrating Amazon S3 in Java via NetBeans IDE

    - by Geertjan
    To continue from yesterday, let's set up a scenario that enables us to make use of this drag/drop service in NetBeans IDE: The above service is applicable to Amazon S3, an Amazon storage provider that is typically used to store large binary files. In Amazon S3, every object stored is contained in a bucket. Buckets partition the namespace of objects stored in Amazon S3. More on buckets here. Let's use the tools in NetBeans IDE to create a Java application that accesses our Amazon S3 buckets. Create a Java application named "AmazonBuckets" with a main class named "AmazonBuckets". Open the main class and then drag the above service into the main method of the class. Now, NetBeans IDE will create all the other classes and the properties file that you see in the screenshot below. The first thing to do is to open the properties file above and enter the access key and secret: access_key=SOMETHINGsecret=SOMETHINGELSE Now you're all set up. Make sure to, of course, actually have some buckets available: Then rewrite the Java class to parse the XML that is returned via the generated code: package amazonbuckets;import java.io.ByteArrayInputStream;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.netbeans.saas.amazon.AmazonS3Service;import org.netbeans.saas.RestResponse;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;import org.xml.sax.SAXException;public class AmazonBuckets {    public static void main(String[] args) {        try {            RestResponse result = AmazonS3Service.getBuckets();            String dataAsString = result.getDataAsString();            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();            Document doc = dBuilder.parse(                    new InputSource(new ByteArrayInputStream(dataAsString.getBytes("utf-8"))));            NodeList bucketList = doc.getElementsByTagName("Bucket");            for (int i = 0; i < bucketList.getLength(); i++) {                Node node = bucketList.item(i);                System.out.println("Bucket Name: " + node.getFirstChild().getTextContent());            }        } catch (IOException | ParserConfigurationException | SAXException | DOMException ex) {        }    }}That's all. This is simpler to setup than the scenario described yesterday. Also notice that there are other Amazon S3 services you can interact with from your Java code, again after generating a heap of code after drag/drop into a Java source file: I tried the above, e.g., I created a new Amazon S3 bucket after dragging "createBucket", adding my credentials in the properties file, and then running the code that had been created. I.e., without adding a single line of code I was able to programmatically create new buckets. The above outlines a handy set of tools and techniques to use if you want to let your users store and access data in Amazon S3 buckets directly from the application you've created for them.

    Read the article

  • Advanced Experiments with JavaScript, CSS, HTML, JavaFX, and Java

    - by Geertjan
    Once you're embedding JavaScript, CSS, and HTML into your Java desktop application, via the JavaFX browser, a whole range of new possibilities open up to you. For example, here's an impressive page on-line, notice that you can drag items and drop them in new places: http://nettuts.s3.amazonaws.com/127_iNETTUTS/demo/index.html The source code of the above is provided too, so you can drop the various files directly into your NetBeans module and use the JavaFX WebEngine to load the HTML page into the JavaFX browser. Once the JavaFX browser is in a NetBeans TopComponent, you'll have the start of an off-line news composer, something like this: WebView view = new WebView(); view.setMinSize(widthDouble, heightDouble); view.setPrefSize(widthDouble, heightDouble); webengine = view.getEngine(); URL url = getClass().getResource("index.html"); webengine.load(url.toExternalForm()); webengine.getLoadWorker().stateProperty().addListener( new ChangeListener() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == State.SUCCEEDED) { Document document = (Document) webengine.executeScript("document"); NodeList list = document.getElementById("columns").getChildNodes(); for (int i = 0; i < list.getLength(); i++) { EventTarget et = (EventTarget) list.item(i); et.addEventListener("click", new EventListener() { @Override public void handleEvent(Event evt) { instanceContent.add(new Date()); } }, true); } } } }); The above is the code showing how, whenever a news item is clicked, the current date can be published into the Lookup. As you can see, I have a viewer component listening to the Lookup for dates.

    Read the article

  • Maven Command Line for NetBeans RCP Developers

    - by Geertjan
    In the ongoing work being done on Maven documentation support for NetBeans Platform developers, the tutorial describing how to use the Maven command line to set up and develop applications on the NetBeans Platform has ben updated: http://platform.netbeans.org/tutorials/nbm-maven-commandline.html An interesting next step after following the tutorial above is to... open the result into the free community edition of IntelliJ IDEA: It's not hard to register the JDK and Maven in IntelliJ IDEA and to then run your application directly from there. The point is that there's no requirement to use NetBeans IDE if you want to create applications on top of its framework.

    Read the article

  • Multi Level Security via Roles

    - by Geertjan
    I'm simulating a small scenario: Users can be dragged into roles; roles can be dragged into role groups. When a drop is made into a role group, a new role is created (WindowManager.getDefault().setRole("")). Then, when the user logs in, they log into a particular role. Depending on the role they log into, a different role group is assigned, which maps to a certain "role" in NetBeans Platform terms, i.e., the related level of security is applied and the related windows open.

    Read the article

  • Gesture Based NetBeans Tip Infrastructure

    - by Geertjan
    All/most/many gestures you make in NetBeans IDE are recorded in an XML file in your user directory, "var/log/uigestures", which is what makes the Key Promoter I outlined yesterday possible. The idea behind it is for analysis to be made possible, when you periodically pass the gestures data back to the NetBeans team. See http://statistics.netbeans.org for details. Since the gestures in the 'uigestures' file are identifiable by distinct loggers and other parameters, there's no end to the interesting things that one is able to do with it. While the NetBeans team can see which gestures are done most frequently, e.g., which kinds of projects are created most often, thus helping in prioritizing new features and bugs, etc, you as the user can, depending on who and how the initiative is taken, directly benefit from your collected data, too. Tim Boudreau, in a recent article, mentioned the usefulness of hippie completion. So, imagine that whenever you use code completion, a tip were to appear reminding you about hippie completion. And then you'd be able to choose whether you'd like to see the tip again or not, etc, i.e., customize the frequency of tips and the types of tips you'd like to be shown. And then, it could be taken a step further. The tip plugin could be set up in such a way that anyone would be able to register new tips per gesture. For example, maybe you have something very interesting to share about code completion in NetBeans. So, you'd create your own plugin in which there'd be an HTML file containing the text you'd like to have displayed whenever you (or your team members, or your students, maybe?) use code completion. Then you'd register that HTML file in plugin's layer file, in a subfolder dedicated to the specific gesture that you're interested in commenting on. The same is true, not just for NetBeans IDE, but for anyone creating their applications on top of the NetBeans Platform, of course.

    Read the article

  • Update 3 for "NetBeans Platform for Beginners"

    - by Geertjan
    The latest monthly update of NetBeans Platform for Beginners was released during the last few days. Without any question at all, this book is awesome. I love how it is a 'living book' and that on a monthly basis new updates are made available. In this particular update, as before, reader comments and questions have led to changes and enhancements in the book. In addition, there's now a tighter integration between the long list of samples on GitHub and the book, since wherever a sample relates to a text in the book, the book has a handy icon, so that you know when to hop over to GitHub to get a related sample. Do you have comments or questions about the book? That's what the feedback link is for: https://leanpub.com/nbp4beginners/feedback And there's also a free sample, just in case you'd like to get a feel for the book prior to buying it: http://samples.leanpub.com/nbp4beginners-sample.pdf If you're from a company where you're all sharing a single copy of the book, it would be great if you'd go back and support this great project (and hopefully encourage future books being written) by buying additional copies, ideally one for each developer. Let's show the authors that writing books on the NetBeans Platform is a really profitable thing to do (and I'm hoping they'll write one on Maven and the NetBeans Platform, as well)!

    Read the article

  • JGridView

    - by Geertjan
    JGrid was announced last week so I wanted to integrate it into a NetBeans Platform app. I.e., I'd like to use Nodes instead of the DefaultListModel that is supported natively, so that I can integrate with the Properties Window, for example: Here's how: import de.jgrid.JGrid; import java.beans.PropertyVetoException; import javax.swing.DefaultListModel; import javax.swing.JScrollPane; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.book.domain.Book; import org.openide.explorer.ExplorerManager; import org.openide.nodes.Node; import org.openide.util.Exceptions; public class JGridView extends JScrollPane { @Override public void addNotify() { super.addNotify(); final ExplorerManager em = ExplorerManager.find(this); if (em != null) { final JGrid grid = new JGrid(); Node root = em.getRootContext(); final Node[] nodes = root.getChildren().getNodes(); final Book[] books = new Book[nodes.length]; for (int i = 0; i < nodes.length; i++) { Node node = nodes[i]; books[i] = node.getLookup().lookup(Book.class); } grid.getCellRendererManager().setDefaultRenderer(new OpenLibraryGridRenderer()); grid.setModel(new DefaultListModel() { @Override public int getSize() { return books.length; } @Override public Object getElementAt(int i) { return books[i]; } }); grid.setUI(new BookshelfUI()); grid.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //Somehow compare the selected item //with the list of books and find a matching book: int selectedIndex = grid.getSelectedIndex(); for (int i = 0; i < nodes.length; i++) { String nodeName = books[i].getTitel(); if (String.valueOf(selectedIndex).equals(nodeName)) { try { em.setSelectedNodes(new Node[]{nodes[i]}); } catch (PropertyVetoException ex) { Exceptions.printStackTrace(ex); } } } } }); setViewportView(grid); } } } Above, you see references to OpenLibraryGridRenderer and BookshelfUI, both of which are part of the "JGrid-Bookshelf" sample in the JGrid download. The above is specific for Book objects, i.e., that's one of the samples that comes with the JGrid download. I need to make the above more general, so that any kind of object can be handled without requiring changes to the JGridView. Once you have the above, it's easy to integrate it into a TopComponent, just like any other NetBeans explorer view.

    Read the article

  • Context Sensitive JTable (Part 2)

    - by Geertjan
    Now, having completed part 1, let's add a popup menu to the JTable. However, the menu item in the popup menu should invoke the same Action as invoked from the toolbar button created yesterday. Add this to the constructor created yesterday: Collection<? extends Action> stockActions =         Lookups.forPath("Actions/Stock").lookupAll(Action.class); for (Action action : stockActions) {     popupMenu.add(new JMenuItem(action)); } MouseListener popupListener = new PopupListener(); // Add the listener to the JTable: table.addMouseListener(popupListener); // Add the listener specifically to the header: table.getTableHeader().addMouseListener(popupListener); And here's the standard popup enablement code: private JPopupMenu popupMenu = new JPopupMenu(); class PopupListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }

    Read the article

  • ComboBox Data Binding

    - by Geertjan
    Let's create a databound combobox, levering MVC in a desktop application. The result will be a combobox, provided by the NetBeans ChoiceView, that displays data retrieved from a database: What follows is not much different from the NetBeans Platform CRUD Application Tutorial and you're advised to consult that document if anything that follows isn't clear enough. One kind of interesting thing about the instructions that follow is that it shows that you're able to create an application where each element of the MVC architecture can be located within a separate module: Start by creating a new NetBeans Platform application named "MyApplication". Model We're going to start by generating JPA entity classes from a database connection. In the New Project wizard, choose "Java Class Library". Click Next. Name the Java Class Library "MyEntities". Click Finish. Right-click the MyEntities project, choose New, and then select "Entity Classes from Database". Work through the wizard, selecting the tables of interest from your database, and naming the package "entities". Click Finish. Now a JPA entity is created for each of the selected tables. In the Project Properties dialog of the project, choose "Copy Dependent Libraries" in the Packaging panel. Build the project. In your project's "dist" folder (visible in the Files window), you'll now see a JAR, together with a "lib" folder that contains the JARs you'll need. In your NetBeans Platform application, create a module named "MyModel", with code name base "org.my.model". Right-click the project, choose Properties, and in the "Libraries" panel, click Add Dependency button in the Wrapped JARs subtab to add all the JARs from the previous step to the module. Also include "derby-client.jar" or the equivalent driver for your database connection to the module. Controler In your NetBeans Platform application, create a module named "MyControler", with code name base "org.my.controler". Right-click the module's Libraries node, in the Projects window, and add a dependency on "Explorer & Property Sheet API". In the MyControler module, create a class with this content: package org.my.controler; import org.openide.explorer.ExplorerManager; public class MyUtils { static ExplorerManager controler; public static ExplorerManager getControler() { if (controler == null) { controler = new ExplorerManager(); } return controler; } } View In your NetBeans Platform application, create a module named "MyView", with code name base "org.my.view".  Create a new Window Component, in "explorer" view, for example, let it open on startup, with class name prefix "MyView". Add dependencies on the Nodes API and on the Explorer & Property Sheet API. Also add dependencies on the "MyModel" module and the "MyControler" module. Before doing so, in the "MyModel" module, make the "entities" package and the "javax.persistence" packages public (in the Libraries panel of the Project Properties dialog) and make the one package that you have in the "MyControler" package public too. Define the top part of the MyViewTopComponent as follows: public final class MyViewTopComponent extends TopComponent implements ExplorerManager.Provider { ExplorerManager controler = MyUtils.getControler(); public MyViewTopComponent() { initComponents(); setName(Bundle.CTL_MyViewTopComponent()); setToolTipText(Bundle.HINT_MyViewTopComponent()); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); controler.setRootContext(new AbstractNode(Children.create(new ChildFactory<Customer>() { @Override protected boolean createKeys(List list) { EntityManager entityManager = Persistence. createEntityManagerFactory("MyEntitiesPU").createEntityManager(); Query query = entityManager.createNamedQuery("Customer.findAll"); list.addAll(query.getResultList()); return true; } @Override protected Node createNodeForKey(Customer key) { Node customerNode = new AbstractNode(Children.LEAF, Lookups.singleton(key)); customerNode.setDisplayName(key.getName()); return customerNode; } }, true))); controler.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { Customer selectedCustomer = controler.getSelectedNodes()[0].getLookup().lookup(Customer.class); StatusDisplayer.getDefault().setStatusText(selectedCustomer.getName()); } }); JPanel row1 = new JPanel(new FlowLayout(FlowLayout.LEADING)); row1.add(new JLabel("Customers: ")); row1.add(new ChoiceView()); add(row1); } @Override public ExplorerManager getExplorerManager() { return controler; } ... ... ... Now run the application and you'll see the same as the image with which this blog entry started.

    Read the article

  • UndoRedo on Nodes (Part 2)

    - by Geertjan
    After the recording of the latest API Design Tip for the upcoming NetBeans Podcast, Jaroslav Tulach helped me with the problem I blogged about yesterday. First he expressed surprise at seeing Undo/Redo work on Nodes, which was never the intention, i.e., that feature was always intended for documents, e.g., the Java editor. However, he then showed me where to find the Properties window in the NetBeans sources, where it is org.netbeans.core.windows.view.ui.NbSheet. It turns out that the Properties window does not have an activated node and hence the Node that implements UndoRedo.Manager is never put in the Lookup. Once we added, on line 303, "this.setActivatedNodes(nodes);", everything worked as expected, i.e., the Undo/Redo actions are now enabled, even when the Properties window is selected: Maybe it means I should file an issue to get that line added to NbSheet?

    Read the article

  • TopComponent, Node, Lookup, Palette, and Visual Library

    - by Geertjan
    Here's a small example that puts together several pieces in the context of a NetBeans Platform application, i.e., TopComponent, Node, Lookup, Palette, and Visual Library: http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/CensusDesigner The result is a drag-and-drop user interface, i.e., drag items from the palette and drop them onto the window, that's all it does, nothing too fancy, just puts the basic NetBeans Platform pieces together in a pretty standard combination:

    Read the article

  • Hello Again, San Francisco

    - by Geertjan
    From the moment I got to the airport in Amsterdam, I've been bumping into JavaOne pilgrims today. Finally got to my hotel, after a pretty good flight (and KLM provides great meals, which helps a lot), and a rather long wait at customs (serves me right for getting seat 66C in a plane with 68 rows). And, best of all, on Twitter I've been seeing a few remarks around the Duke's Choice Awards for this year. The references all point to the September - October issue of the Java Magazine, where page 24 shows the following: So, from page 24 onwards, you can read all about the above applications. What's especially cool is that three of the above are applications created on top of the NetBeans Platform! That's AgroSense (farm management software), MICE (NATO system for defense and battle-space operations), and Level One Registration Tool (UN Refugee Agency sofware for managing refugees). Congratulations to all the winners, looking forward to learning more about them all during the coming days here at the conference.

    Read the article

  • Deadlock Analysis in NetBeans 8

    - by Geertjan
    Lock contention profiling is very important in multi-core environments. Lock contention occurs when a thread tries to acquire a lock while another thread is holding it, forcing it to wait. Lock contentions result in deadlocks. Multi-core environments have even more threads to deal with, causing an increased likelihood of lock contentions. In NetBeans 8, the NetBeans Profiler has new support for displaying detailed information about lock contention, i.e., the relationship between the threads that are locked. After all, whenever there's a deadlock, in any aspect of interaction, e.g., a political deadlock, it helps to be able to point to the responsible party or, at least, the order in which events happened resulting in the deadlock. As an example, let's take the handy Deadlock sample code from the Java Tutorial and look at the tools in NetBeans IDE for identifying and analyzing the code. The description of the deadlock is nice: Alphonse and Gaston are friends, and great believers in courtesy. A strict rule of courtesy is that when you bow to a friend, you must remain bowed until your friend has a chance to return the bow. Unfortunately, this rule does not account for the possibility that two friends might bow to each other at the same time. To help identify who bowed first or, at least, the order in which bowing took place, right-click the file and choose "Profile File". In the Profile Task Manager, make the choices below: When you have clicked Run, the Threads window shows the two threads are blocked, i.e., the red "Monitor" lines tell you that the related threads are blocked while trying to enter a synchronized method or block: But which thread is holding the lock? Which one is blocked by the other? The above visualization does not answer these questions. New in NetBeans 8 is that you can analyze the deadlock in the new Lock Contention window to determine which of the threads is responsible for the lock: Here is the code that simulates the lock, very slightly tweaked at the end, where I use "setName" on the threads, so that it's even easier to analyze the threads in the relevant NetBeans tools. Also, I converted the anonymous inner Runnables to lambda expressions. package org.demo; public class Deadlock { static class Friend { private final String name; public Friend(String name) { this.name = name; } public String getName() { return this.name; } public synchronized void bow(Friend bower) { System.out.format("%s: %s" + " has bowed to me!%n", this.name, bower.getName()); bower.bowBack(this); } public synchronized void bowBack(Friend bower) { System.out.format("%s: %s" + " has bowed back to me!%n", this.name, bower.getName()); } } public static void main(String[] args) { final Friend alphonse = new Friend("Alphonse"); final Friend gaston = new Friend("Gaston"); Thread t1 = new Thread(() -> { alphonse.bow(gaston); }); t1.setName("Alphonse bows to Gaston"); t1.start(); Thread t2 = new Thread(() -> { gaston.bow(alphonse); }); t2.setName("Gaston bows to Alphonse"); t2.start(); } } In the above code, it's extremely likely that both threads will block when they attempt to invoke bowBack. Neither block will ever end, because each thread is waiting for the other to exit bow. Note: As you can see, it really helps to use "Thread.setName", everywhere, wherever you're creating a Thread in your code, since the tools in the IDE become a lot more meaningful when you've defined the name of the thread because otherwise the Profiler will be forced to use thread names like "thread-5" and "thread-6", i.e., based on the order of the threads, which is kind of meaningless. (Normally, except in a simple demo scenario like the above, you're not starting the threads in the same class, so you have no idea at all what "thread-5" and "thread-6" mean because you don't know the order in which the threads were started.) Slightly more compact: Thread t1 = new Thread(() -> { alphonse.bow(gaston); },"Alphonse bows to Gaston"); t1.start(); Thread t2 = new Thread(() -> { gaston.bow(alphonse); },"Gaston bows to Alphonse"); t2.start();

    Read the article

  • Screencast: "Unlocking the Java EE Platform with HTML5"

    - by Geertjan
    The Java EE platform aims to increase your productivity and reduce the amount of scaffolding code needed in Java enterprise applications. It encompasses a range of specifications, such as JPA, EJB, JSF, and JAX-RS. How do these specifications fit together in an application, and how do they relate to each other? And how can HTML5 be used to leverage Java EE? In this recording of a session I did last week at Oredev in Malmo, Sweden, you learn how Java EE works and how it can be integrated with HTML5 front ends, via HTML, JavaScript, and CSS.

    Read the article

  • Invoking JavaScript from Java

    - by Geertjan
    Here's an Action class defined in Java. The Action class executes a script via the JavaFX WebEngine: @NbBundle.Messages("CTL_AddBananasAction=Add Banana") private class AddBananasAction extends AbstractAction { public AddBananasAction() { super(Bundle.CTL_AddBananasAction()); } @Override public void actionPerformed(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { webengine.executeScript("addBanana(' " + newBanana + " ') "); } }); } }How does the 'executescript' call know where to find the JavaScript file? Well, earlier in the code, the WebEngine loaded an HTML file, where the JavaScript file was registered: WebView view = new WebView(); view.setMinSize(widthDouble, heightDouble); view.setPrefSize(widthDouble, heightDouble); webengine = view.getEngine(); URL url = getClass().getResource("home.html"); webengine.load(url.toExternalForm()); Finally, here's a skeleton 'addBanana' method, which is invoked via the Action class shown above: function addBanana(user){ statustext.text(user); } By the way, if you have your JavaScript and CSS embedded within your HTML file, the code navigator combines all three into the same window, which is kind of cool:

    Read the article

  • Two Hidden NetBeans Keyboard Shortcuts for Opening & Toggling between Views

    - by Geertjan
    The following are two really basic shortcuts for working with NetBeans editor windows that will be added to the Keyboard Shortcuts card for NetBeans IDE 7.2: Ctrl-Alt-PgUp/PgDown: Shortcuts for switching between editor types (e.g. Source, Design, History buttons). Switching between the editor types is a frequent operation sometimes, e.g., when using GUI builder, and while it can be done easily via mouse, or from View | Editors menu, it is very handy to know the shortcuts as well. Ctrl-PgUp/PgDown: Similarly, these are shortcuts for switching to next/previous opened document (tab). Note this is not like Ctrl-Tab that cycles in the last used order, but going through the tabs as they appear in the editor. Both shortcuts should fit into the "Opening and Toggling between Views" section. These are important to mention on the card because they are not visible anywhere else in the UI (as there are no menu items like "Go to next/previous editor type" or "Go to next/previous document"). Reported by Tomas Pavek from the NetBeans Team, here: http://netbeans.org/bugzilla/show_bug.cgi?id=213815

    Read the article

  • Eclipse and NetBeans replacing embedded IDEs (part 2 and part 3)

    - by Geertjan
    After part 1, in Embedded Insights, the series Eclipse and NetBeans replacing embedded IDEs by principal analyst Robert Cravotta continues below. Many embedded tool developers are choosing to migrate their embedded development toolset to an open source IDE platform for a number of reasons. Maintaining an up-to-date IDE with the latest ideas, innovations, and features requires continuous effort from the tool development team. In contrast to maintaining a proprietary IDE, adopting an open source IDE platform enables the tool developers to leverage the ideas and effort of the community and take advantage of advances in IDE features much sooner and without incurring the full risk of experimenting with new features in their own toolsets. Both the Eclipse and NetBeans platforms deliver regular releases that enable tool developers to more easily take advantage of the newest features in the platform architecture.  Read more of part 2 here, in an article published Thursday, May 17th, 2012. Both the NetBeans and Eclipse projects began as development environments and both evolved into platforms that support a wider array of software products. Both platforms have been actively supported and evolving open source projects that have competed and coexisted together for the past decade and this has led to a level a parity between the two platforms. From the perspective of a tool developer, applications are built the same way on either platform – the difference is in the specific terminology and tools. Read more of part 3 here, in an article published Tuesday, June 12th, 2012. And, as a bonus in this blog entry, here's how to get started creating an IDE on the NetBeans Platform:  http://netbeans.dzone.com/how-to-create-commercial-quality-ide

    Read the article

  • GeoTools Demo Embedded in an Application Framework via Maven

    - by Geertjan
    GeoTools 8.4 was very recently released, according to its active blog, and to celebrate here's a starting point for working with GeoTools on the NetBeans Platform: The sources of the above are below, as a Maven project, so this project can be used in any IDE or command line: http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.3/tutorials/geospatial/geotools/MyGeospatialSystem Though quite dated, the GeoTools NetBeans Quick Start is very helpful, especially since it used Maven too, but not the NetBeans Platform, unlike the above sample. From the point of view of NetBeans Platform developers, the GeoTools JMapPane class is very useful, providing the integration point between GeoTools and the rest of the NetBeans Platform application. Being integrated into the NetBeans Platform means that a host of standard features are now available to the GeoTools features, e.g., print functionality, which only requires a runtime dependency on the NetBeans Print API, together with the "print.printable" client property put into constructor of the TopComponent: By the way, I've spent some time now and again being confused about the difference between GeoTools and GeoToolkit. Here's an interesting starting point to beginning to understand the differences and history between them. Soon I'd like to have an example similar for the above for GeoToolkit.

    Read the article

  • Tissue Specific Electrochemical Fingerprinting on the NetBeans Platform

    - by Geertjan
    Proteomics and metalloproteomics are rapidly developing interdisciplinary fields providing enormous amounts of data to be classified, evaluated, and interpreted. Approaches offered by bioinformatics and also by biostatistical data analysis and treatment are therefore becoming increasingly relevant. A bioinformatics tool has been developed at universities in Prague and Brno, in the Czech Republic, for analysis and visualization in this domain, on the NetBeans Platform: More info:  http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0049654

    Read the article

  • JEditorPane Code Completion (Part 3)

    - by Geertjan
    The final step is to put an object into the Lookup on key listening in each of the JEditorPanes, e.g., a "City" object for the CityEditorPane and a "Country" object for the CountryEditorPane. Then, within the CompletionProviders, only add items to the CompletionResultSet if the object of interest is in the Lookup. The result is that you can then have different code completions in different JEditorPanes, as shown below: I've also included the Tools | Options | Editor | Code Completion tab, so that the code completion can be customized. The full source code for the example is here: java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.2/misc/CustomerApp

    Read the article

  • Test JPQL with NetBeans IDE 7.3 Tools

    - by Geertjan
    Since I pretty much messed up this part of the "Unlocking Java EE 6 Platform" demo, which I did together with PrimeFaces lead Çagatay Çivici during JavaOne 2012, I feel obliged to blog about it to clarify what should have happened! In my own defense, I only learned about this feature 15 minutes before the session started. In 7.3 Beta, it works for Java SE projects, while for Maven-based web projects, you need a post 7.3 Beta build, which is what I set up for my demo right before it started. Then I saw that the feature was there, without actually trying it out, which resulted in that part of the demo being a bit messy. And thanks to whoever it was in the audience who shouted out how to use it correctly! Screenshots below show everything related to this new feature, available from 7.3 onwards, which means you can try out your JPQL queries right within the IDE, without deploying the application (you only need to build it since the queries are run on the compiled classes): SQL view: Result view for the above: Here, you see the result of a more specific query, i.e., check that a record with a specific name value is present in the database: Also note that there is code completion within the editor part of the dialog above. I.e., as you press Ctrl-Space, you'll see context-sensitive suggestions for filling out the query. All this is pretty cool stuff! Saves time because now there's no need to deploy the app to check the database connection.

    Read the article

  • JavaFX in a JSF 2.0 Custom Tag?

    - by Geertjan
    I followed these instructions and now have a simple JSF 2.0 tag handler: The reason I created this is because I'm curious about whether it would be possible to change the tag created above: <my:hello name="Jack" /> ...to something like this: <my:chart type="pie" xAxis="${some-expression}" yAxis="${some-expression}" width="300" height="500" /> Has anyone tried this? That could be a way to incorporate a JavaFX chart into a Java EE application. That's different to how Adam Bien is doing it in LightFish, but might be a simpler and more reusable way of doing the same thing.

    Read the article

  • 44 Tips for Front End Web Devs (Part 1)

    - by Geertjan
    HTML, JavaScript, and CSS development in NetBeans IDE is fairly new, especially the integrated features of all the editors with the browser. In this screencast, newbies (and even those who have used NetBeans for many years) get a series of tips and insights into using NetBeans IDE in the context of HTML5 development. For example, useful keyboard shortcuts, plugins such as Emmet, and much much more is covered: Part 2 of this series, which is also the final part, is set to be published tomorrow. Note: The outline of the screencast is found in yesterday's blog entry!

    Read the article

< Previous Page | 4 5 6 7 8 9 10  | Next Page >