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

The following examples show how to use org.openide.loaders.DataObject#equals() . 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: ResourceHolder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Setter for </code>resource</code>. */
public void setResource(DataObject resource) {
    if (resource == null) {
        this.resource = null;
        return;
    }

    Class<?> clazz = resource.getClass();

    // Check if the class of parameter is valid for this ResourceHolder.
    if(!Arrays.asList(resourceClasses).contains(clazz))
        throw new IllegalArgumentException();

    if(!resource.equals(this.resource))
        this.resource = resource;
}
 
Example 2
Source File: PropertyPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Helper method. Changes resource. */
private void changeResource(DataObject resource) {
    if (resource == null) {
        throw new IllegalArgumentException();
    }

    DataObject oldValue = i18nString.getSupport().getResourceHolder().getResource();

    if ((oldValue != null) && oldValue.equals(resource)) {
        return;
    }

    i18nString.getSupport().getResourceHolder().setResource(resource);
    String newResourceValue = i18nString.getSupport().getResourceHolder()
                              .getValueForKey(i18nString.getKey());
    if (newResourceValue != null) {
        i18nString.setValue(newResourceValue);
    }
    updateAllValues();

    firePropertyChange(PROP_RESOURCE, oldValue, resource);

    I18nUtil.getOptions().setLastResource2(resource);
}
 
Example 3
Source File: ClientSideProjectLogicalView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean hasObject(Node node, Object obj) {
    if (obj == null) {
        return false;
    }
    FileObject fileObject = node.getLookup().lookup(FileObject.class);
    if (fileObject == null) {
        return false;
    }
    if (obj instanceof DataObject) {
        DataObject dataObject = node.getLookup().lookup(DataObject.class);
        if (dataObject == null) {
            return false;
        }
        if (dataObject.equals(obj)) {
            return true;
        }
        return hasObject(node, ((DataObject) obj).getPrimaryFile());
    } else if (obj instanceof FileObject) {
        return obj.equals(fileObject);
    }
    return false;
}
 
