Java Code Examples for org.openide.loaders.DataFolder

The following examples show how to use org.openide.loaders.DataFolder. These examples are extracted from open source projects. 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 Project: netbeans   Source File: DnDSupport.java    License: Apache License 2.0 6 votes vote down vote up
private void reorderButtons( DataObject objToMove, DataObject objUnderCursor ) throws IOException {
    DataFolder backingFolder = getBackingFolder(currentToolbar);
    List<DataObject> children = new ArrayList<DataObject>( Arrays.asList( backingFolder.getChildren() ) );
    if( null == objUnderCursor ) {
        children.remove( objToMove );
        children.add( objToMove );
    } else {
        int targetIndex = children.indexOf( objUnderCursor );
        int currentIndex = children.indexOf( objToMove );
        if( currentIndex < targetIndex )
            targetIndex--;
        targetIndex = Math.max( 0, targetIndex );
        targetIndex = Math.min( children.size(), targetIndex );
        children.remove( objToMove );
        children.add( targetIndex, objToMove );
    }

    backingFolder.setOrder( children.toArray( new DataObject[children.size()]) );
}
 
Example 2
Source Project: netbeans   Source File: NewFileWizardIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Set<FileObject> instantiate() throws IOException {
    FileObject dir = Templates.getTargetFolder(wizard);
    FileObject template = Templates.getTemplate(wizard);

    DataFolder dataFolder = DataFolder.findFolder(dir);
    DataObject dataTemplate = DataObject.find(template);
    DataObject createdFile = dataTemplate.createFromTemplate(dataFolder, Templates.getTargetName(wizard), getTemplateParams());

    // #187374
    try {
        FileUtils.reformatFile(createdFile);
    } catch (IOException exc) {
        LOGGER.log(Level.WARNING, exc.getMessage(), exc);
    }

    return Collections.singleton(createdFile.getPrimaryFile());
}
 
Example 3
Source Project: netbeans   Source File: DTDWizardIterator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This is where, the schema gets instantiated from the template.
 */
public Set instantiate (TemplateWizard wizard) throws IOException {        
    FileObject dir = Templates.getTargetFolder( wizard );        
    DataFolder df = DataFolder.findFolder( dir );
    FileObject template = Templates.getTemplate( wizard );        
    DataObject dTemplate = DataObject.find( template );                
    DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard));
    if (dobj == null)
        return Collections.emptySet();
        
    encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile());
    if(!EncodingUtil.isValidEncoding(encoding))
        encoding = "UTF-8"; //NOI18N
    EditCookie edit = dobj.getCookie(EditCookie.class);
    if (edit != null) {
        EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
        Document doc = (Document)editorCookie.openDocument();
        fixEncoding(doc, encoding);
        SaveCookie save = dobj.getCookie(SaveCookie.class);
        if (save!=null) save.save();
    }
    
    return Collections.singleton(dobj.getPrimaryFile());
}
 
Example 4
Source Project: netbeans   Source File: ActionPasteType.java    License: Apache License 2.0 6 votes vote down vote up
/**
*  
*/ 
   static PasteType getPasteType(final DataFolder targetFolder, final Transferable transfer) {
       final FileObject folder = targetFolder.getPrimaryFile();
       PasteType retVal = null;

       try {
           /*Copy/Cut/Paste is allowed just on SystemFileSystem*/ 
           if (folder.getFileSystem().isDefault()) {
               final int[] pasteOperations = new int[]{LoaderTransfer.CLIPBOARD_COPY, LoaderTransfer.CLIPBOARD_CUT};

               for (int i = 0; i < pasteOperations.length; i++) {
                   final DataObject[] dataObjects = LoaderTransfer.getDataObjects(transfer, pasteOperations[i]);
                   if (dataObjects != null) {                                                
                       if (canBePasted(dataObjects, targetFolder, pasteOperations[i])) {
                           retVal = new PasteTypeImpl(Arrays.asList(dataObjects), targetFolder, pasteOperations[i]);
                           break;
                       }
                   }
               }
           }
       } catch (FileStateInvalidException e) {/*just null is returned if folder.getFileSystem fires ISE*/}

       return retVal;
   }
 
