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

The following examples show how to use org.openide.loaders.DataObject#isTemplate() . 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: TemplatesPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected Node[] createNodes(Node key) {
    Node [] orig = super.createNodes (key);
    Node [] filtered = new Node [orig.length];
    for (int i = 0; i < orig.length; i++) {
        FileObject fo = orig[i].getLookup ().lookup(FileObject.class);
        boolean isTemplate;
        if (fo != null) {
            isTemplate = isTemplate(fo);
        } else {
            DataObject dobj = getDOFromNode (orig [i]);
            isTemplate = dobj.isTemplate();
        }
        if (isTemplate) {
            filtered [i] = new TemplateNode (orig [i], Children.LEAF);
        } else {
            filtered [i] = new TemplateNode (orig [i]);
        }
    }
    return filtered;
}
 
Example 2
Source File: JavaNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Create a node for the Java data object using the default children.
* @param jdo the data object to represent
*/
public JavaNode (final DataObject jdo, boolean isJavaSource) {
    super (jdo, Children.LEAF);
    this.isJavaSource = isJavaSource;
    this.isCompiled = new AtomicReference<>();
    this.isExecutable = new AtomicReference<>();
    this.computedIcon = new AtomicReference<>();
    this.computedIconListener = new AtomicReference<>();
    this.setIconBaseWithExtension(isJavaSource ? JAVA_ICON_BASE : CLASS_ICON_BASE);
    Logger.getLogger("TIMER").log(Level.FINE, "JavaNode", new Object[] {jdo.getPrimaryFile(), this});
    if (!jdo.isTemplate()) {
        WORKER.post(IconTask.create(this));
        if (isJavaSource) {
            WORKER.post(new BuildStatusTask(this));
            WORKER.post(new ExecutableTask(this));
            jdo.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (DataObject.PROP_PRIMARY_FILE.equals(evt.getPropertyName())) {
                        Logger.getLogger("TIMER").log(Level.FINE, "JavaNode", new Object[]{jdo.getPrimaryFile(), this});
                        WORKER.post(new Runnable() {
                            public void run() {
                                computedIconListener.set(null);
                                synchronized (JavaNode.this) {
                                    status = null;
                                    executableListener = null;
                                    WORKER.post(new BuildStatusTask(JavaNode.this));
                                    WORKER.post(new ExecutableTask(JavaNode.this));
                                }
                            }
                        });
                    }
                }
            });
        }
    }
}
 
Example 3
Source File: DefaultFileObjectFromTemplateCreator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public FileObject create(FileObject template, FileObject folder, String name) throws IOException {
    DataObject templateDobj = DataObject.find(template);
    if (templateDobj == null || !templateDobj.isTemplate()) {
        return FileUtil.createData(folder, name);
    }
    DataFolder target = DataFolder.findFolder(folder);
    String simpleName = FileObjects.stripExtension(name);
    DataObject newDobj = templateDobj.createFromTemplate(target, simpleName);
    return newDobj.getPrimaryFile();
}
 
Example 4
Source File: ProjectTemplatePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node[] createNodes(DataObject dobj) {
    if (dobj.isTemplate()) {
        Node templateNode = new FilterNode(dobj.getNodeDelegate(), Children.LEAF);
        if( null == filterText || templateNode.getDisplayName().toLowerCase().contains( filterText.toLowerCase() ) )
            return new Node[] { templateNode };
    }
    return new Node[0];
}
 
Example 5
Source File: TemplateChooserPanelGUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isTemplate (DataObject dobj) {
    if (dobj.isTemplate())
        return true;
    if (dobj instanceof DataShadow) {
        return ((DataShadow)dobj).getOriginal().isTemplate();
    }
    return false;
}
 
Example 6
Source File: CatalogPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean acceptTemplate(DataObject d) {
    if (d.isTemplate() || d instanceof DataFolder) {
        Object o = d.getPrimaryFile().getAttribute("simple"); // NOI18N
        return o == null || Boolean.TRUE.equals(o);
    } else {
        return false;
    }
}
 
Example 7
Source File: InstantiateAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected boolean enable (Node[] activatedNodes) {
    if (activatedNodes.length != 1) return false;
    DataObject obj = activatedNodes[0].getCookie(DataObject.class);
    return obj != null && obj.isTemplate ();
}