M.Y. Developers
M.Y. Developers

Reputation: 211

Replace Netbeans Projects Logical View to Outline View

Context: We are designing a Netbeans Platform RCP based Lua IDE. We have implemented a build system that allows users to easily enable/disable files and add aliases to rename files at buildtime. We feel it is necessary in a UI standpoint to have checkboxes next to our custom nodes in the projects logical tab in order to simplify enabling and disabling files

Problem: We want to replace the default BeanTreeView with an Outline view because the default view does not honor the CheckableNode in the lookup. We are not sure of the best way to do this but the solution we have devised seems like the wrong way to go. The component does not resize properly and the nodes do not auto-expand at startup like they do in the native BeanTreeView.

Implementation Details: We created a FilterNode that proxies the DataObject node delegate. We also added our own property sets to the lookup and added a class that implements CheckableNode (hence the checkboxes on the left of the outline view).

Here is it looks now, this is exactly how we want it to look:

custom logical tab view

And here is the code we used to install it:

final String PROJECT_LOGICAL_TAB_ID = "projectTabLogical_tc";
    WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
        @Override
        public void run() {
            TopComponent findTopComponent = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID);
            if (findTopComponent != null) {
                Component[] components = findTopComponent.getComponents();
                for (Component component : components) {
                    component.setVisible(false);          
                }
                OutlineView myView2 = new OutlineView("Filename");
                Outline outline2 = myView2.getOutline();
                outline2.setRootVisible(false);
                outline2.setTableHeader(null);         
                findTopComponent.add(myView2, BorderLayout.CENTER);
                findTopComponent.revalidate();
                findTopComponent.validate();
                findTopComponent.repaint();
            }


        }
    });

Thanks in advance.

Upvotes: 2

Views: 1038

Answers (2)

M.Y. Developers
M.Y. Developers

Reputation: 211

The solution lies in a delay between invokeWhenUIReady and the transformation.

        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
        @Override
        public void run() {                
            RequestProcessor.getDefault().post(new Runnable() {
                @Override
                public void run() {
                    //We must do this in the awt thread
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            TopComponent findTopComponent = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID); // TODO add your handling code here:
                            findTopComponent.setVisible(false);
                            findTopComponent.removeAll();
                            findTopComponent.setLayout(new BorderLayout());
                            OutlineView myView2 = new OutlineView("Filename");                      
                            Outline outline2 = myView2.getOutline();
                            outline2.setRootVisible(false);
                            outline2.setTableHeader(null);
                            findTopComponent.add(myView2, BorderLayout.CENTER);
                            findTopComponent.setVisible(true);
                            findTopComponent.open();
                            findTopComponent.requestActive();
                        }
                    });
                }
                //This delay is important!
            }, 1000);
        }
    });

Upvotes: 1

user1722245
user1722245

Reputation: 2173

it works for me: (win7, Java 7 x64, NB dev (20121214))

public void jbuttonActionPerformance(ActionEvent ev){

    TopComponent findTopComponent = WindowManager.getDefault().findTopComponent("OutlineTopComponent"); // TODO add your handling code here:
   findTopComponent.setVisible(false);
   findTopComponent.removeAll();
   findTopComponent.setLayout(new BorderLayout());

    OutlineView myView2 = new OutlineView("Filename");
    Outline outline2 = myView2.getOutline();
    findTopComponent.add(myView2, BorderLayout.CENTER);

    findTopComponent.setVisible(true);
    findTopComponent.open();findTopComponent.requestActive();
}

Jirka

Upvotes: 1

Related Questions