Example 5
Source Project: netbeans   Source File: TemplatesPanel.java    License: Apache License 2.0 6 votes vote down vote up
static private DataFolder getTargetFolder (Node [] nodes) {
    DataFolder folder;
    if (nodes == null || nodes.length == 0) {
        folder = DataFolder.findFolder (getTemplatesRoot ());
    } else {
        // try if has a data folder (alert: leaf node can be a empty folder)
        folder = nodes[0].getLookup ().lookup (DataFolder.class);
        
        // if not this node then try its parent
        if (folder == null && nodes [0].isLeaf ()) {
            Node parent = nodes [0].getParentNode ();
            folder = parent.getLookup ().lookup (DataFolder.class);
        }
    }
    return folder;
}
 
Example 6
Source Project: netbeans   Source File: JavaDataLoaderTest.java    License: Apache License 2.0 6 votes vote down vote up
private void recognize(int count) throws IOException {
    clearWorkDir();
    FileUtil.refreshAll();

    File wd = getWorkDir();

    while (count-- > 0) {
        new FileOutputStream(new File(wd, "f" + count + ".java")).close();
        new FileOutputStream(new File(wd, "f" + count + ".bbb")).close();
    }

    long s = System.currentTimeMillis();
    FileUtil.refreshAll();

    FileObject f = FileUtil.toFileObject(wd);
    DataFolder df = DataFolder.findFolder(f);

    System.err.println("preparation took: " + (System.currentTimeMillis() - s));
    System.err.println(df.getChildren().length);
    System.err.println("recognition took:" + (System.currentTimeMillis() - s));
}
 
Example 7
Source Project: netbeans   Source File: Util.java    License: Apache License 2.0 6 votes vote down vote up
/** Adds source to source map (I18N wizard settings). If there is already no change is done.
 * If it's added anew then it is tried to find correspondin reousrce, i.e.
 * first resource from the same folder.
 * @param sourceMap settings where to add teh sources
 * @param source source to add */
public static void addSource(Map<DataObject,SourceData> sourceMap,
                             DataObject source) {
    if (sourceMap.containsKey(source)) {
        return;
    }
    
    DataFolder folder = source.getFolder();
    
    if (folder == null) {
        sourceMap.put(source, null);
        return;
    }

    // try to associate Bundle file

    for (DataObject child : folder.getChildren()) {
        if (child instanceof PropertiesDataObject) { // PENDING 
            sourceMap.put(source, new SourceData(child));
            return;
        }
    }
    
    // No resource found in the same folder.
    sourceMap.put(source, null);
}
 
Example 8
Source Project: netbeans   Source File: JavaTemplateAttributesProvider.java    License: Apache License 2.0 6 votes vote down vote up
public Map<String,?> attributesFor(DataObject template, DataFolder target, String name) {
    FileObject templateFO = template.getPrimaryFile();
    if (!JavaDataLoader.JAVA_EXTENSION.equals(templateFO.getExt()) || templateFO.isFolder()) {
        return null;
    }
    
    FileObject targetFO = target.getPrimaryFile();
    Map<String,Object> result = new HashMap<String,Object>();
    
    ClassPath cp = ClassPath.getClassPath(targetFO, ClassPath.SOURCE);
    if (cp == null) {
        LOG.warning("No classpath was found for folder: " + target.getPrimaryFile()); // NOI18N
    }
    else {
        result.put("package", cp.getResourceName(targetFO, '.', false)); // NOI18N
    }
    
    String sourceLevel = SourceLevelQuery.getSourceLevel(targetFO);
    if (sourceLevel != null) {
        result.put("javaSourceLevel", sourceLevel); // NOI18N
        if (isJava15orLater(sourceLevel))
            result.put("java15style", Boolean.TRUE); // NOI18N
    }
    
    return result;
}
 