Example 4
Source File: CustomizationWSEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean modelExists(final WSDLModel wsdlModel) {
    if (wsdlModels.size() == 0) {
        return false;
    }
    DataObject modelDobj = getDataObjectOfModel(wsdlModel);
    if (!modelDobj.isValid()) {
        return true;
    }
    Set<WSDLModel> wsdls = wsdlModels.keySet();
    for (WSDLModel wsdl : wsdls) {
        DataObject dobj = getDataObjectOfModel(wsdl);
        if (!dobj.isValid()) {
            continue;
        }
        if (modelDobj.equals(dobj)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: CustomizationWSEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean modelExists(final WSDLModel wsdlModel) {
    if (wsdlModels.size() == 0) {
        return false;
    }
    DataObject modelDobj = getDataObjectOfModel(wsdlModel);
    if (!modelDobj.isValid()) {
        return true;
    }
    Set<WSDLModel> wsdls = wsdlModels.keySet();
    for (WSDLModel wsdl : wsdls) {
        DataObject dobj = getDataObjectOfModel(wsdl);
        if (!dobj.isValid()) {
            continue;
        }
        if (modelDobj.equals(dobj)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: ConvertToCCAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
   protected boolean enable(Node[] activatedNodes) {
//enables the action only if the first activated node
//contains DataObject instance which is currently associated
//with edited document
if (activatedNodes.length > 0) {
    Node node = activatedNodes[0]; //multiselection doesn't make sense
    DataObject dobj = node.getLookup().lookup(DataObject.class);
    if (dobj != null) {
	JTextComponent tc = EditorRegistry.lastFocusedComponent();
	if (tc != null && tc.getSelectedText() != null) { //disable w/o editor selection
	    DataObject editedDobj = NbEditorUtilities.getDataObject(tc.getDocument());
	    if (editedDobj != null && editedDobj.equals(dobj)) {
		return true;
	    }
	}
    }
}
return false;
   }
 
Example 7
Source File: PhpLogicalViewProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean hasObject(Node node, Object obj) {
    if (obj == null) {
        return false;
    }
    FileObject fileObject = node.getLookup().lookup(FileObject.class);
    if (fileObject == null) {
        return false;
    }
    if (obj instanceof DataObject) {
        DataObject dataObject = node.getLookup().lookup(DataObject.class);
        if (dataObject == null) {
            return false;
        }
        if (dataObject.equals(obj)) {
            return true;
        }
        return hasObject(node, ((DataObject) obj).getPrimaryFile());
    } else if (obj instanceof FileObject) {
        return obj.equals(fileObject);
    }
    return false;
}
 
Example 8
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<? extends DataObject> listAdd) {
    List<DataObject> listDest = new ArrayList<DataObject>();
    if (listAdd.size() > 0) {
        //Insert new nodes just before last (root) node
        DataObject root = null;
        //Find root
        for (int i = 0; i < children.length; i++) {
            FileObject fo = children[i].getPrimaryFile();
            if ("Favorites/Root.instance".equals(fo.getPath())) { //NOI18N
                root = children[i];
            }
        }
        if (root != null) {
            for (int i = 0; i < children.length; i++) {
                if (!root.equals(children[i])) {
                    listDest.add(children[i]);
                }
            }
            listDest.addAll(listAdd);
            listDest.add(root);
        } else {
            listDest.addAll(Arrays.asList(children));
            listDest.addAll(listAdd);
        }
        //Set desired order
        DataObject [] newOrder = listDest.toArray(new DataObject[listDest.size()]);
        try {
            favourities.setOrder(newOrder);
        } catch (IOException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
    }
}
 
Example 9
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether all files belong to the same data object.
 *
 * @param files array of Files
 * @return true if all files share common DataObject (even null), false otherwise
 */
public static boolean shareCommonDataObject(File[] files) {
    if (files == null || files.length < 2) return true;
    DataObject common = findDataObject(files[0]);
    for (int i = 1; i < files.length; i++) {
        DataObject dao = findDataObject(files[i]);
        if (dao != common && (dao == null || !dao.equals(common))) return false;
    }
    return true;
}
 
Example 10
Source File: TextImporter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void reorder( String fileName, FileObject categoryFolder, int dropIndex ) throws IOException {
    if( dropIndex < 0 )
        return;
    FileObject itemFile = categoryFolder.getFileObject(fileName, "xml" ); //NOI18N
    if( null == itemFile )
        return;
    DataFolder catDob = DataFolder.findFolder(categoryFolder);
    DataObject[] children = catDob.getChildren();
    
    DataObject dob = DataObject.find(itemFile);
    if( null == dob )
        return;
    
    int curIndex = -1;
    for( int i=0; i<children.length; i++ ) {
        if( children[i].equals(dob) ) {
            curIndex = i;
            break;
        } 
    }
    if( curIndex < 0 )
        return;
    
    DataObject[] sortedChildren = new DataObject[children.length];
    if( dropIndex >= sortedChildren.length )
        dropIndex = sortedChildren.length-1;
    sortedChildren[dropIndex] = dob;
    int index = 0;
    for( int i=0; i<sortedChildren.length; i++ ) {
        if( sortedChildren[i] != null ) {
            continue;
        }
        DataObject tmp = children[index++];
        if( dob.equals(tmp) ) {
            i--;
            continue;
        }
        sortedChildren[i] = tmp;
    }
    
    catDob.setOrder(sortedChildren);
}
 
Example 11
Source File: ShowHistoryAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void performAction(final Node[] activatedNodes) {                        
    VCSContext ctx = VCSContext.forNodes(activatedNodes);
    final Set<VCSFileProxy> rootSet = ctx.getRootFiles();                    

    final VCSFileProxy[] files = rootSet.toArray(new VCSFileProxy[rootSet.size()]);                
    if(!files[0].isFile()) {
        return;
    }

    VCSFileProxy file = files[0];
    FileObject fo = file.toFileObject();
    if(fo != null) {
        DataObject dataObject = null;
        try {
            dataObject = DataObject.find(fo);
        } catch (DataObjectNotFoundException ex) {
            History.LOG.log(Level.WARNING, null, ex);
        }
        if(dataObject != null) {
            
            if(!hasHistoryElement(dataObject)) {
                // there is no history element defined for this data object, so 
                // lets open in a separate TopComponent
                openLocalHistoryTC(files);
                return;
            }
            
            // activate the History tab if there is a opened TopComponent 
            // with a History MultiView element
            Set<TopComponent> tcs = TopComponent.getRegistry().getOpened();
            for (final TopComponent tc : tcs) {
                Lookup l = tc.getLookup();
                final DataObject tcDataObject = l.lookup(DataObject.class);
                if (tcDataObject != null && dataObject.equals(tcDataObject)) { 
                    final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
                    if(handler != null) {
                        if(activateHistoryTab(handler, tc)) {
                            // done, history tab found and activated.
                            return;
                        }
                    } 
                }
            }
            
            final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class);
            if(editorCookie != null) {
                Runnable r = new Runnable() {
                    @Override
                    public void run() {
                        JEditorPane pane = NbDocument.findRecentEditorPane(editorCookie);
                        if(pane != null) {
                            // editor is oen, though we havent found a multiview => open the LH top component
                            openLocalHistoryTC(files);
                        }
                    }
                };
                if(SwingUtilities.isEventDispatchThread()) {
                    r.run();
                } else {
                    SwingUtilities.invokeLater(r);
                }
            }
           
            EditCookie editCookie = dataObject.getLookup().lookup(EditCookie.class);
            if(editCookie != null) {
            // no editor found, lets open it...
                // editcookie might return imediately, so listen for the TC 
                // to be opened and activate then
                TopComponent.getRegistry().addPropertyChangeListener(new TCOpenedListener(dataObject, files));
                editCookie.edit();
                return;
            }
        }
    }
    openLocalHistoryTC(files);
}