|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.project.ui; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.MessageFormat; import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.Sources; import org.netbeans.modules.project.uiapi.ProjectChooserFactory; import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.WizardDescriptor; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.loaders.TemplateWizard; import org.openide.util.NbBundle; public final class NewFileWizard extends TemplateWizard { private Project currP; private MessageFormat format; // private String[] recommendedTypes; private Project getCurrentProject () { return currP; } private void setCurrentProject (Project p) { this.currP = p; } public NewFileWizard( Project project /*, String recommendedTypes[] */ ) { setCurrentProject (project); putProperty( ProjectChooserFactory.WIZARD_KEY_PROJECT, getCurrentProject () ); format = new MessageFormat (NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_MessageFormat")); // this.recommendedTypes = recommendedTypes; //setTitleFormat( new MessageFormat( "{0}") ); addPropertyChangeListener (new PropertyChangeListener () { public void propertyChange (PropertyChangeEvent evt) { // check ProjectChooserFactory.WIZARD_KEY_PROJECT property if (ProjectChooserFactory.WIZARD_KEY_PROJECT.equals (evt.getPropertyName ())) { Project newProject = (Project)evt.getNewValue (); if (!getCurrentProject ().equals (newProject)) { // set the new project and force reload panels in wizard setCurrentProject (newProject); try { //reload (DataObject.find (Templates.getTemplate (NewFileWizard.this))); // bugfix #44481, check if the template is null if (Templates.getTemplate (NewFileWizard.this) != null) { Hacks.reloadPanelsInWizard (NewFileWizard.this, DataObject.find (Templates.getTemplate (NewFileWizard.this))); } } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } } } } }); } public static Iterator getIterator (DataObject obj) { // read the attributes declared in module's layer Object unknownIterator = obj.getPrimaryFile ().getAttribute ("instantiatingIterator"); //NOI18N if (unknownIterator == null) { unknownIterator = obj.getPrimaryFile ().getAttribute ("templateWizardIterator"); //NOI18N } // set default NewFileIterator if no attribute is set if (unknownIterator == null) { try { obj.getPrimaryFile ().setAttribute ("instantiatingIterator", NewFileIterator.genericFileIterator ()); //NOI18N } catch (java.io.IOException e) { // can ignore it because a iterator will created though } } // returns iterator created by given attributes return TemplateWizard.getIterator (obj); } public void updateState () { super.updateState (); String substitute = (String)getProperty ("NewFileWizard_Title"); // NOI18N String title; if (substitute == null) { title = NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_Title"); // NOI18N } else { Object[] args = new Object[] { NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_Subtitle"), // NOI18N substitute}; title = format.format (args); } super.setTitle (title); } public void setTitle (String ignore) {} protected WizardDescriptor.Panel createTemplateChooser () { WizardDescriptor.Panel panel = new TemplateChooserPanel( getCurrentProject () /*, recommendedTypes */ ); JComponent jc = (JComponent)panel.getComponent (); jc.getAccessibleContext ().setAccessibleName (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSN_NewFileWizard")); // NOI18N jc.getAccessibleContext ().setAccessibleDescription (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSD_NewFileWizard")); // NOI18N return panel; } protected WizardDescriptor.Panel createTargetChooser () { Sources c = ProjectUtils.getSources(getCurrentProject ()); return Templates.createSimpleTargetChooser(getCurrentProject (), c.getSourceGroups(Sources.TYPE_GENERIC)); } } /** Old impl might be usefull later in Wizards API ///** Wizard for creating new files in a project. // * // * @author Jesse Glick, Petr Hrebejk // */ //public class NewFileWizard implements TemplateWizard.Iterator, ChangeListener { // // /** Currently selected project */ // private Project p; // /** Recommended template types, or null for any. */ // private final String[] recommendedTypes; // /** Currently selected template to delegate subsequent panels to, or null. */ // private InstantiatingIterator delegate = null; // /** True if currently on a panel created by the delegate. */ // private boolean insideDelegate = false; // /** The template chooser panel (initially null). */ // private WizardDescriptor.Panel templateChooser = null; // /** Change listeners. */ // private final List/* |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.