Example 9
Source Project: netbeans   Source File: OpenProjectFolderAction.java    License: Apache License 2.0 6 votes vote down vote up
public ContextAction(Lookup context) {
    super(OpenProjectFolderAction_LBL_action());
    this.context = context;
    boolean foundProject = false;
    for (DataFolder d : context.lookupAll(DataFolder.class)) {
        if (ProjectManager.getDefault().isProject(d.getPrimaryFile())) {
            foundProject = true;
            break;
        }
    }
    if (!foundProject) {
        putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
        setEnabled(false);
    }
    // #199137: do not try to adjust label, etc. according to actual projects
    // 1. such computation cannot be done in EQ without sometimes blocking
    // 2. even if done asynch, looks bad to update label after popup is posted
}
 
Example 10
Source Project: netbeans   Source File: DocumentTitlePropertyTest.java    License: Apache License 2.0 6 votes vote down vote up
/** Test updating document property Document.TitleProperty when dataobject is moved */
public void testMove () throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    FileUtil.createFolder(FileUtil.getConfigRoot(), "newFolder");

    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    DataFolder dFolder = (DataFolder) DataObject.find(FileUtil.getConfigFile("newFolder"));

    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    EditorCookie ec = obj.getCookie(EditorCookie.class);

    StyledDocument doc = ec.openDocument();

    String val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("someFolder/someFile.obj"));

    obj.move(dFolder);

    val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("newFolder/someFile.obj"));
}
 
Example 11
Source Project: netbeans   Source File: DefaultCreationNoTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks that a file without CreateFromTemplate handler creates OK as copy of the template
 * @throws Exception 
 */
public void testCreateNoHandler() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject templ = FileUtil.createData(root, "simpleTemplate.txt");
    String txt = "{a}";
    OutputStream os = templ.getOutputStream();
    os.write(txt.getBytes());
    os.close();
    
    DataObject obj = DataObject.find(templ);
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    Map m = new HashMap();
    m.put("a", "eeee");
    DataObject x = obj.createFromTemplate(folder, "nue", m);
    
    assertEquals(txt + "\n", x.getPrimaryFile().asText());
}
 
Example 12
Source Project: netbeans   Source File: DefaultPlugin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new test class.
 * 
 * @param  targetRoot     <!-- //PENDING -->
 * @param  testClassName  <!-- //PENDING -->
 * @param  testCreator  {@code TestCreator} to be used for filling
 *                      the test class template
 * @param  templateDataObj  {@code DataObject} representing
 *                          the test file template
 * @return  the created test, or {@code null} if no test was created
 */
private DataObject createEmptyTest(FileObject targetRoot,
                                   String testClassName,
                                   TestCreator testCreator,
                                   final Map<String, ? extends Object> templateParams,
                                   DataObject templateDataObj) {
    if (testClassName == null) {
        throw new IllegalArgumentException("testClassName = null"); //NOI18N
    }
    
    DataObject testDataObj = null;
    try {
        DataFolder targetFolderDataObj = DataFolder.findFolder(targetRoot);
        testDataObj = templateDataObj.createFromTemplate(
                                    targetFolderDataObj,
                                    testClassName,
                                    templateParams);

        /* fill in setup etc. according to dialog settings */
        testCreator.createEmptyTest(testDataObj.getPrimaryFile());
    } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
    }
    return testDataObj;
}
 
Example 13
Source Project: netbeans   Source File: TargetEvaluator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Used by the ObjectNameWizard panel to set the target folder
 * gotten from the system wizard initially. 
 */
void setInitialFolder(DataFolder selectedFolder, Project p) {
    if (selectedFolder == null) {
        return;
    }
    FileObject targetFolder = selectedFolder.getPrimaryFile();
    Sources sources = ProjectUtils.getSources(p);
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    String packageName = null;
    for (int i = 0; i < groups.length && packageName == null; i++) {
        packageName = org.openide.filesystems.FileUtil.getRelativePath(groups[i].getRootFolder(), targetFolder);
        deployData.setWebApp(DeployData.getWebAppFor(groups[i].getRootFolder()));
    }
    if (packageName == null) {
        packageName = "";
    }
    setInitialPath(packageName);
}
 
