Java Code Examples for org.openide.loaders.DataObject#getName()

The following examples show how to use org.openide.loaders.DataObject#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: J2SEProject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
@NonNull
public List<DataObject> sort(@NonNull final List<DataObject> original) {
    if (!isLibrary()) {
        return original;
    }
    final List<DataObject> result = new ArrayList<>(Collections.<DataObject>nCopies(CAT_MAP.size(), null));
    for (DataObject dobj : original) {
        final String name = dobj.getName();
        final Integer index = CAT_MAP.get(name);
        if (index == null) {
            result.add(dobj);
        } else {
            result.set (index, dobj);
        }
    }
    return filterNulls(result);
}
 
Example 2
Source File: AbstractLogicalViewProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Node findNodeInConfigFiles(Node root, FileObject fo) {
    // XXX ugly, some node names contain the extension and other don't
    // so retrieving the node name from the corresp. DataObject
    String nodeName;
    try {
        DataObject dobj = DataObject.find(fo);
        nodeName = dobj.getName();
    } catch (DataObjectNotFoundException e) {
        nodeName = fo.getName();
    }
    Node configFiles = root.getChildren().findChild("configurationFiles"); // NOI18N
    if (configFiles == null) {
        return null;
    }
    return NodeOp.findChild(configFiles, nodeName);
}
 
