Search in sources :

Example 1 with ExplorerContext

use of org.netbeans.modules.refactoring.api.ui.ExplorerContext in project netbeans-mmd-plugin by raydac.

the class MovePanel method initValues.

private void initValues() {
    final String text;
    if (this.files.length > 1) {
        text = String.format(BUNDLE.getString("MovePanel.multiFileText"), Integer.toString(this.files.length));
    } else {
        text = String.format(BUNDLE.getString("MovePanel.singleFileText"), this.files[0].getName());
    }
    this.labelMessage.setText(text);
    final List<Project> projects = new ArrayList<Project>();
    for (final Project p : OpenProjects.getDefault().getOpenProjects()) {
        projects.add(p);
    }
    final ComboBoxModel<Project> projectModel = new DefaultComboBoxModel<Project>(projects.toArray(new Project[projects.size()]));
    final ItemListener listener = new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (comboProjects.equals(e.getSource())) {
                updateFolders();
                parent.stateChanged(null);
            } else if (comboFolders.equals(e.getSource())) {
                parent.stateChanged(null);
            }
        }
    };
    this.comboProjects.addItemListener(listener);
    this.comboFolders.addItemListener(listener);
    this.comboProjects.setModel(projectModel);
    this.comboProjects.setSelectedItem(FileOwnerQuery.getOwner(this.files[0]));
    updateFolders();
    final ExplorerContext explorerContext = this.lookup.lookup(ExplorerContext.class);
    if (explorerContext != null) {
        final Node targetNode = explorerContext.getTargetNode();
        if (targetNode != null) {
            final DataObject dobj = targetNode.getLookup().lookup(DataObject.class);
            if (dobj != null) {
                final FileObject fo = dobj.getPrimaryFile();
                if (fo != null && fo.isValid() && fo.isFolder()) {
                    final Project proj = FileOwnerQuery.getOwner(fo);
                    if (proj != null) {
                        this.comboProjects.setSelectedItem(proj);
                        this.comboFolders.setSelectedItem(FileUtil.getRelativePath(proj.getProjectDirectory(), fo));
                    }
                }
            }
        }
    }
}
Also used : Project(org.netbeans.api.project.Project) ItemEvent(java.awt.event.ItemEvent) ExplorerContext(org.netbeans.modules.refactoring.api.ui.ExplorerContext) DataObject(org.openide.loaders.DataObject) Node(org.openide.nodes.Node) ArrayList(java.util.ArrayList) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) FileObject(org.openide.filesystems.FileObject)

Aggregations

ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 ArrayList (java.util.ArrayList)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 Project (org.netbeans.api.project.Project)1 ExplorerContext (org.netbeans.modules.refactoring.api.ui.ExplorerContext)1 FileObject (org.openide.filesystems.FileObject)1 DataObject (org.openide.loaders.DataObject)1 Node (org.openide.nodes.Node)1