Example 14
Source Project: netbeans   Source File: PropertiesDataObject.java    License: Apache License 2.0 6 votes vote down vote up
/** Copies primary and secondary files to new folder.
     * Overrides superclass method.
     * @param df the new folder
     * @return data object for the new primary
     * @throws IOException if there was a problem copying
     * @throws UserCancelException if the user cancelled the copy */
    @Override
    protected synchronized DataObject handleCopy(DataFolder df) throws IOException {
        if (LOG.isLoggable(FINER)) {
            LOG.finer("handleCopy("                                     //NOI18N
                    + FileUtil.getFileDisplayName(df.getPrimaryFile()) + ')');
        }
        try {
//            pasteSuffix = createPasteSuffix(df);

            return super.handleCopy(df);
        } finally {
            pasteSuffix = null;
            bundleStructure = null;
        }
    }
 
Example 15
Source Project: netbeans   Source File: CopyClassesUI.java    License: Apache License 2.0 6 votes vote down vote up
private final Vector getNodes() {
    Vector<Node> result = new Vector<Node>(javaObjects.size());
    LinkedList<FileObject> q = new LinkedList<FileObject>(javaObjects);
    while (!q.isEmpty()) {
        FileObject f = q.removeFirst();
        if (!VisibilityQuery.getDefault().isVisible(f)) {
            continue;
        }
        DataObject d = null;
        try {
            d = DataObject.find(f);
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
        if (d instanceof DataFolder) {
            for (DataObject o : ((DataFolder) d).getChildren()) {
                q.addLast(o.getPrimaryFile());
            }
        } else if(d != null) {
            result.add(d.getNodeDelegate());
        }
    }
    return result;
}
 
Example 16
Source Project: netbeans   Source File: AnnotationProviderTest.java    License: Apache License 2.0 6 votes vote down vote up
@RandomlyFails
public void testContextLookupIsConsistentAfterMove() throws Exception {              
    ConsistencyCheckProvider.setCalled(0);
    // Prepare the data object (to initialize the lookup)
    FileObject fo = fs.getRoot().createData("test2", "txt");
    DataObject data = DataObject.find(fo);
    EditorCookie ec = data.getCookie(EditorCookie.class);

    // now move it (the lookup should update itself)
    FileObject fld = fs.getRoot().createFolder("folder1");
    DataFolder df = DataFolder.findFolder(fld);
    data.move(df);

    // now open the editor (invoke AnnotationProviders)
    // and check the lookup
    ec.open();
    assertEquals("Consistent lookup content", data.getPrimaryFile(),ConsistencyCheckProvider.getInLkp());
}
 
Example 17
Source Project: netbeans   Source File: CreateNewNonIndexedProperty.java    License: Apache License 2.0 6 votes vote down vote up
/** setUp method  */
public void setUp() {
    System.out.println("########  "+getName()+"  #######");
    
    OptionsOperator optionsOperator = OptionsOperator.invoke();
    optionsOperator.selectOption(Bundle.getString("org.netbeans.core.Bundle", "UI/Services/Editing")+"|"+Bundle.getString("org.netbeans.modules.beans.Bundle", "PROP_Option_Menu"));
    PropertySheetOperator propertySheetTabOperator = new PropertySheetOperator(optionsOperator);
    new Property(propertySheetTabOperator, Bundle.getString("org.netbeans.modules.beans.Bundle", "PROP_Option_Prop_Style")).setValue(Bundle.getString("org.netbeans.modules.beans.Bundle", "MSG_Option_Gen_This"));

    FileObject testFile = Repository.getDefault().findResource("gui/data/" + NAME_TEST_FILE + ".java");
    FileObject destination = Repository.getDefault().findFileSystem(sampleDir.replace('\\', '/')).getRoot();
    optionsOperator.close();
    try {
        DataObject.find(testFile).copy(DataFolder.findFolder(destination));
    } catch (IOException e) {
        fail(e);
    }
    new PropertiesAction().perform();
}
 
Example 18
Source Project: netbeans   Source File: I18nUtil.java    License: Apache License 2.0 6 votes vote down vote up
/** 
 * Indicates if folder or its subfolders contains data object
 * that is supported by any internationalization factory. 
 */
public static boolean containsAcceptedDataObject(DataFolder folder) {
    DataObject[] children = folder.getChildren();
    DataObject[] folders = new DataObject[children.length];
    int i, foldersCount = 0;

    for (DataObject child : children) {
        if (child instanceof DataFolder) {  
            folders[foldersCount++] = child;
        } else if (FactoryRegistry.hasFactory(child.getClass())) {
            return true;
        }
    }
    for (i = 0; i < foldersCount; i++) {
        if (containsAcceptedDataObject((DataFolder) children[i])) {
            return true;
        }
    }
    return false;
}
 
Example 19
Source Project: netbeans   Source File: NewTestSuiteWizardIterator.java    License: Apache License 2.0 6 votes vote down vote up
public Set<DataObject> instantiate() throws IOException {
    FileObject targetFolder = Templates.getTargetFolder(wiz);
    TestNGSupport.findTestNGSupport(FileOwnerQuery.getOwner(targetFolder)).configureProject(targetFolder);
    String targetName = Templates.getTargetName(wiz);

    DataFolder df = DataFolder.findFolder(targetFolder);
    FileObject template = Templates.getTemplate(wiz);

    DataObject dTemplate = DataObject.find(template);
    String pkgName = getSelectedPackageName(targetFolder);
    String suiteName = pkgName + " suite";
    String projectName = ProjectUtils.getInformation(FileOwnerQuery.getOwner(targetFolder)).getName();
    if (pkgName == null || pkgName.trim().length() < 1) {
        pkgName = ".*"; //NOI18N
        suiteName = "All tests for " + projectName;
    }
    
    Map<String, String> props = new HashMap<String, String>();
    props.put("suiteName", projectName);
    props.put("testName", suiteName);
    props.put("pkg", pkgName);

    DataObject dobj = dTemplate.createFromTemplate(df, targetName, props);

    return Collections.singleton(dobj);
}
 
Example 20
Source Project: netbeans   Source File: ValidateLayerConsistencyTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void loadChildren(FileObject folder) {
    List<FileObject> kids = new ArrayList<FileObject>();
    for (DataObject kid : DataFolder.findFolder(folder).getChildren()) {
        kids.add(kid.getPrimaryFile());
    }
    FileUtil.getOrder(kids, true);
}
 
Example 21
Source Project: netbeans   Source File: PackageViewChildren.java    License: Apache License 2.0 5 votes vote down vote up
protected Node[] createNodes(String path) {
    FileObject fo = root.getFileObject(path);
    if ( fo != null && fo.isValid() && fo.isFolder()) {
        Object o = names2nodes.get(path);
        PackageNode n;
        DataFolder folder;
        try {
            folder = DataFolder.findFolder(fo);
        } catch (IllegalArgumentException iae) {
            if (!fo.isValid()) {
                return new Node[0];
            } else {
                throw new IllegalStateException(
                    MessageFormat.format(
                        "Root: {0}, Path: {1}, Visible: {2}, Valid: {3}",           //NOI18N
                        FileUtil.getFileDisplayName(root),
                        path,
                        VisibilityQuery.getDefault().isVisible(fo),
                        fo.isValid()),
                    iae);
            }
        }
        if (folder.isValid()) {
            if ( o == NODE_NOT_CREATED ) {
                n = new PackageNode(root, folder, false);
            } else { // NODE_NOT_CREATED_EMPTY, PackageNode
                n = new PackageNode(root, folder);
            }
            names2nodes.put(path, n);
            return new Node[] {n};
        }
    }
    return new Node[0];
}
 
Example 22
Source Project: netbeans   Source File: TemplatesPanel.java    License: Apache License 2.0 5 votes vote down vote up
static Node getTemplateRootNode () {
    if (templatesRootNode == null) {
        DataFolder df = DataFolder.findFolder (getTemplatesRoot ());
        templatesRootNode = new TemplateNode (new FilterNode (df.getNodeDelegate (), df.createNodeChildren (new TemplateFilter ())));
    }
    return templatesRootNode;
}
 
Example 23
Source Project: netbeans   Source File: DefaultSettings.java    License: Apache License 2.0 5 votes vote down vote up
private String constructPrefsFileName( Model model ) {
    DataFolder dof = (DataFolder)model.getRoot().lookup( DataFolder.class );
    if( null != dof ) {
        FileObject fo = dof.getPrimaryFile();
        if( null != fo ) {
            return fo.getPath();
        }
    }
    return model.getName();
}
 
Example 24
Source Project: netbeans   Source File: ProjectCustomizerTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testReadCategories() throws Exception {
    FileObject customizerFO = FileUtil.createFolder(FileUtil.getConfigRoot(), "Projects/test/Customizer");
    // - One         | one
    // + Category #1 | two
    //   - Three     | three
    // + Category #2 |
    //   - Four      | four
    DelegateCategoryProvider dcp = new DelegateCategoryProvider(DataFolder.findFolder(customizerFO), null);
    Category categories[] = dcp.readCategories(DataFolder.findFolder(customizerFO));
    assertNotNull(categories);
    assertEquals(3, categories.length);
    assertEquals("one", categories[0].getName());
    assertEquals("One", categories[0].getDisplayName());
    assertEquals("one", dcp.create(categories[0]).getName());
    assertEquals("Category1", categories[1].getName());
    assertEquals("Category #1", categories[1].getDisplayName());
    assertEquals("two", dcp.create(categories[1]).getName());
    Category[] subcategories = categories[1].getSubcategories();
    assertEquals(1, subcategories.length);
    assertEquals("three", subcategories[0].getName());
    assertEquals("Three", subcategories[0].getDisplayName());
    assertEquals("three", dcp.create(subcategories[0]).getName());
    assertEquals("Category2", categories[2].getName());
    assertEquals("Category #2", categories[2].getDisplayName());
    assertEquals(null, dcp.create(categories[2]).getName());
    subcategories = categories[2].getSubcategories();
    assertEquals(1, subcategories.length);
    assertEquals("four", subcategories[0].getName());
    assertEquals("Four", subcategories[0].getDisplayName());
    assertEquals("four", dcp.create(subcategories[0]).getName());
}
 
Example 25
Source Project: netbeans   Source File: J2SEWizardIterator.java    License: Apache License 2.0 5 votes vote down vote up
public J2SEWizardIterator(FileObject installFolder) throws IOException {
    this.installFolder = DataFolder.findFolder(installFolder);
    this.platform = NewJ2SEPlatform.create (installFolder);        
    String archFolder = null;
    for (int i = 0; i< SOLARIS_64_FOLDERS.length; i++) {
        if (Util.findTool("java",Collections.singleton(installFolder),SOLARIS_64_FOLDERS[i]) != null) {
            archFolder = SOLARIS_64_FOLDERS[i];
            break;
        }
    }
    if (archFolder != null) {
        this.secondaryPlatform  = NewJ2SEPlatform.create (installFolder);
        this.secondaryPlatform.setArchFolder(archFolder);
    }
}
 
Example 26
Source Project: netbeans   Source File: Tutorials.java    License: Apache License 2.0 5 votes vote down vote up
private void buildContent() {
    String rootName = "WelcomePage/TutorialsLinks";  // NOI18N
    FileObject root = FileUtil.getConfigFile( rootName );
    if( null == root ) {
        Logger.getLogger(Tutorials.class.getName()).log(Level.INFO,
                "Start page content not found: " + "FileObject: " + rootName ); //NOI18N
        return;
    }
    DataFolder folder = DataFolder.findFolder( root );
    if( null == folder ) {
        Logger.getLogger(Tutorials.class.getName()).log(Level.INFO,
                "Start page content not found: " + "DataFolder: " + rootName ); //NOI18N
        return;
    }
    DataObject[] children = folder.getChildren();
    if( null == children ) {
        Logger.getLogger(Tutorials.class.getName()).log(Level.INFO,
                "Start page content not found: " + "DataObject: " + rootName ); //NOI18N
        return;
    }

    for( int i=0; i<children.length; i++ ) {
        row = addLink( row, children[i] );
    }

    WebLink link = new WebLink(BundleSupport.getLabel("AllOnlineDocs"), BundleSupport.getURL("AllOnlineDocs"), Utils.getLinkColor(), false); //NOI18N
    link.setFont( link.getFont().deriveFont( Font.BOLD ) );
    add( link, new GridBagConstraints(0, row++, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20,0,0,0), 0, 0 ) );

    add( new JLabel(), new GridBagConstraints(0, row++, 1, 1, 0.0, 1.0,
            GridBagConstraints.NORTHWEST, GridBagConstraints.VERTICAL, new Insets(0,0,0,0), 0, 0 ) );
}
 
