Java Code Examples for org.openide.WizardDescriptor#Iterator

The following examples show how to use org.openide.WizardDescriptor#Iterator . 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: NewJavaFileWizardIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Optional<WizardDescriptor.InstantiatingIterator<WizardDescriptor>> asInstantiatingIterator(
        @NullAllowed final WizardDescriptor.Iterator<WizardDescriptor> it) {
    return Optional.ofNullable(it)
            .map((p)->{
                return p instanceof WizardDescriptor.InstantiatingIterator ?
                        (WizardDescriptor.InstantiatingIterator<WizardDescriptor>) p:
                        null;
            });
}
 
Example 2
Source File: ImportImageWizard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ImportImageWizard(WizardDescriptor.Iterator iterator) {
    super(iterator);
    wizardIterator = iterator;

    putProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); // NOI18N
    putProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, Boolean.TRUE); // NOI18N
    putProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, Boolean.TRUE); // NOI18N

    setTitle(NbBundle.getMessage(ImportImageWizard.class, "ImportImageWizard.Title")); // NOI18N
    setTitleFormat(new java.text.MessageFormat("{0}")); // NOI18N

    putProperty(WizardDescriptor.PROP_CONTENT_DATA,  // NOI18N
                new String[] { NbBundle.getMessage(ImportImageWizard.class, "ImportImageWizard.Step1"), // NOI18N
                               NbBundle.getMessage(ImportImageWizard.class, "ImportImageWizard.Step2") }); // NOI18N
}
 
Example 3
Source File: I18nTestWizardAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets wizard iterator thru panels used in wizard invoked by this action, 
 * i.e I18N wizard. */
private WizardDescriptor.Iterator getWizardIterator() {
    WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[3];
    
    panels[0] = new SourceWizardPanel.Panel(true);
    panels[1] = new ResourceWizardPanel.Panel(true);
    panels[2] = new TestStringWizardPanel.Panel();
    
    return new WizardDescriptor.ArrayIterator(panels);
        
}
 
Example 4
Source File: I18nWizardDescriptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new I18nWizardDescriptor */
private I18nWizardDescriptor(WizardDescriptor.Iterator<Settings> panels, Settings settings) {
    super(panels, settings);
    
    this.panels = panels;
    this.settings = settings;
}
 
Example 5
Source File: I18nWizardAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets wizard iterator thru panels used in wizard invoked by this action, 
 * i.e I18N wizard. */
private WizardDescriptor.Iterator<I18nWizardDescriptor.Settings> getWizardIterator() {
    List<WizardDescriptor.Panel<I18nWizardDescriptor.Settings>> panels
            = new ArrayList<WizardDescriptor.Panel<I18nWizardDescriptor.Settings>>(4);
    
    panels.add(new SourceWizardPanel.Panel());
    panels.add(new ResourceWizardPanel.Panel());
    panels.add(new AdditionalWizardPanel.Panel());
    panels.add(new HardStringWizardPanel.Panel());
    
    return new WizardDescriptor.ArrayIterator<I18nWizardDescriptor.Settings>(
        panels.toArray(new WizardDescriptor.Panel[panels.size()])
    );
}
 
Example 6
Source File: InstallUnitWizard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean implInvokeWizard (WizardDescriptor.Iterator<WizardDescriptor> iterator) {
    WizardDescriptor wizardDescriptor = new WizardDescriptor (iterator);
    wizardDescriptor.setModal (true);
    
    wizardDescriptor.setTitleFormat (new MessageFormat(NbBundle.getMessage (InstallUnitWizard.class, "InstallUnitWizard_MessageFormat")));
    wizardDescriptor.setTitle (NbBundle.getMessage (InstallUnitWizard.class, "InstallUnitWizard_Title"));
    
    Dialog dialog = DialogDisplayer.getDefault ().createDialog (wizardDescriptor);
    dialog.setVisible (true);
    dialog.toFront ();
    boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
    log.log (Level.FINE, "InstallUnitWizard returns with value " + wizardDescriptor.getValue ());
    return !cancelled;
}
 
Example 7
Source File: NewFileIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private WizardDescriptor.Iterator<WizardDescriptor> getSimpleIterator () {
    if (simpleIterator == null) {
        assert panel != null;
        simpleIterator = new WizardDescriptor.ArrayIterator<WizardDescriptor>(Collections.singletonList(panel));
    }
    return simpleIterator;
}
 