Example 3
Source File: TemplateChooserPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void readSettings(WizardDescriptor settings) {
    this.wizard = settings;
    TemplateChooserPanelGUI panel = (TemplateChooserPanelGUI) this.getComponent();
    final FileObject currentTemplate = Templates.getTemplate(settings);
    FileObject templates = FileUtil.getConfigFile("Templates");    //NOI18N
    String currentCategoryName = null;
    String currentTemplateName = null;
    if (templates != null && currentTemplate != null && currentTemplate.getParent() != null && templates.equals(currentTemplate.getParent().getParent())) {
        try {                
            final DataObject dobj = DataObject.find(currentTemplate);                
            final DataObject owner = DataObject.find(currentTemplate.getParent());
            currentTemplateName = dobj.getName();
            currentCategoryName = owner.getName();
        } catch (DataObjectNotFoundException e) {
            //Ignore and use default
        }
    }
    panel.readValues( project, currentCategoryName, currentTemplateName );
    settings.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    settings.putProperty(WizardDescriptor.PROP_CONTENT_DATA, new String[] {
            NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Name"), // NOI18N
            NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Dots")}); // NOI18N
    // bugfix #44400: wizard title always changes
    settings.putProperty("NewFileWizard_Title", null); // NOI18N
}
 
Example 4
Source File: MoveClassUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MoveClassUI(DataObject javaObject, FileObject targetFolder, PasteType pasteType, boolean needsByPass) {
    this.needsByPass = needsByPass;
    this.disable = targetFolder != null;
    this.targetFolder = targetFolder;
    this.javaObject = javaObject;
    this.sourceName = javaObject.getName();
    this.pasteType = pasteType;
    this.refactoring = new MoveRefactoring(Lookups.fixed(javaObject.getPrimaryFile()));
    this.refactoring.getContext().add(JavaRefactoringUtils.getClasspathInfoFor(javaObject.getPrimaryFile()));
}
 
Example 5
Source File: FormI18nSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets <code>I18nSupport</code> instance for specified data object and document.
 * @exception IOException when the document could not be loaded */
@Override
public I18nSupport create(DataObject dataObject) throws IOException {
    I18nSupport support = super.create(dataObject);
    
    FormDataObject formDataObject = (FormDataObject)dataObject;
    FormEditorSupport formSupport = (FormEditorSupport)formDataObject.getFormEditorSupport();
    if (formSupport.isOpened()) {
        return support;
    }
    if (formSupport.loadForm()) {
        return support;
    }
    throw new IOException("I18N: Loading form for " + dataObject.getName() + " was not succesful."); // NOI18N
}
 
Example 6
Source File: CompletionTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static JEditorPane getAnEditorPane(DataObject file, PrintWriter log) throws Exception {
    EditorCookie  cookie = (EditorCookie)file.getCookie(EditorCookie.class);
    
    if (cookie == null)
        throw new IllegalStateException("Given file (\"" + file.getName() + "\") does not have EditorCookie.");
    
    JEditorPane[] panes = cookie.getOpenedPanes();
    long          start = System.currentTimeMillis();
    
    if (panes == null) {
        //Prepare by opening a document. The actual opening into the editor
        //should be faster (hopefully...).
        cookie.openDocument();
        cookie.open();
        while ((panes = cookie.getOpenedPanes()) == null && (System.currentTimeMillis() - start) < OPENING_TIMEOUT) {
            try {
                Thread.sleep(SLEEP_TIME);
            } catch (InterruptedException e) {
                e.printStackTrace(log);
            }
        };
        
        log.println("Waiting spent: " + (System.currentTimeMillis() - start) + "ms.");
    };
    
    if (panes == null)
        throw new IllegalStateException("The editor was not opened. The timeout was: " + OPENING_TIMEOUT + "ms.");
    
    return panes[0];
}
 
Example 7
Source File: DnDSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new toolbar button represented by the given DataObject.
 */
private boolean addButton( DataObject dobj, int dropIndex, boolean dropBefore ) throws IOException {
    if( null == dobj )
        return false;
    //check if the dropped button (action) already exists in this toolbar
    String objName = dobj.getName();
    DataFolder backingFolder = getBackingFolder(currentToolbar);
    DataObject[] children = backingFolder.getChildren();
    for( int i=0; i<children.length; i++ ) {
        //TODO is comparing DataObject names ok?
        if( objName.equals( children[i].getName() ) ) {
            //user dropped to toolbat a new button that already exists in this toolbar
            //just move the existing button to a new position
            return moveButton( children[i], dropIndex, dropBefore );
        }
    }

    DataObject objUnderCursor = getDataObjectUnderDropCursor( dropIndex-1, dropBefore );

    DataShadow shadow = DataShadow.create( backingFolder, dobj );
    // use some fake position, so getChildren don't complain
    shadow.getPrimaryFile().setAttribute("position", 100001); // NOI18N

    //find the added object
    DataObject newObj = null;
    children = backingFolder.getChildren();
    for( int i=0; i<children.length; i++ ) {
        if( objName.equals( children[i].getName() ) ) {
            newObj = children[i];
            break;
        }
    }

    if( null != newObj )
        reorderButtons( newObj, objUnderCursor ); //put the button to its proper position

    return true;
}
 
Example 8
Source File: PrintAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String getName(DataObject data) {
    if (data == null) {
        return null;
    }
    return data.getName();
}
 
Example 9
Source File: ActionProviderImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages({
    "# {0} - artifactId", "TXT_Run=Run ({0})",
    "# {0} - artifactId", "TXT_Debug=Debug ({0})",
    "# {0} - artifactId", "TXT_ApplyCodeChanges=Apply Code Changes ({0})",
    "# {0} - artifactId", "TXT_Profile=Profile ({0})",
    "# {0} - artifactId", "TXT_Test=Test ({0})",
    "# {0} - artifactId", "TXT_Build=Build ({0})",
    "# {0} - artifactId", "TXT_Delete=Delete ({0})",
})

static String taskName(Project project, String action, Lookup lkp) {
    String title;
    DataObject dobj = lkp.lookup(DataObject.class);
    String dobjName = dobj != null ? dobj.getName() : "";
    Project prj = project != null ? project : lkp.lookup(Project.class);
    String prjLabel = prj != null ? ProjectUtils.getInformation(prj).getDisplayName() : "No Project on Lookup"; //NOI18N
    switch (action) {
        case ActionProvider.COMMAND_RUN:
            title = TXT_Run(prjLabel);
            break;
        case ActionProvider.COMMAND_DEBUG:
            title = TXT_Debug(prjLabel);
            break;
        case ActionProvider.COMMAND_DELETE:
            title = TXT_Delete(prjLabel);
            break;
        case ActionProvider.COMMAND_PROFILE:
            title = TXT_Profile(prjLabel);
            break;
        case ActionProvider.COMMAND_TEST:
            title = TXT_Test(prjLabel);
            break;
        case ActionProvider.COMMAND_RUN_SINGLE:
            title = TXT_Run(dobjName);
            break;
        case ActionProvider.COMMAND_DEBUG_SINGLE:
        case ActionProvider.COMMAND_DEBUG_TEST_SINGLE:
            title = TXT_Debug(dobjName);
            break;
        case ActionProvider.COMMAND_PROFILE_SINGLE:
        case ActionProvider.COMMAND_PROFILE_TEST_SINGLE:
            title = TXT_Profile(dobjName);
            break;
        case ActionProvider.COMMAND_TEST_SINGLE:
            title = TXT_Test(dobjName);
            break;
        case "debug.fix":
            title = TXT_ApplyCodeChanges(prjLabel);
            break;
        default:
            title = TXT_Build(prjLabel);
    }
    return title;
}
 
Example 10
Source File: ActionsList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Pair convertImpl(List<FileObject> keys, boolean ignoreFolders,
        boolean prohibitSeparatorsAndActionNames)
{
    List<Object> all = new ArrayList<Object>();
    List<Action> actions = new ArrayList<Action>();

    for (FileObject item : keys) {
        DataObject dob;
        try {
            dob = DataObject.find(item);
            if (dob == null && prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: DataObject is null for item=" + item + "\n"); //NOI18N
                }
            }
        } catch (DataObjectNotFoundException dnfe) {
            if (prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: DataObject not found for item=" + item + "\n"); //NOI18N
                }
            } else {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE, "DataObject not found for action fileObject=" + item); //NOI18N
                }
            }
            continue; // ignore
        }

        Object toAdd = null;
        InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class);
        if (prohibitSeparatorsAndActionNames && ic == null) {
            if (LOG.isLoggable(Level.INFO)) {
                LOG.info("ActionsList: InstanceCookie not found for item=" + item + "\n"); //NOI18N
            }
            continue;
        }
        if (ic != null) {
            try {
                if (!isSeparator(ic)) {
                    toAdd = ic.instanceCreate();
                    if (toAdd == null && prohibitSeparatorsAndActionNames) {
                        if (LOG.isLoggable(Level.INFO)) {
                            LOG.info("ActionsList: InstanceCookie.instanceCreate() null for item=" + item + "\n"); //NOI18N
                        }
                    }
                }
            } catch (Exception e) {
                LOG.log(Level.INFO, "Can't instantiate object", e); //NOI18N
                continue;
            }
        } else if (dob instanceof DataFolder) {
            toAdd = dob;
        } else {
            toAdd = dob.getName();
        }

        // Filter out the same succeding items
        if (all.size() > 0) {
            Object lastOne = all.get(all.size() - 1);
            if (Utilities.compareObjects(lastOne, toAdd)) {
                continue;
            }
            if (isSeparator(lastOne) && isSeparator(toAdd)) {
                continue;
            }
        }
        
        if (toAdd instanceof Action) {
            Action action = (Action) toAdd;
            actions.add(action);
            AcceleratorBinding.setAccelerator(action, item);
        } else if (isSeparator(toAdd)) {
            if (prohibitSeparatorsAndActionNames) {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("ActionsList: Separator for item=" + item + "\n"); //NOI18N
                }
            }
            actions.add(null);
        }
        all.add(toAdd);
    }

    Pair p = new Pair();
    p.all = all.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(all);
    p.actions = actions.isEmpty() ? Collections.<Action>emptyList() : Collections.unmodifiableList(actions);
    return p;
}