Example 27
Source Project: netbeans   Source File: NewProtractorConfWizardIterator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Set instantiate() throws IOException {
    FileObject dir = Templates.getTargetFolder(wizard);
    FileObject template = Templates.getTemplate(wizard);

    DataFolder dataFolder = DataFolder.findFolder(dir);
    DataObject dataTemplate = DataObject.find(template);
    DataObject createdFile = dataTemplate.createFromTemplate(dataFolder, Templates.getTargetName(wizard));
    return Collections.singleton(createdFile.getPrimaryFile());
}
 
Example 28
Source Project: netbeans   Source File: PropertiesDataObject.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates new name for this instance when moving/copying to new folder destination. 
 * @param folder new folder destination. */
private String createPasteSuffix(DataFolder folder) {
    String basicName = getPrimaryFile().getName();

    DataObject[] children = folder.getChildren();


    // Repeat until there is not such file name.
    for(int i = 0; ; i++) {
        String newName;

        if (i == 0) {
            newName = basicName;
        } else {
            newName = basicName + i;
        }
        boolean exist = false;

        for(int j = 0; j < children.length; j++) {
            if(children[j] instanceof PropertiesDataObject && newName.equals(children[j].getName())) {
                exist = true;
                break;
            }
        }

        if(!exist) {
            if (i == 0) {
                return ""; // NOI18N
            } else {
                return "" + i; // NOI18N
            }
        }
    }
}
 
Example 29
Source Project: netbeans   Source File: CreateFromTemplateDecoratorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    MockLookup.init();
    root = FileUtil.createMemoryFileSystem().getRoot();
    fo = FileUtil.createData(root, "simpleObject.txt");
    folder = DataFolder.findFolder(target = FileUtil.createFolder(root, "target"));
    obj = DataObject.find(fo);
}
 
Example 30
Source Project: netbeans   Source File: ActivatorIterator.java    License: Apache License 2.0 5 votes vote down vote up
protected List<WizardDescriptor.Panel<WizardDescriptor>> createPanels (Project project, TemplateWizard wiz) {
    Sources sources = ProjectUtils.getSources(project);
    DataFolder targetFolder=null;
    try {
        targetFolder = wiz.getTargetFolder();
    }
    catch (IOException ex) {
        targetFolder = DataFolder.findFolder(project.getProjectDirectory());
    }
    return Collections.<WizardDescriptor.Panel<WizardDescriptor>>singletonList(
        JavaTemplates.createPackageChooser(project,
                      sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA))
        );
}