Example 8
Source File: NewJavaFileWizardIterator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private WizardDescriptor.Panel[] createPanels (
        @NonNull final WizardDescriptor wizardDescriptor,
        @NonNull final WizardDescriptor.Iterator<WizardDescriptor> it) {
    
    // Ask for Java folders
    Project project = Templates.getProject( wizardDescriptor );
    if (project == null) throw new NullPointerException ("No project found for: " + wizardDescriptor);
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    assert groups != null : "Cannot return null from Sources.getSourceGroups: " + sources;
    groups = checkNotNull (groups, sources);
    if (groups.length == 0) {
        groups = sources.getSourceGroups( Sources.TYPE_GENERIC ); 
        groups = checkNotNull (groups, sources);
        return new WizardDescriptor.Panel[] {            
            Templates.buildSimpleTargetChooser(project, groups).create(),
        };
    }
    else {
        final List<WizardDescriptor.Panel<?>> panels = new ArrayList<>();
        if (this.type == Type.FILE) {
            panels.add(JavaTemplates.createPackageChooser( project, groups ));
        } else if (type == Type.PKG_INFO) {
            panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PKG_INFO, true));
        } else if (type == Type.MODULE_INFO) {
            panels.add(new JavaTargetChooserPanel(project, groups, null, Type.MODULE_INFO, false));
        } else {
            assert type == Type.PACKAGE;
            SourceGroup[] groovySourceGroups = sources.getSourceGroups(SOURCE_TYPE_GROOVY);
            if (groovySourceGroups.length > 0) {
                List<SourceGroup> all = new ArrayList<>();
                all.addAll(Arrays.asList(groups));
                all.addAll(Arrays.asList(groovySourceGroups));
                groups = all.toArray(new SourceGroup[all.size()]);
            }

            SourceGroup[] resources = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
            assert resources != null;
            if (resources.length > 0) { // #161244
                List<SourceGroup> all = new ArrayList<SourceGroup>();
                all.addAll(Arrays.asList(groups));
                all.addAll(Arrays.asList(resources));
                groups = all.toArray(new SourceGroup[all.size()]);
            }
            panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PACKAGE, false));
        }
        if (it != null) {
            if (it.current() != null) {
                panels.add(it.current());
            }
            while(it.hasNext()) {
                it.nextPanel();
                panels.add(it.current());
            }
        }
        return panels.toArray(new WizardDescriptor.Panel<?>[panels.size()]);
    }
}
 
Example 9
Source File: I18nWizardDescriptor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Creates I18N wizard descriptor.
 * @return <code>I18nWizardDescriptor</code> instance. */
static WizardDescriptor createI18nWizardDescriptor(WizardDescriptor.Iterator<Settings> panels, Settings settings) {
    return new I18nWizardDescriptor(panels, settings);
}
 
Example 10
Source File: HTMLTemplateTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Test public void checkTheIterator() throws Exception {
    final String path = "Templates/Test/x.js";
    FileObject fo = FileUtil.getConfigFile(path);
    assertNotNull(fo);
    
    FileObject tmp = fo.getFileSystem().getRoot().createFolder("tmp");
    DataFolder tmpF = DataFolder.findFolder(tmp);
    
    DataObject obj = DataObject.find(fo);
    
    final TemplateWizard tw = new TemplateWizard();
    tw.setTemplate(obj);
    tw.setTargetName("test");
    tw.setTargetFolder(tmpF);

    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tw.doNextClick();
        }
    });
    
    Field f = tw.getClass().getDeclaredField("iterator");
    f.setAccessible(true);
    WizardDescriptor.Iterator<?> master = (WizardDescriptor.Iterator<?>) f.get(tw);
    assertNotNull("Master iterator found", master);
    
    WizardDescriptor.Panel<?> p1 = master.current();
    assertNotNull("Panel found", p1);
    assertTrue("It is HTML wizard: " + p1, p1 instanceof HTMLPanel);
    final HTMLPanel h1 = (HTMLPanel) p1;
    HTMLWizard it = (HTMLWizard) h1.getWizard();
    
    final CountDownLatch cdl = it.initializationDone;
    cdl.await();
    
    Component cmp1 = p1.getComponent();
    assertNotNull("component initialized", cmp1);
    
    while (!p1.isValid()) {
        awaitFX();
    }
    assertTrue("error code set to 0", p1.isValid());

    awaitSwing();
    assertSelectedIndex("Zero th panel is selected", cmp1, 0);
    
    assertSteps("There steps", cmp1, "One", "Two", "Three");
    
    assertCurrentStep(h1, "One");

    h1.getWizard().setProp("errorCode", 10);
    assertFalse("Now we are not valid", h1.getWizard().isValid());
    
    h1.getWizard().setProp("errorCode", 0);
    assertTrue("Now we are valid", h1.getWizard().isValid());
    
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            try {
                h1.getWizard().nextPanel();
                assertCurrentStep(h1, "Two");

                h1.getWizard().nextPanel();
                assertCurrentStep(h1, "Three");
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    });
    final Set res = h1.getWizard().instantiate();
    assertEquals("One file created: " + res, res.size(), 1);
    
    final DataObject[] dobjPtr = new DataObject[] { null };
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            Object dObj = res.iterator().next();
            assertTrue("It is data object: " + dObj, dObj instanceof DataObject);
            dobjPtr[0] = (DataObject) dObj;
        }
    });
    
    FileObject created = dobjPtr[0].getPrimaryFile();
    
    assertTrue("Error: " + created.asText(), created.asText().contains("Hello from Finished"));
}
 
