2

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.

M.Y. Developers
  • 211
  • 5
  • 6
  • I've only used `Outline` in a stand-alone context, but I'd expect the layout manager of the `TopComponent` to influence the `DefaultOutlineCellRenderer`. Does your `OutlineModel` have a `RowModel`? – trashgod Dec 17 '12 at 09:13
  • Do you have BorderLayout in TopComponent? – user1722245 Dec 17 '12 at 17:03
  • @trashgod: Yes we also use Outline in a stand-alone context in another top component and it scales fine without a RowModel. – M.Y. Developers Dec 17 '12 at 22:24
  • @user1722245: Yes the top componenet had a border layout (at least the gui snapshot says it does). We also tried setting a new BorderLayout but still have the same problem. – M.Y. Developers Dec 17 '12 at 22:25

2 Answers2

1

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

user1722245
  • 2,065
  • 1
  • 18
  • 31
  • Thanks! This lead us to the solution to the problem. I am still not sure why this fixes the problem but adding a delay from invokeWhenUIReady to the actual transformation solves the problem. Any idea why this fixes it? – M.Y. Developers Dec 19 '12 at 03:45
1

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);
        }
    });
M.Y. Developers
  • 211
  • 5
  • 6
  • When the logical view restores the previous node state (ie selections/collapsed/expanded) it seems to restore the bean tree view if it is not found. This is why we need the delay. Unfortunately it does not always work at the specified time so a cleaner solution (property change based?) would be much appreciated. – M.Y. Developers Dec 19 '12 at 21:12