Example 11
Source File: HTMLJavaTemplateTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Test public void checkTheIterator() throws Exception {
    final String path = "Templates/JavaTest/x.js";
    FileObject fo = FileUtil.getConfigFile(path);
    assertNotNull(fo);
    
    FileObject tmp = fo.getFileSystem().getRoot().createFolder("tmp");
    DataFolder tmpF = DataFolder.findFolder(tmp);
    
    DataObject obj = DataObject.find(fo);
    
    final TemplateWizard tw = new TemplateWizard();
    tw.setTemplate(obj);
    tw.setTargetName("test");
    tw.setTargetFolder(tmpF);

    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tw.doNextClick();
        }
    });
    
    Field f = tw.getClass().getDeclaredField("iterator");
    f.setAccessible(true);
    WizardDescriptor.Iterator<?> master = (WizardDescriptor.Iterator<?>) f.get(tw);
    assertNotNull("Master iterator found", master);
    
    WizardDescriptor.Panel<?> p1 = master.current();
    assertNotNull("Panel found", p1);
    assertTrue("It is HTML wizard: " + p1, p1 instanceof HTMLPanel);
    HTMLPanel h1 = (HTMLPanel) p1;
    HTMLWizard it = (HTMLWizard) h1.getWizard();
    
    final CountDownLatch cdl = it.initializationDone;
    cdl.await();
    
    Component cmp1 = p1.getComponent();
    assertNotNull("component initialized", cmp1);
    assertEquals("the right title", "One", cmp1.getName());
    
    while (!p1.isValid()) {
        awaitFX();
    }
    assertTrue("error code set to 0", p1.isValid());

    try {
        System.setProperty("assertgc.paths", "0");
        NbTestCase.assertGC("Shouldn't GC", it.ref());
        throw new IllegalStateException("Ref for " + it.data() + " should exist: " + it.ref().get());
    } catch (AssertionError ex) {
        // OK
    }
    
    assertSelectedIndex("Zero th panel is selected", cmp1, 0);
    
    assertSteps("There steps", cmp1, "One", "Two", "Three");
    
    assertCurrentStep(h1, "One");

    h1.getWizard().setProp("errorCode", 10);
    assertFalse("Now we are not valid", h1.getWizard().isValid());
    
    h1.getWizard().setProp("errorCode", 0);
    assertTrue("Now we are valid", h1.getWizard().isValid());
    
    h1.getWizard().nextPanel();
    assertCurrentStep(h1, "Two");
    
    h1.getWizard().nextPanel();
    assertCurrentStep(h1, "Three");
    
    Set res = h1.getWizard().instantiate();
    assertEquals("One file created: " + res, res.size(), 1);
    
    Object dObj = res.iterator().next();
    assertTrue("It is data object: " + dObj, dObj instanceof DataObject);
    
    FileObject created = ((DataObject)dObj).getPrimaryFile();
    
    assertTrue("Error: " + created.asText(), created.asText().contains("Hello from Finished"));
    
    assertEquals("Three techIds", it.getTechIds().length, 3);
    assertEquals("ein", it.getTechIds()[0]);
    assertEquals("zwei", it.getTechIds()[1]);
    assertEquals("drei", it.getTechIds()[2]);
}
 
Example 12
Source File: InstallUnitWizard.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean invokeWizard (InstallUnitWizardModel model, boolean allowRunInBackground) {
    WizardDescriptor.Iterator<WizardDescriptor> iterator;
    iterator = new InstallUnitWizardIterator (model, true, allowRunInBackground);
    return implInvokeWizard (iterator);
}
 
Example 13
Source File: InstallUnitWizard.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean invokeWizard(InstallUnitWizardModel model, boolean allowRunInBackground, boolean runInBackground) {
    WizardDescriptor.Iterator<WizardDescriptor> iterator;
    iterator = new InstallUnitWizardIterator(model, true, allowRunInBackground, runInBackground);
    return implInvokeWizard(iterator);
}