--- a/apisupport.ant/nbproject/project.xml +++ a/apisupport.ant/nbproject/project.xml @@ -109,7 +109,7 @@ 1 - 1.48 + 1.49 --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java +++ a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java @@ -72,6 +72,7 @@ import org.netbeans.modules.apisupport.project.NbModuleProject; import org.netbeans.modules.apisupport.project.NbModuleType; import org.netbeans.modules.apisupport.project.api.Util; +import org.netbeans.modules.apisupport.project.spi.ExecProject; import org.netbeans.modules.apisupport.project.suite.SuiteProject; import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl; import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties; @@ -97,10 +98,11 @@ import org.openide.util.Mutex; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; +import org.openide.util.Task; import org.openide.util.Utilities; import org.openide.util.actions.SystemAction; -public final class ModuleActions implements ActionProvider { +public final class ModuleActions implements ActionProvider, ExecProject { static final String TEST_USERDIR_LOCK_PROP_NAME = "run.args.ide"; // NOI18N static final String TEST_USERDIR_LOCK_PROP_VALUE = "--test-userdir-lock-with-invalid-arg"; // NOI18N @@ -109,6 +111,18 @@ COMMAND_DEBUG_SINGLE )); + @Override + public Task execute(String... args) throws IOException { + StringBuilder sb = new StringBuilder(); + for (String r : args) { + sb.append(r).append(' '); + } + Properties p = new Properties(); + p.setProperty("run.args", sb.substring(0, sb.length() - 1)); + + return ActionUtils.runTarget(findBuildXml(project), new String[]{"run"}, p); + } + static Action[] getProjectActions(NbModuleProject project) { List actions = new ArrayList(); actions.add(CommonProjectActions.newFileAction()); --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/SuiteActions.java +++ a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/SuiteActions.java @@ -44,6 +44,7 @@ package org.netbeans.modules.apisupport.project.ui; +import org.openide.util.Task; import java.awt.event.ActionEvent; import java.io.IOException; import java.util.ArrayList; @@ -63,6 +64,7 @@ import org.netbeans.modules.apisupport.project.suite.SuiteBrandingModel; import org.netbeans.modules.apisupport.project.suite.SuiteProject; import org.netbeans.modules.apisupport.project.spi.BrandingModel; +import org.netbeans.modules.apisupport.project.spi.ExecProject; import org.netbeans.modules.apisupport.project.ui.customizer.SuiteCustomizer; import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties; import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils; @@ -94,7 +96,18 @@ * Defines actions available on a suite. * @author Jesse Glick */ -public final class SuiteActions implements ActionProvider { +public final class SuiteActions implements ActionProvider, ExecProject { + @Override + public Task execute(String... args) throws IOException { + StringBuilder sb = new StringBuilder(); + for (String r : args) { + sb.append(r).append(' '); + } + Properties p = new Properties(); + p.setProperty("run.args", sb.substring(0, sb.length() - 1)); + + return ActionUtils.runTarget(findBuildXml(project), new String[]{"run"}, p); + } static Action[] getProjectActions(SuiteProject project) { NbPlatform platform = project.getPlatform(true); //true -> #96095 --- a/apisupport.project/apichanges.xml +++ a/apisupport.project/apichanges.xml @@ -110,6 +110,20 @@ + Execute the project + + + + + + Layout designer seeks for ExecProject interface + in project's lookup when it needs to execute the application + with additional parameters. + + + + + Added prepareContext method --- a/apisupport.project/manifest.mf +++ a/apisupport.project/manifest.mf @@ -4,5 +4,5 @@ OpenIDE-Module-Requires: javax.script.ScriptEngine.freemarker OpenIDE-Module-Layer: org/netbeans/modules/apisupport/project/ui/resources/layer.xml AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 1.48 +OpenIDE-Module-Specification-Version: 1.49 --- a/apisupport.project/nbproject/project.xml +++ a/apisupport.project/nbproject/project.xml @@ -68,6 +68,15 @@ + org.netbeans.api.progress + + + + 1 + 1.25 + + + org.netbeans.api.xml @@ -223,6 +232,14 @@ + org.netbeans.swing.outline + + + + 1.15 + + + org.openide.actions --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/ExecProject.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/ExecProject.java @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.apisupport.project.spi; + +import java.io.IOException; +import org.openide.util.Task; + +/** Abstraction over executing a project. + * + * @author Jaroslav Tulach + * @since 1.49 + */ +public interface ExecProject { + /** Asks the project to execute itself given provided arguments. + * + * @param args arguments for the execution + * @return task that will finish as soon as execution is over + * @throws IOException if the launch fails + */ + public Task execute(String... args) throws IOException; +} --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/newTC.html +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/newTC.html @@ -41,6 +41,6 @@ --> - Creates a new singleton window component integrated into the Window System along with an action in main menu which opens this window. + Helps redefine the layout of window modes. --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.form +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.form @@ -1,4 +1,4 @@ - +
@@ -167,5 +167,18 @@ + + + + + + + + + + + + + --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.java @@ -45,18 +45,22 @@ package org.netbeans.modules.apisupport.project.ui.wizard.winsys; import java.awt.Cursor; +import java.awt.EventQueue; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicReference; import javax.swing.DefaultComboBoxModel; -import org.netbeans.modules.apisupport.project.layers.LayerUtils; +import org.netbeans.modules.apisupport.project.api.Util; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileSystem; import org.openide.util.AsyncGUIJob; +import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; +import org.openide.util.Task; +import org.openide.util.TaskListener; import org.openide.util.Utilities; /** @@ -93,7 +97,7 @@ markInvalid(); } } - + // public void addNotify() { // super.addNotify(); // attachDocumentListeners(); @@ -130,23 +134,12 @@ @Override public void construct() { try { - FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(data.getProject()); - FileObject foRoot = fs.getRoot().getFileObject("Windows2/Modes"); //NOI18N - if (foRoot != null) { - FileObject[] fos = foRoot.getChildren(); - Collection col = new ArrayList(); - for (FileObject fo : fos) { - if (fo.isData() && "wsmode".equals(fo.getExt())) { //NOI18N - col.add(fo.getName()); - } - } - modes = col.toArray(new String[col.size()]); - } else { + modes = DesignSupport.existingModes(data); + if (modes == null) { modes = DEFAULT_MODES; } } catch (IOException exc) { modes = DEFAULT_MODES; - } } @@ -162,6 +155,7 @@ }); } + @Override protected void storeToDataModel() { data.setOpened(cbOpenedOnStart.isSelected()); data.setKeepPrefSize(cbKeepPrefSize.isSelected()); @@ -173,6 +167,7 @@ data.setMode((String)comMode.getSelectedItem()); } + @Override protected void readFromDataModel() { cbOpenedOnStart.setSelected(data.isOpened()); cbKeepPrefSize.setSelected(data.isKeepPrefSize()); @@ -194,10 +189,12 @@ } } + @Override protected String getPanelName() { return getMessage("LBL_BasicSettings_Title"); } + @Override protected HelpCtx getHelp() { return new HelpCtx(BasicSettingsPanel.class); } @@ -224,6 +221,7 @@ cbUndockingNotAllowed = new javax.swing.JCheckBox(); cbDraggingNotAllowed = new javax.swing.JCheckBox(); cbMaximizationNotAllowed = new javax.swing.JCheckBox(); + redefine = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); @@ -320,6 +318,17 @@ gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); add(cbMaximizationNotAllowed, gridBagConstraints); + + org.openide.awt.Mnemonics.setLocalizedText(redefine, "&Redefine..."); + redefine.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + redefineActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_END; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); + add(redefine, gridBagConstraints); }// //GEN-END:initComponents private void windowPosChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_windowPosChanged @@ -330,6 +339,62 @@ if( !cbSlidingNotAllowed.isEnabled() ) cbSlidingNotAllowed.setSelected( false ); }//GEN-LAST:event_windowPosChanged + +private void redefineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redefineActionPerformed + try { + final AtomicReference userDir = new AtomicReference(); + Task task = DesignSupport.invokeDesignMode(data.getProject(), userDir); + redefine.setEnabled(false); + if (task == null) { + return; + } + redefine.setText(org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "MSG_LaunchingLayout", new Object[]{})); + + class PostProcess implements TaskListener, Runnable { + Set modeNames; + + @Override + public void taskFinished(Task task) { + FileObject modes = userDir.get().getFileObject("config/Windows2Local/Modes"); + if (modes != null) { + modeNames = new TreeSet(); + for (FileObject m : modes.getChildren()) { + if (m.isData() && "wsmode".equals(m.getExt())) { //NOI18N + modeNames.add(m.getName()); + try { + data.defineMode(m.getName(), DesignSupport.readMode(m)); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + EventQueue.invokeLater(this); + } + } + + @Override + public void run() { + redefine.setEnabled(true); + redefine.setText(org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "MSG_RedefineLayout", new Object[] {})); + int s = comMode.getModel().getSize(); + for (int i = 0; i < s; i++) { + modeNames.remove((String)comMode.getModel().getElementAt(i)); + } + boolean first = true; + for (String mn : modeNames) { + ((DefaultComboBoxModel)comMode.getModel()).addElement(mn); + if (first) { + comMode.getModel().setSelectedItem(mn); + } + first = false; + } + } + } + task.addTaskListener(new PostProcess()); + } catch (IOException e) { + Util.err.notify(e); + } +}//GEN-LAST:event_redefineActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox cbClosingNotAllowed; @@ -341,6 +406,7 @@ private javax.swing.JCheckBox cbUndockingNotAllowed; private javax.swing.JComboBox comMode; private javax.swing.JLabel lblMode; + private javax.swing.JButton redefine; // End of variables declaration//GEN-END:variables private void initAccessibility() { --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties @@ -82,3 +82,16 @@ CTL_UndockingNotAllowed=&Undocking not allowed CTL_DraggingNotAllowed=&Dragging not allowed CTL_MaximizationNotAllowed=&Maximization not allowed +MSG_RedefineLayout=Redefine... +MSG_LaunchingLayout=Launching... +MSG_ReallyLaunch=Following action needs to start your application in a special mode.\n\ +This requires your application is compilable, executable and does\n\ +not do anything strange.\n\ +\n\ +\As soon as the application is launched, you can play with the layout,\n\ +create new modes, rename existing. Close the application to save changes.\n\ +\n\ +Do you want to proceed? +MSG_AlreadyLaunched=Your application may have already been started in design mode.\nContinue with another launch anyway? +MSG_ModesGenerated=Following modes has been generated:\\n{0} +IGNORE\ PREVIOUS\ RUN=Ignore results of previous run --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/DesignSupport.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/DesignSupport.java @@ -0,0 +1,232 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.apisupport.project.ui.wizard.winsys; + +import java.awt.EventQueue; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.MissingResourceException; +import java.util.concurrent.atomic.AtomicReference; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JTextArea; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.netbeans.api.project.Project; +import org.netbeans.modules.apisupport.project.layers.LayerUtils; +import org.netbeans.modules.apisupport.project.spi.ExecProject; +import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; +import org.openide.util.Task; +import org.openide.util.TaskListener; + +public final class DesignSupport implements TaskListener, Runnable { + private final Project project; + private final JButton toEnable; + private final AtomicReference userDir; + + + private DesignSupport(Project p, JButton toEnable, AtomicReference ud) { + this.project = p; + this.toEnable = toEnable; + this.userDir = ud; + } + + static JComponent warningPanel() throws MissingResourceException { + JTextArea a = new JTextArea(); + a.setEditable(false); + a.setText(org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "MSG_ReallyLaunch", new Object[]{})); + a.setOpaque(false); + return a; + } + + public static Task invokeDesignMode( + Project prj, AtomicReference userDir + ) throws IOException { + return invokeDesignMode(prj, userDir, true, true); + } + + + static Task invokeDesignMode( + Project prj, AtomicReference userDir, boolean warn, boolean warnPrevResult + ) throws IOException { + ExecProject es = prj.getLookup().lookup(ExecProject.class); + if (es == null) { + throw new IOException("Project " + prj.getProjectDirectory() + " does not support execution!"); // NOI18N + } + if (warn) { + NotifyDescriptor nd = new NotifyDescriptor.Confirmation(warningPanel()); + nd.setOptions(new Object[]{NotifyDescriptor.YES_OPTION, NotifyDescriptor.CANCEL_OPTION}); + if (DialogDisplayer.getDefault().notify(nd) != NotifyDescriptor.YES_OPTION) { + return null; + } + } + FileObject fo = prj.getProjectDirectory().getFileObject("build/designdir"); // NOI18N + if (fo != null) { + if (warnPrevResult) { + NotifyDescriptor nd = new NotifyDescriptor.Confirmation(org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "MSG_AlreadyLaunched", new Object[]{})); + nd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); + if (DialogDisplayer.getDefault().notify(nd) != NotifyDescriptor.OK_OPTION) { + return null; + } + } + fo.delete(); + } + fo = FileUtil.createFolder(prj.getProjectDirectory(), "build/designdir"); // NOI18N + File path = FileUtil.toFile(fo); + userDir.set(fo); + return es.execute( + "--nosplash", // NOI18N + "-J-Dorg.netbeans.core.WindowSystem.designMode=true", // NOI18N + "--userdir " + path // NOI18N + ); + } + + static String[] existingModes(NewTCIterator.DataModel data) throws IOException { + FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(data.getProject()); + FileObject foRoot = fs.getRoot().getFileObject("Windows2/Modes"); //NOI18N + if (foRoot != null) { + FileObject[] fos = foRoot.getChildren(); + Collection col = new ArrayList(); + for (FileObject fo : fos) { + if (fo.isData() && "wsmode".equals(fo.getExt())) { //NOI18N + col.add(fo.getName()); + data.existingMode(fo.getName()); + } + } + return col.toArray(new String[col.size()]); + } else { + return null; + } + } + + public static String readMode(FileObject fo) throws IOException { + final InputStream is = fo.getInputStream(); + try { + StringWriter w = new StringWriter(); + Source t = new StreamSource(DesignSupport.class.getResourceAsStream("polishing.xsl")); // NOI18N + Transformer tr = TransformerFactory.newInstance().newTransformer(t); + Source s = new StreamSource(is); + Result r = new StreamResult(w); + tr.transform(s, r); + return w.toString(); + } catch (TransformerException ex) { + throw new IOException(ex); + } finally { + is.close(); + } + } + public static void redefineLayout(Project p, JButton toEnable) { + try { + AtomicReference userDir = new AtomicReference(); + Task task = invokeDesignMode(p, userDir); + if (task == null) { + toEnable.setEnabled(true); + } + task.addTaskListener(new DesignSupport(p, toEnable, userDir)); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public void taskFinished(Task task) { + FileObject modeDir = userDir.get().getFileObject("config/Windows2Local/Modes"); + OutputStream os; + if (modeDir != null) { + StringBuilder sb = new StringBuilder(); + try { + + FileSystem layer = findLayer(project); + if (layer == null) { + throw new IOException("Cannot find layer in " + project); // NOI18N + } + for (FileObject m : modeDir.getChildren()) { + if (m.isData() && "wsmode".equals(m.getExt())) { + final String name = "Windows2/Modes/" + m.getNameExt(); // NOI18N + FileObject mode = FileUtil.createData(layer.getRoot(), name); // NOI18N + os = mode.getOutputStream(); + os.write(DesignSupport.readMode(m).getBytes("UTF-8")); // NOI18N + os.close(); + sb.append(name).append("\n"); + } + } + NotifyDescriptor nd = new NotifyDescriptor.Message( + NbBundle.getMessage(DesignSupport.class, "MSG_ModesGenerated", new Object[] {sb}), + NotifyDescriptor.INFORMATION_MESSAGE + ); + DialogDisplayer.getDefault().notifyLater(nd); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + EventQueue.invokeLater(this); + } + + @Override + public void run() { + toEnable.setEnabled(true); + } + + static FileSystem findLayer(Project p) throws IOException { + if (p.getLookup().lookup(NbModuleProvider.class) != null) { + return LayerUtils.getEffectiveSystemFilesystem(p); + } + return null; + } +} --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java @@ -46,8 +46,10 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -63,39 +65,46 @@ import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.netbeans.api.templates.TemplateRegistration; +import org.netbeans.modules.apisupport.project.api.LayerHandle; +import org.netbeans.modules.apisupport.project.ui.wizard.winsys.NewTCIterator.DataModel; import org.openide.modules.SpecificationVersion; import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; /** - * Wizard for creating new TopComponent. + * Wizard for redefining layout of windows. * - * @author Milos Kleint + * @author Jaroslav Tulach */ @TemplateRegistration( folder="NetBeansModuleDevelopment", - position=200, - displayName="#template_winsys", - iconBase="org/netbeans/modules/apisupport/project/ui/resources/newTC.png", - description="../../resources/newTC.html", + position=3249, + displayName="#template_winsys_layout", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newLayout.png", + description="../../resources/newLayout.html", category="nbm-specific" ) -@Messages("template_winsys=Window") -public final class NewTCIterator extends BasicWizardIterator { +@Messages("template_winsys_layout=Layout of Windows") +public final class LayoutIterator extends BasicWizardIterator { - private NewTCIterator.DataModel data; + private DataModel data; + @Override public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); - return getCreatedFiles(cmf, data.getProject()); + return Collections.singleton( + LayerHandle.forProject(data.getProject()).getLayerFile() + ); } + @Override protected BasicWizardIterator.Panel[] createPanels(WizardDescriptor wiz) { - data = new NewTCIterator.DataModel(wiz); + data = new DataModel(wiz); return new BasicWizardIterator.Panel[] { - new BasicSettingsPanel(wiz, data), - new NameAndLocationPanel(wiz, data) + new LayoutWarningPanel(wiz, data), + new LayoutLaunchingPanel(wiz, data), + new LayoutSummaryPanel(wiz, data) }; } @@ -104,123 +113,7 @@ data = null; } - static final class DataModel extends BasicWizardIterator.BasicDataModel { - - private String name; - private String icon; - private String mode; - private boolean opened = false; - private boolean keepPrefSize = false; - private boolean slidingNotAllowed = false; - private boolean closingNotAllowed = false; - private boolean draggingNotAllowed = false; - private boolean undockingNotAllowed = false; - private boolean maximizationNotAllowed = false; - - private CreatedModifiedFiles files; - - DataModel(WizardDescriptor wiz) { - super(wiz); - } - - public CreatedModifiedFiles getCreatedModifiedFiles() { - return getFiles(); - } - - public void setCreatedModifiedFiles(CreatedModifiedFiles files) { - this.setFiles(files); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public CreatedModifiedFiles getFiles() { - return files; - } - - public void setFiles(CreatedModifiedFiles files) { - this.files = files; - } - - public String getIcon() { - return icon; - } - - public void setIcon(String icon) { - this.icon = icon; - } - - public String getMode() { - return mode; - } - - public void setMode(String mode) { - this.mode = mode; - } - - public boolean isOpened() { - return opened; - } - - public void setOpened(boolean opened) { - this.opened = opened; - } - - public boolean isKeepPrefSize() { - return keepPrefSize; - } - - public void setKeepPrefSize(boolean keepPrefSize) { - this.keepPrefSize = keepPrefSize; - } - - public boolean isClosingNotAllowed() { - return closingNotAllowed; - } - - public void setClosingNotAllowed(boolean closingNotAllowed) { - this.closingNotAllowed = closingNotAllowed; - } - - public boolean isDraggingNotAllowed() { - return draggingNotAllowed; - } - - public void setDraggingNotAllowed(boolean draggingNotAllowed) { - this.draggingNotAllowed = draggingNotAllowed; - } - - public boolean isMaximizationNotAllowed() { - return maximizationNotAllowed; - } - - public void setMaximizationNotAllowed(boolean maximizationNotAllowed) { - this.maximizationNotAllowed = maximizationNotAllowed; - } - - public boolean isSlidingNotAllowed() { - return slidingNotAllowed; - } - - public void setSlidingNotAllowed(boolean slidingNotAllowed) { - this.slidingNotAllowed = slidingNotAllowed; - } - - public boolean isUndockingNotAllowed() { - return undockingNotAllowed; - } - - public void setUndockingNotAllowed(boolean undockingNotAllowed) { - this.undockingNotAllowed = undockingNotAllowed; - } - } - - public static void generateFileChanges(DataModel model) { + static void generateFileChanges(final DataModel model) { CreatedModifiedFiles fileChanges = new CreatedModifiedFiles(model.getProject()); Project project = model.getProject(); NbModuleProvider moduleInfo = model.getModuleInfo(); @@ -235,7 +128,7 @@ actionLessTC = current == null || current.compareTo(new SpecificationVersion("6.24")) >= 0; // NOI18N xmlLessTC = current == null || current.compareTo(new SpecificationVersion("6.37")) >= 0; // NOI18N } catch (IOException ex) { - Logger.getLogger(NewTCIterator.class.getName()).log(Level.INFO, null, ex); + Logger.getLogger(LayoutIterator.class.getName()).log(Level.INFO, null, ex); actionLessTC = false; xmlLessTC = false; } @@ -244,7 +137,7 @@ SpecificationVersion current = model.getModuleInfo().getDependencyVersion("org.netbeans.modules.settings"); propertiesPersistence = current == null || current.compareTo(new SpecificationVersion("1.18")) >= 0; // NOI18N } catch (IOException ex) { - Logger.getLogger(NewTCIterator.class.getName()).log(Level.INFO, null, ex); + Logger.getLogger(LayoutIterator.class.getName()).log(Level.INFO, null, ex); propertiesPersistence = false; } @@ -382,6 +275,30 @@ fileChanges.add(fileChanges.bundleKey(bundlePath, "HINT_" + name + "TopComponent", // NOI18N "This is a " + name + " window")); //NOI18N + final Map newModes = model.getNewModes(); + if (newModes != null) { + Set files = new HashSet(); + for (String wsmode : newModes.keySet()) { + files.add(wsmode + ".wsmode"); + } + + fileChanges.add(fileChanges.layerModifications(new CreatedModifiedFiles.LayerOperation() { + @Override + public void run(FileSystem layer) throws IOException { + FileObject fo = FileUtil.createFolder(layer.getRoot(), "Windows2/Modes"); + for (Map.Entry entry : newModes.entrySet()) { + FileObject wsmode = fo.createData(entry.getKey() + ".wsmode"); + OutputStream os = wsmode.getOutputStream(); + try { + os.write(entry.getValue().getBytes("UTF-8")); + } finally { + os.close(); + } + } + } + }, files)); + } + model.setCreatedModifiedFiles(fileChanges); } --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.form +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.form @@ -1,9 +1,10 @@ - +
+ @@ -14,197 +15,23 @@ - - - - - - - - - + - + - - + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.java @@ -44,120 +44,133 @@ package org.netbeans.modules.apisupport.project.ui.wizard.winsys; -import java.io.File; -import javax.swing.JFileChooser; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.modules.apisupport.project.api.UIUtil; +import java.awt.EventQueue; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicReference; +import javax.swing.JComponent; +import javax.swing.JLabel; +import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.view.CheckableNode; +import org.openide.explorer.view.OutlineView; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; -import org.openide.util.Utilities; +import org.openide.util.Task; +import org.openide.util.TaskListener; /** - * the second panel in topcomponent wizard. + * Shows progress of launching first, then let's user pickup changed modes. * - * @author Milos Kleint + * @author Jaroslav Tulach */ -final class NameAndLocationPanel extends BasicWizardIterator.Panel { +final class LayoutLaunchingPanel extends BasicWizardIterator.Panel +implements TaskListener, Runnable, ExplorerManager.Provider { + private AtomicReference userDir = new AtomicReference(); + private NewTCIterator.DataModel data; + private Task task; + private ProgressHandle handle; + private ExplorerManager em; + private final OutlineView outlineView; - private NewTCIterator.DataModel data; - - /** Creates new NameAndLocationPanel */ - public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) { + @NbBundle.Messages({ + "CTL_FoundModes=Found modes", + "LBL_LayoutingWizardTitle=Define Your Modes" + }) + public LayoutLaunchingPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) { super(setting); this.data = data; + Node root = new AbstractNode(new Children.Array()); + this.em = new ExplorerManager(); + this.em.setRootContext(root); initComponents(); initAccessibility(); - putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle")); - - DocumentListener dListener = new UIUtil.DocumentAdapter() { - public void insertUpdate(DocumentEvent e) { - if (checkValidity()) { - updateData(); - } + putClientProperty("NewFileWizard_Title", Bundle.LBL_LayoutingWizardTitle()); // NOI18N + outlineView = new OutlineView(Bundle.CTL_FoundModes()); + outlineView.getOutline().setRootVisible(false); + tree.add(outlineView); + outlineView.setDefaultActionAllowed(false); + outlineView.setVisible(false); + tree.setMinimumSize(outlineView.getPreferredSize()); + } + + @Override + protected void storeToDataModel() { + for (Node n : getExplorerManager().getRootContext().getChildren().getNodes()) { + ModeNode mn = (ModeNode)n; + if (mn.isSelected()) { + data.defineMode(mn.getName(), mn.text); } - }; - txtPrefix.getDocument().addDocumentListener(dListener); - txtIcon.getDocument().addDocumentListener(dListener); - - if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) { - JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent(); - txt.getDocument().addDocumentListener(dListener); } } - protected void storeToDataModel() { - updateData(); + @NbBundle.Messages({ + "MSG_LaunchingApplication=Launching your application" + }) + @Override + protected void readFromDataModel() { + checkValidity(); + if (task == null) { + try { + task = DesignSupport.invokeDesignMode(data.getProject(), userDir, false, !data.isIgnorePreviousRun()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + handle = ProgressHandleFactory.createHandle(Bundle.MSG_LaunchingApplication()); + JComponent pc = ProgressHandleFactory.createProgressComponent(handle); + JLabel ml = ProgressHandleFactory.createMainLabelComponent(handle); + + progress.add(ml); + progress.add(pc); + + handle.start(); + markInvalid(); + try { + DesignSupport.existingModes(data); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + task.addTaskListener(this); } - private void updateData() { - data.setPackageName(comPackageName.getEditor().getItem().toString()); - String icon = txtIcon.getText().trim(); - data.setIcon(icon.length() == 0 ? (String)null : icon); - data.setName(txtPrefix.getText().trim()); - NewTCIterator.generateFileChanges(data); - createdFilesValue.setText(UIUtil.generateTextAreaContent( - data.getCreatedModifiedFiles().getCreatedPaths())); - modifiedFilesValue.setText(UIUtil.generateTextAreaContent( - data.getCreatedModifiedFiles().getModifiedPaths())); - //#68294 check if the paths for newly created files are valid or not.. - String[] invalid = data.getCreatedModifiedFiles().getInvalidPaths(); - if (invalid.length > 0) { - setError(NbBundle.getMessage(NameAndLocationPanel.class, "ERR_ToBeCreateFileExists", invalid[0])); - } - - } - - protected void readFromDataModel() { - txtPrefix.setText(data.getName()); - txtIcon.setText(data.getIcon()); - if (data.getPackageName() != null) { - comPackageName.setSelectedItem(data.getPackageName()); - } - checkValidity(); - } - + @Override + @NbBundle.Messages({ + "LBL_DesignLayout=Design Window Layout" + }) protected String getPanelName() { - return getMessage("LBL_NameLocation_Title"); + return Bundle.LBL_DesignLayout(); } private boolean checkValidity() { - if (txtPrefix.getText().trim().length() == 0) { - setInfo(getMessage("ERR_Name_Prefix_Empty"), false); + int cnt = 0; + for (Node node : getExplorerManager().getRootContext().getChildren().getNodes()) { + if (node instanceof ModeNode) { + ModeNode mn = (ModeNode)node; + if (mn.isSelected()) { + cnt++; + } + } + } + if (cnt == 0 || !outlineView.isVisible()) { + markInvalid(); return false; } - if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) { - setError(getMessage("ERR_Name_Prefix_Invalid")); - return false; - } - String path = txtIcon.getText().trim(); - if (path.length() != 0) { - File fil = new File(path); - if (!fil.exists()) { - setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid")); - return false; - } - } - String packageName = comPackageName.getEditor().getItem().toString().trim(); - if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) { - setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid")); - return false; - } - markValid(); return true; } + @Override protected HelpCtx getHelp() { - return new HelpCtx(NameAndLocationPanel.class); - } - - private static String getMessage(String key) { - return NbBundle.getMessage(NameAndLocationPanel.class, key); + return new HelpCtx(LayoutLaunchingPanel.class); } /** This method is called from within the constructor to @@ -165,206 +178,130 @@ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - // //GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; - lblPrefix = new javax.swing.JLabel(); - txtPrefix = new javax.swing.JTextField(); - lblIcon = new javax.swing.JLabel(); - txtIcon = new javax.swing.JTextField(); - btnIcon = new javax.swing.JButton(); - lblProjectName = new javax.swing.JLabel(); - txtProjectName = new JTextField(ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); - lblPackageName = new javax.swing.JLabel(); - comPackageName = UIUtil.createPackageComboBox(data.getSourceRootGroup()); - createdFiles = new javax.swing.JLabel(); - modifiedFiles = new javax.swing.JLabel(); - filler = new javax.swing.JLabel(); - createdFilesValue = new javax.swing.JTextArea(); - modifiedFilesValue = new javax.swing.JTextArea(); + progress = new javax.swing.JPanel(); + tree = new javax.swing.JPanel(); setLayout(new java.awt.GridBagLayout()); - - lblPrefix.setLabelFor(txtPrefix); - org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Prefix")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; + gridBagConstraints.gridwidth = 4; + gridBagConstraints.gridheight = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(1, 0, 6, 12); - add(lblPrefix, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(1, 0, 6, 0); - add(txtPrefix, gridBagConstraints); - - lblIcon.setLabelFor(txtIcon); - org.openide.awt.Mnemonics.setLocalizedText(lblIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(lblIcon, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 1; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - add(txtIcon, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(btnIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon_Browse")); - btnIcon.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnIconActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 2; - gridBagConstraints.gridy = 1; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); - add(btnIcon, gridBagConstraints); - - lblProjectName.setLabelFor(txtProjectName); - org.openide.awt.Mnemonics.setLocalizedText(lblProjectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 12); - add(lblProjectName, gridBagConstraints); - - txtProjectName.setEditable(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 2; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 0); - add(txtProjectName, gridBagConstraints); - - lblPackageName.setLabelFor(comPackageName); - org.openide.awt.Mnemonics.setLocalizedText(lblPackageName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_PackageName")); + add(progress, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(lblPackageName, gridBagConstraints); + gridBagConstraints.gridwidth = 4; + gridBagConstraints.gridheight = 11; + add(tree, gridBagConstraints); + }// //GEN-END:initComponents + + @NbBundle.Messages({ + "ACS_DesignPanel=Design Window Layout" + }) + private void initAccessibility() { + this.getAccessibleContext().setAccessibleDescription(Bundle.ACS_DesignPanel()); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel progress; + private javax.swing.JPanel tree; + // End of variables declaration//GEN-END:variables - comPackageName.setEditable(true); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 3; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - add(comPackageName, gridBagConstraints); + @Override + @NbBundle.Messages({ + "LBL_NoModesFound=No layout definition found", + "MSG_NoModesFound=Is everything OK? Did your application compile and run?" + }) + public void taskFinished(Task task) { + handle.finish(); + FileObject modeDir = userDir.get().getFileObject("config/Windows2Local/Modes"); + boolean one = false; + final Children ch = getExplorerManager().getRootContext().getChildren(); + if (modeDir != null) { + try { + FileSystem layer = DesignSupport.findLayer(data.getProject()); + if (layer == null) { + throw new IOException("Cannot find layer in " + data.getProject()); // NOI18N + } + for (FileObject m : modeDir.getChildren()) { + if (m.isData() && "wsmode".equals(m.getExt())) { + ModeNode mn = new ModeNode(m, data); + ch.add(new Node[] { mn }); + one = true; + } + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + if (!one) { + AbstractNode empty = new AbstractNode(Children.LEAF); + empty.setName("empty"); // NOI18N + empty.setDisplayName(Bundle.LBL_NoModesFound()); + empty.setShortDescription(Bundle.MSG_NoModesFound()); + ch.add(new Node[] { empty }); + markInvalid(); + } else { + markValid(); + } + + EventQueue.invokeLater(this); + } + @Override + public void run() { + progress.setVisible(false); + outlineView.setVisible(true); + progress.invalidate(); + outlineView.invalidate(); + validateTree(); + } - createdFiles.setLabelFor(createdFilesValue); - org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(36, 0, 6, 12); - add(createdFiles, gridBagConstraints); + @Override + public ExplorerManager getExplorerManager() { + return em; + } - modifiedFiles.setLabelFor(modifiedFilesValue); - org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 5; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(modifiedFiles, gridBagConstraints); + private class ModeNode extends AbstractNode + implements CheckableNode { + private final FileObject mode; + private final String text; + private boolean selected; - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 6; - gridBagConstraints.gridwidth = 3; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(filler, gridBagConstraints); + public ModeNode(FileObject mode, NewTCIterator.DataModel data) throws IOException { + super(Children.LEAF); + this.mode = mode; + this.text = DesignSupport.readMode(mode); + this.selected = !data.isExistingMode(mode.getName()); + + setName(mode.getName()); + } - createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); - createdFilesValue.setColumns(20); - createdFilesValue.setEditable(false); - createdFilesValue.setRows(5); - createdFilesValue.setBorder(null); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 4; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(36, 0, 6, 0); - add(createdFilesValue, gridBagConstraints); + @Override + public boolean isCheckable() { + return true; + } - modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); - modifiedFilesValue.setColumns(20); - modifiedFilesValue.setEditable(false); - modifiedFilesValue.setRows(5); - modifiedFilesValue.setToolTipText("modifiedFilesValue"); - modifiedFilesValue.setBorder(null); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 5; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - add(modifiedFilesValue, gridBagConstraints); + @Override + public boolean isCheckEnabled() { + return true; + } - } - // //GEN-END:initComponents - - private void initAccessibility() { - this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel")); - comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName")); - txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon")); - txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix")); - btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton")); - txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName")); - createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue")); - modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue")); + @Override + public Boolean isSelected() { + return selected; + } + + @Override + public void setSelected(Boolean selected) { + this.selected = Boolean.TRUE.equals(selected); + checkValidity(); + } } - private void btnIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIconActionPerformed - JFileChooser chooser = UIUtil.getIconFileChooser(txtIcon.getText()); - int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N - if (ret == JFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - txtIcon.setText(file.getAbsolutePath()); - } - }//GEN-LAST:event_btnIconActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btnIcon; - private javax.swing.JComboBox comPackageName; - private javax.swing.JLabel createdFiles; - private javax.swing.JTextArea createdFilesValue; - private javax.swing.JLabel filler; - private javax.swing.JLabel lblIcon; - private javax.swing.JLabel lblPackageName; - private javax.swing.JLabel lblPrefix; - private javax.swing.JLabel lblProjectName; - private javax.swing.JLabel modifiedFiles; - private javax.swing.JTextArea modifiedFilesValue; - private javax.swing.JTextField txtIcon; - private javax.swing.JTextField txtPrefix; - private javax.swing.JTextField txtProjectName; - // End of variables declaration//GEN-END:variables - } --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.form +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.form @@ -1,9 +1,10 @@ - +
+ @@ -14,124 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NameAndLocationPanel.java @@ -44,61 +44,34 @@ package org.netbeans.modules.apisupport.project.ui.wizard.winsys; -import java.io.File; -import javax.swing.JFileChooser; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.apisupport.project.api.UIUtil; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; -import org.openide.util.Utilities; /** - * the second panel in topcomponent wizard. - * - * @author Milos Kleint + * 3rd panel of the layout wizard. */ -final class NameAndLocationPanel extends BasicWizardIterator.Panel { +final class LayoutSummaryPanel extends BasicWizardIterator.Panel { private NewTCIterator.DataModel data; - /** Creates new NameAndLocationPanel */ - public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) { + public LayoutSummaryPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) { super(setting); this.data = data; initComponents(); initAccessibility(); - putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle")); - - DocumentListener dListener = new UIUtil.DocumentAdapter() { - public void insertUpdate(DocumentEvent e) { - if (checkValidity()) { - updateData(); - } - } - }; - txtPrefix.getDocument().addDocumentListener(dListener); - txtIcon.getDocument().addDocumentListener(dListener); - - if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) { - JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent(); - txt.getDocument().addDocumentListener(dListener); - } + putClientProperty("NewFileWizard_Title", Bundle.LBL_LayoutSummaryTitle()); } + @Override protected void storeToDataModel() { - updateData(); + } - private void updateData() { - data.setPackageName(comPackageName.getEditor().getItem().toString()); - String icon = txtIcon.getText().trim(); - data.setIcon(icon.length() == 0 ? (String)null : icon); - data.setName(txtPrefix.getText().trim()); + @Override + protected void readFromDataModel() { NewTCIterator.generateFileChanges(data); createdFilesValue.setText(UIUtil.generateTextAreaContent( data.getCreatedModifiedFiles().getCreatedPaths())); @@ -107,57 +80,21 @@ //#68294 check if the paths for newly created files are valid or not.. String[] invalid = data.getCreatedModifiedFiles().getInvalidPaths(); if (invalid.length > 0) { - setError(NbBundle.getMessage(NameAndLocationPanel.class, "ERR_ToBeCreateFileExists", invalid[0])); + setError(NbBundle.getMessage(LayoutSummaryPanel.class, "ERR_ToBeCreateFileExists", invalid[0])); } - } - protected void readFromDataModel() { - txtPrefix.setText(data.getName()); - txtIcon.setText(data.getIcon()); - if (data.getPackageName() != null) { - comPackageName.setSelectedItem(data.getPackageName()); - } - checkValidity(); + @Override + @NbBundle.Messages({ + "LBL_LayoutSummaryTitle=Changed Files" + }) + protected String getPanelName() { + return Bundle.LBL_LayoutSummaryTitle(); } - protected String getPanelName() { - return getMessage("LBL_NameLocation_Title"); - } - - private boolean checkValidity() { - if (txtPrefix.getText().trim().length() == 0) { - setInfo(getMessage("ERR_Name_Prefix_Empty"), false); - return false; - } - if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) { - setError(getMessage("ERR_Name_Prefix_Invalid")); - return false; - } - String path = txtIcon.getText().trim(); - if (path.length() != 0) { - File fil = new File(path); - if (!fil.exists()) { - setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid")); - return false; - } - } - String packageName = comPackageName.getEditor().getItem().toString().trim(); - if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) { - setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid")); - return false; - } - - markValid(); - return true; - } - + @Override protected HelpCtx getHelp() { - return new HelpCtx(NameAndLocationPanel.class); - } - - private static String getMessage(String key) { - return NbBundle.getMessage(NameAndLocationPanel.class, key); + return new HelpCtx(LayoutSummaryPanel.class); } /** This method is called from within the constructor to @@ -165,19 +102,10 @@ * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - // //GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; - lblPrefix = new javax.swing.JLabel(); - txtPrefix = new javax.swing.JTextField(); - lblIcon = new javax.swing.JLabel(); - txtIcon = new javax.swing.JTextField(); - btnIcon = new javax.swing.JButton(); - lblProjectName = new javax.swing.JLabel(); - txtProjectName = new JTextField(ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); - lblPackageName = new javax.swing.JLabel(); - comPackageName = UIUtil.createPackageComboBox(data.getSourceRootGroup()); createdFiles = new javax.swing.JLabel(); modifiedFiles = new javax.swing.JLabel(); filler = new javax.swing.JLabel(); @@ -186,92 +114,9 @@ setLayout(new java.awt.GridBagLayout()); - lblPrefix.setLabelFor(txtPrefix); - org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Prefix")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(1, 0, 6, 12); - add(lblPrefix, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(1, 0, 6, 0); - add(txtPrefix, gridBagConstraints); - - lblIcon.setLabelFor(txtIcon); - org.openide.awt.Mnemonics.setLocalizedText(lblIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(lblIcon, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 1; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - add(txtIcon, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(btnIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon_Browse")); - btnIcon.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnIconActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 2; - gridBagConstraints.gridy = 1; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); - add(btnIcon, gridBagConstraints); - - lblProjectName.setLabelFor(txtProjectName); - org.openide.awt.Mnemonics.setLocalizedText(lblProjectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 12); - add(lblProjectName, gridBagConstraints); - - txtProjectName.setEditable(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 2; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 0); - add(txtProjectName, gridBagConstraints); - - lblPackageName.setLabelFor(comPackageName); - org.openide.awt.Mnemonics.setLocalizedText(lblPackageName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_PackageName")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 3; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); - add(lblPackageName, gridBagConstraints); - - comPackageName.setEditable(true); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 3; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - add(comPackageName, gridBagConstraints); - createdFiles.setLabelFor(createdFilesValue); - org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles")); + java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle"); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(createdFiles, bundle.getString("LBL_CreatedFiles")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; @@ -281,7 +126,7 @@ add(createdFiles, gridBagConstraints); modifiedFiles.setLabelFor(modifiedFilesValue); - org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles")); + org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, bundle.getString("LBL_ModifiedFiles")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; @@ -289,7 +134,6 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); add(modifiedFiles, gridBagConstraints); - gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; @@ -326,45 +170,25 @@ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; add(modifiedFilesValue, gridBagConstraints); + }// //GEN-END:initComponents + @NbBundle.Messages({ + "ACS_LayoutSummaryPanel=Overview Your Changes", + "ACS_CTL_Layout_CreatedFilesValue=List of files that will be created", + "ACS_CTL_Layout_ModifiedFilesValue=List of files that will be modified" + }) + private void initAccessibility() { + this.getAccessibleContext().setAccessibleDescription(Bundle.ACS_LayoutSummaryPanel()); + createdFilesValue.getAccessibleContext().setAccessibleDescription(Bundle.ACS_CTL_Layout_CreatedFilesValue()); + modifiedFilesValue.getAccessibleContext().setAccessibleDescription(Bundle.ACS_CTL_Layout_ModifiedFilesValue()); } - // //GEN-END:initComponents - - private void initAccessibility() { - this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel")); - comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName")); - txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon")); - txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix")); - btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton")); - txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName")); - createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue")); - modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue")); - } - - private void btnIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIconActionPerformed - JFileChooser chooser = UIUtil.getIconFileChooser(txtIcon.getText()); - int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N - if (ret == JFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - txtIcon.setText(file.getAbsolutePath()); - } - }//GEN-LAST:event_btnIconActionPerformed - + // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btnIcon; - private javax.swing.JComboBox comPackageName; private javax.swing.JLabel createdFiles; private javax.swing.JTextArea createdFilesValue; private javax.swing.JLabel filler; - private javax.swing.JLabel lblIcon; - private javax.swing.JLabel lblPackageName; - private javax.swing.JLabel lblPrefix; - private javax.swing.JLabel lblProjectName; private javax.swing.JLabel modifiedFiles; private javax.swing.JTextArea modifiedFilesValue; - private javax.swing.JTextField txtIcon; - private javax.swing.JTextField txtPrefix; - private javax.swing.JTextField txtProjectName; // End of variables declaration//GEN-END:variables } --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.form +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.form @@ -1,4 +1,4 @@ - + @@ -7,165 +7,47 @@ + - + + + + + + + + + + + + + + + + + + + + + + - + + + + + - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/BasicSettingsPanel.java @@ -44,166 +44,52 @@ package org.netbeans.modules.apisupport.project.ui.wizard.winsys; -import java.awt.Cursor; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import javax.swing.DefaultComboBoxModel; -import org.netbeans.modules.apisupport.project.layers.LayerUtils; +import java.awt.BorderLayout; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; +import org.netbeans.modules.apisupport.project.ui.wizard.winsys.NewTCIterator.DataModel; import org.openide.WizardDescriptor; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileSystem; -import org.openide.util.AsyncGUIJob; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; -import org.openide.util.Utilities; /** - * the first panel in TopComponent wizard + * Ask whether the user is ready to launch the application. With all + * the consequences. * - * @author Milos Kleint + * @author Jaroslav Tulach */ -final class BasicSettingsPanel extends BasicWizardIterator.Panel { +final class LayoutWarningPanel extends BasicWizardIterator.Panel { + private final DataModel data; - private NewTCIterator.DataModel data; - private static final String[] DEFAULT_MODES = - new String[] { - "editor" //NOI18N - }; - private boolean loadedComboBox = false; - - /** - * Creates new form BasicSettingsPanel - */ - public BasicSettingsPanel(WizardDescriptor setting, NewTCIterator.DataModel data) { + @NbBundle.Messages({ + "LBL_LayoutWizardTitle=Launch Your Application?" + }) + public LayoutWarningPanel(WizardDescriptor setting, NewTCIterator.DataModel data) { super(setting); this.data = data; initComponents(); initAccessibility(); - setupCombo(); - putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle")); + putClientProperty("NewFileWizard_Title", Bundle.LBL_LayoutWizardTitle()); //NOI18N + panel.add(DesignSupport.warningPanel(), BorderLayout.CENTER); } - private void checkValidity() { - //TODO: probably nothing... - if (loadedComboBox) { - markValid(); - } else { - markInvalid(); - } + @Override + protected void storeToDataModel() { + data.setIgnorePreviousRun(ignore.isSelected()); } -// public void addNotify() { -// super.addNotify(); -// attachDocumentListeners(); -// checkValidity(); -// } -// -// public void removeNotify() { -// // prevent checking when the panel is not "active" -// removeDocumentListeners(); -// super.removeNotify(); -// } -// -// private void attachDocumentListeners() { -// if (!listenersAttached) { -// listenersAttached = true; -// } -// } -// -// private void removeDocumentListeners() { -// if (listenersAttached) { -// listenersAttached = false; -// } -// } - - private void setupCombo() { - //TODO get dynamically from layers?? - final Cursor currentCursor = getCursor(); - setCursor(Utilities.createProgressCursor(this)); + @Override + protected void readFromDataModel() { + ignore.setSelected(data.isIgnorePreviousRun()); + } - Utilities.attachInitJob(comMode, new AsyncGUIJob() { - - String[] modes = null; - - @Override - public void construct() { - try { - FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(data.getProject()); - FileObject foRoot = fs.getRoot().getFileObject("Windows2/Modes"); //NOI18N - if (foRoot != null) { - FileObject[] fos = foRoot.getChildren(); - Collection col = new ArrayList(); - for (FileObject fo : fos) { - if (fo.isData() && "wsmode".equals(fo.getExt())) { //NOI18N - col.add(fo.getName()); - } - } - modes = col.toArray(new String[col.size()]); - } else { - modes = DEFAULT_MODES; - } - } catch (IOException exc) { - modes = DEFAULT_MODES; - - } - } - - @Override - public void finished() { - comMode.setModel(new DefaultComboBoxModel(modes)); - setComModeSelectedItem(); - windowPosChanged(null); - setCursor(currentCursor); - loadedComboBox = true; - checkValidity(); - } - }); + @Override + protected String getPanelName() { + return Bundle.LBL_LayoutWizardTitle(); } - protected void storeToDataModel() { - data.setOpened(cbOpenedOnStart.isSelected()); - data.setKeepPrefSize(cbKeepPrefSize.isSelected()); - data.setClosingNotAllowed(cbClosingNotAllowed.isSelected()); - data.setDraggingNotAllowed(cbDraggingNotAllowed.isSelected()); - data.setMaximizationNotAllowed(cbMaximizationNotAllowed.isSelected()); - data.setSlidingNotAllowed(cbSlidingNotAllowed.isSelected()); - data.setUndockingNotAllowed(cbUndockingNotAllowed.isSelected()); - data.setMode((String)comMode.getSelectedItem()); - } - - protected void readFromDataModel() { - cbOpenedOnStart.setSelected(data.isOpened()); - cbKeepPrefSize.setSelected(data.isKeepPrefSize()); - cbClosingNotAllowed.setSelected(data.isClosingNotAllowed()); - cbDraggingNotAllowed.setSelected(data.isDraggingNotAllowed()); - cbMaximizationNotAllowed.setSelected(data.isMaximizationNotAllowed()); - cbSlidingNotAllowed.setSelected(data.isSlidingNotAllowed()); - cbUndockingNotAllowed.setSelected(data.isUndockingNotAllowed()); - setComModeSelectedItem(); - windowPosChanged(null); - checkValidity(); - } - - private void setComModeSelectedItem() { - if (data.getMode() != null) { - comMode.setSelectedItem(data.getMode()); - } else { - comMode.setSelectedItem("output");//NOI18N - } - } - - protected String getPanelName() { - return getMessage("LBL_BasicSettings_Title"); - } - + @Override protected HelpCtx getHelp() { - return new HelpCtx(BasicSettingsPanel.class); - } - - private static String getMessage(String key) { - return NbBundle.getMessage(BasicSettingsPanel.class, key); + return new HelpCtx(LayoutWarningPanel.class); } /** This method is called from within the constructor to @@ -213,141 +99,45 @@ */ // //GEN-BEGIN:initComponents private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - lblMode = new javax.swing.JLabel(); - comMode = new javax.swing.JComboBox(); - cbOpenedOnStart = new javax.swing.JCheckBox(); - cbKeepPrefSize = new javax.swing.JCheckBox(); - cbSlidingNotAllowed = new javax.swing.JCheckBox(); - cbClosingNotAllowed = new javax.swing.JCheckBox(); - cbUndockingNotAllowed = new javax.swing.JCheckBox(); - cbDraggingNotAllowed = new javax.swing.JCheckBox(); - cbMaximizationNotAllowed = new javax.swing.JCheckBox(); + panel = new javax.swing.JPanel(); + ignore = new javax.swing.JCheckBox(); - setLayout(new java.awt.GridBagLayout()); + panel.setLayout(new java.awt.BorderLayout()); - lblMode.setLabelFor(comMode); - org.openide.awt.Mnemonics.setLocalizedText(lblMode, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "LBL_Mode")); // NOI18N - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(lblMode, gridBagConstraints); + ignore.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(ignore, org.openide.util.NbBundle.getMessage(LayoutWarningPanel.class, "IGNORE PREVIOUS RUN", new Object[] {})); // NOI18N - comMode.addItemListener(new java.awt.event.ItemListener() { - public void itemStateChanged(java.awt.event.ItemEvent evt) { - windowPosChanged(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 0.1; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 6); - add(comMode, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbOpenedOnStart, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "LBL_OpenOnStart")); // NOI18N - cbOpenedOnStart.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - cbOpenedOnStart.setMargin(new java.awt.Insets(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbOpenedOnStart, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbKeepPrefSize, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "LBL_KeepPrefSize")); // NOI18N - cbKeepPrefSize.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - cbKeepPrefSize.setEnabled(false); - cbKeepPrefSize.setMargin(new java.awt.Insets(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbKeepPrefSize, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbSlidingNotAllowed, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "CTL_SlidingNotAllowed")); // NOI18N - cbSlidingNotAllowed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - cbSlidingNotAllowed.setEnabled(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 3; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbSlidingNotAllowed, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbClosingNotAllowed, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "CTL_ClosingNotAllowed")); // NOI18N - cbClosingNotAllowed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbClosingNotAllowed, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbUndockingNotAllowed, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "CTL_UndockingNotAllowed")); // NOI18N - cbUndockingNotAllowed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 5; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbUndockingNotAllowed, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbDraggingNotAllowed, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "CTL_DraggingNotAllowed")); // NOI18N - cbDraggingNotAllowed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 6; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbDraggingNotAllowed, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(cbMaximizationNotAllowed, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "CTL_MaximizationNotAllowed")); // NOI18N - cbMaximizationNotAllowed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 7; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weighty = 0.1; - gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0); - add(cbMaximizationNotAllowed, gridBagConstraints); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(8, 8, 8) + .addComponent(ignore, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE) + .addContainerGap()) + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(ignore) + .addContainerGap()) + ); }// //GEN-END:initComponents - -private void windowPosChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_windowPosChanged - cbKeepPrefSize.setEnabled( !("editor".equals( comMode.getSelectedItem()) ) ); - if( !cbKeepPrefSize.isEnabled() ) - cbKeepPrefSize.setSelected( false ); - cbSlidingNotAllowed.setEnabled( !("editor".equals( comMode.getSelectedItem()) ) ); - if( !cbSlidingNotAllowed.isEnabled() ) - cbSlidingNotAllowed.setSelected( false ); -}//GEN-LAST:event_windowPosChanged // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JCheckBox cbClosingNotAllowed; - private javax.swing.JCheckBox cbDraggingNotAllowed; - private javax.swing.JCheckBox cbKeepPrefSize; - private javax.swing.JCheckBox cbMaximizationNotAllowed; - private javax.swing.JCheckBox cbOpenedOnStart; - private javax.swing.JCheckBox cbSlidingNotAllowed; - private javax.swing.JCheckBox cbUndockingNotAllowed; - private javax.swing.JComboBox comMode; - private javax.swing.JLabel lblMode; + private javax.swing.JCheckBox ignore; + private javax.swing.JPanel panel; // End of variables declaration//GEN-END:variables + @NbBundle.Messages({ + "ACS_LayoutWarningPanel=Do you want to launch your application?" + }) private void initAccessibility() { - this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_BasicSettingsPanel")); - cbOpenedOnStart.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_OpenOnStart")); - cbKeepPrefSize.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_KeepPrefSize")); - comMode.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Mode")); + this.getAccessibleContext().setAccessibleDescription(Bundle.ACS_LayoutWarningPanel()); } } --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java @@ -46,10 +46,14 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.project.Project; @@ -105,7 +109,6 @@ } static final class DataModel extends BasicWizardIterator.BasicDataModel { - private String name; private String icon; private String mode; @@ -116,6 +119,9 @@ private boolean draggingNotAllowed = false; private boolean undockingNotAllowed = false; private boolean maximizationNotAllowed = false; + private Map newModes; + private Set existingModes; + private boolean ignorePreviousRun = true; private CreatedModifiedFiles files; @@ -158,6 +164,41 @@ public String getMode() { return mode; } + + public void defineMode(String name, String definition) { + if (newModes == null) { + newModes = new TreeMap(); + } + newModes.put(name, definition); + } + void existingMode(String name) { + if (existingModes == null) { + existingModes = new TreeSet(); + } + existingModes.add(name); + } + boolean isExistingMode(String name) { + return existingModes != null && existingModes.contains(name); + } + + Map getNewModes() { + if (newModes == null) { + return null; + } + TreeMap copy = new TreeMap(newModes); + if (existingModes != null) { + copy.keySet().removeAll(existingModes); + } + return copy.isEmpty() ? null : copy; + } + + public boolean isIgnorePreviousRun() { + return ignorePreviousRun; + } + + public void setIgnorePreviousRun(boolean ignorePreviousRun) { + this.ignorePreviousRun = ignorePreviousRun; + } public void setMode(String mode) { this.mode = mode; @@ -220,7 +261,7 @@ } } - public static void generateFileChanges(DataModel model) { + static void generateFileChanges(final DataModel model) { CreatedModifiedFiles fileChanges = new CreatedModifiedFiles(model.getProject()); Project project = model.getProject(); NbModuleProvider moduleInfo = model.getModuleInfo(); @@ -248,140 +289,165 @@ propertiesPersistence = false; } - - Map replaceTokens = new HashMap(); - replaceTokens.put("TEMPLATENAME", name);//NOI18N - replaceTokens.put("PACKAGENAME", packageName);//NOI18N - replaceTokens.put("MODE", mode); //NOI18N - replaceTokens.put("OPENED", model.isOpened() ? "true" : "false"); //NOI18N - replaceTokens.put("WINSYSBEHAVIOR", defineWinSysBehavior( model ) ); //NOI18N + if (name != null) { + Map replaceTokens = new HashMap(); + replaceTokens.put("TEMPLATENAME", name);//NOI18N + replaceTokens.put("PACKAGENAME", packageName);//NOI18N + replaceTokens.put("MODE", mode); //NOI18N + replaceTokens.put("OPENED", model.isOpened() ? "true" : "false"); //NOI18N + replaceTokens.put("WINSYSBEHAVIOR", defineWinSysBehavior( model ) ); //NOI18N - // 0. move icon file if necessary - String icon = model.getIcon(); - File fil = null; - if (icon != null) { - fil = new File(icon); - if (!fil.exists()) { - fil = null; + // 0. move icon file if necessary + String icon = model.getIcon(); + File fil = null; + if (icon != null) { + fil = new File(icon); + if (!fil.exists()) { + fil = null; + } } - } - String relativeIconPath = null; - if (fil != null) { - FileObject fo = FileUtil.toFileObject(fil); - if (!FileUtil.isParentOf(Util.getResourceDirectory(project), fo)) { - String iconPath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, - "", fo.getNameExt()); //NOI18N - fileChanges.add(fileChanges.createFile(iconPath, fo)); - relativeIconPath = packageName.replace('.', '/') + "/" + fo.getNameExt(); // NOI18N + String relativeIconPath = null; + if (fil != null) { + FileObject fo = FileUtil.toFileObject(fil); + if (!FileUtil.isParentOf(Util.getResourceDirectory(project), fo)) { + String iconPath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, + "", fo.getNameExt()); //NOI18N + fileChanges.add(fileChanges.createFile(iconPath, fo)); + relativeIconPath = packageName.replace('.', '/') + "/" + fo.getNameExt(); // NOI18N + } else { + relativeIconPath = FileUtil.getRelativePath(Util.getResourceDirectory(project), fo); + } + replaceTokens.put("ICONPATH", relativeIconPath);//NOI18N + replaceTokens.put("COMMENTICON", "");//NOI18N + } else { - relativeIconPath = FileUtil.getRelativePath(Util.getResourceDirectory(project), fo); + replaceTokens.put("ICONPATH", "SET/PATH/TO/ICON/HERE"); //NOI18N + replaceTokens.put("COMMENTICON", "//");//NOI18N } - replaceTokens.put("ICONPATH", relativeIconPath);//NOI18N - replaceTokens.put("COMMENTICON", "");//NOI18N - - } else { - replaceTokens.put("ICONPATH", "SET/PATH/TO/ICON/HERE"); //NOI18N - replaceTokens.put("COMMENTICON", "//");//NOI18N + + + // 2. update project dependencies + replaceTokens.put("MODULENAME", moduleInfo.getCodeNameBase()); // NOI18N + String specVersion = moduleInfo.getSpecVersion(); + replaceTokens.put("SPECVERSION", specVersion != null ? specVersion : "0"); // NOI18N + fileChanges.add(fileChanges.addModuleDependency("org.openide.windows")); //NOI18N + fileChanges.add(fileChanges.addManifestToken(ManifestManager.OPENIDE_MODULE_REQUIRES, WindowManager.class.getName())); + fileChanges.add(fileChanges.addModuleDependency("org.openide.util")); //NOI18N + fileChanges.add(fileChanges.addModuleDependency("org.openide.util.lookup")); //NOI18N + fileChanges.add(fileChanges.addModuleDependency("org.openide.awt")); //NOI18N + if (propertiesPersistence) { + fileChanges.add(fileChanges.addModuleDependency("org.netbeans.modules.settings")); //NOI18N + } + + // x. generate java classes + final String tcName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, + name, "TopComponent.java"); //NOI18N + FileObject template = CreatedModifiedFiles.getTemplate( + xmlLessTC ? "templateTopComponent637.java" : + (propertiesPersistence ? "templateTopComponentAnno.java" : "templateTopComponent.java") + ); + fileChanges.add(fileChanges.createFileWithSubstitutions(tcName, template, replaceTokens)); + // x. generate java classes + final String tcFormName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, + name, "TopComponent.form"); //NOI18N + template = CreatedModifiedFiles.getTemplate("templateTopComponent.form");//NOI18N + fileChanges.add(fileChanges.createFileWithSubstitutions(tcFormName, template, replaceTokens)); + + if (!actionLessTC) { + final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, + name, "Action.java"); //NOI18N + template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N + fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens)); + } + + if (!xmlLessTC) { + final String settingsName = name + "TopComponent.settings"; //NOI18N + template = CreatedModifiedFiles.getTemplate("templateSettings.xml");//NOI18N + fileChanges.add(fileChanges.createLayerEntry("Windows2/Components/" + settingsName, template, replaceTokens, null, null)); // NOI18N + } + + if (!xmlLessTC) { + final String wstcrefName = name + "TopComponent.wstcref"; //NOI18N + template = CreatedModifiedFiles.getTemplate("templateWstcref.xml");//NOI18N + fileChanges.add(fileChanges.createLayerEntry("Windows2/Modes/" + mode + "/" + wstcrefName, // NOI18N + template, replaceTokens, null, null)); + } + + String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N + if (xmlLessTC) { + // nothing in layer + } else if (actionLessTC) { + String path = "Actions/Window/" + packageName.replace('.','-') + "-" + name + "Action.instance"; // NOI18N + { + Map attrs = new HashMap(); + attrs.put("instanceCreate", "methodvalue:org.openide.windows.TopComponent.openAction"); // NOI18N + attrs.put("component", "methodvalue:" + packageName + '.' + name + "TopComponent.findInstance"); // NOI18N + if (relativeIconPath != null) { + attrs.put("iconBase", relativeIconPath); // NOI18N + } + attrs.put("displayName", "bundlevalue:" + packageName + ".Bundle#CTL_" + name + "Action"); // NOI18N + fileChanges.add( + fileChanges.createLayerEntry( + path, + null, + null, + null, + attrs + ) + ); + } + + { + Map attrs = new HashMap(); + attrs.put("originalFile", path); // NOI18N + fileChanges.add( + fileChanges.createLayerEntry( + "Menu/Window/" + name + "Action.shadow", // NOI18N + null, + null, + null, + attrs + ) + ); + } + } else { + fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N + Collections.emptySet())); + } + // XXX use @Messages where available + fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "Action", // NOI18N + name)); //NOI18N + + fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "TopComponent", // NOI18N + name + " Window")); //NOI18N + fileChanges.add(fileChanges.bundleKey(bundlePath, "HINT_" + name + "TopComponent", // NOI18N + "This is a " + name + " window")); //NOI18N } - - // 2. update project dependencies - replaceTokens.put("MODULENAME", moduleInfo.getCodeNameBase()); // NOI18N - String specVersion = moduleInfo.getSpecVersion(); - replaceTokens.put("SPECVERSION", specVersion != null ? specVersion : "0"); // NOI18N - fileChanges.add(fileChanges.addModuleDependency("org.openide.windows")); //NOI18N - fileChanges.add(fileChanges.addManifestToken(ManifestManager.OPENIDE_MODULE_REQUIRES, WindowManager.class.getName())); - fileChanges.add(fileChanges.addModuleDependency("org.openide.util")); //NOI18N - fileChanges.add(fileChanges.addModuleDependency("org.openide.util.lookup")); //NOI18N - fileChanges.add(fileChanges.addModuleDependency("org.openide.awt")); //NOI18N - if (propertiesPersistence) { - fileChanges.add(fileChanges.addModuleDependency("org.netbeans.modules.settings")); //NOI18N + final Map newModes = model.getNewModes(); + if (newModes != null) { + Set files = new HashSet(); + for (String wsmode : newModes.keySet()) { + files.add(wsmode + ".wsmode"); + } + + fileChanges.add(fileChanges.layerModifications(new CreatedModifiedFiles.LayerOperation() { + @Override + public void run(FileSystem layer) throws IOException { + FileObject fo = FileUtil.createFolder(layer.getRoot(), "Windows2/Modes"); + for (Map.Entry entry : newModes.entrySet()) { + FileObject wsmode = fo.createData(entry.getKey() + ".wsmode"); + OutputStream os = wsmode.getOutputStream(); + try { + os.write(entry.getValue().getBytes("UTF-8")); + } finally { + os.close(); + } + } + } + }, files)); } - // x. generate java classes - final String tcName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, - name, "TopComponent.java"); //NOI18N - FileObject template = CreatedModifiedFiles.getTemplate( - xmlLessTC ? "templateTopComponent637.java" : - (propertiesPersistence ? "templateTopComponentAnno.java" : "templateTopComponent.java") - ); - fileChanges.add(fileChanges.createFileWithSubstitutions(tcName, template, replaceTokens)); - // x. generate java classes - final String tcFormName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, - name, "TopComponent.form"); //NOI18N - template = CreatedModifiedFiles.getTemplate("templateTopComponent.form");//NOI18N - fileChanges.add(fileChanges.createFileWithSubstitutions(tcFormName, template, replaceTokens)); - - if (!actionLessTC) { - final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, - name, "Action.java"); //NOI18N - template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N - fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens)); - } - - if (!xmlLessTC) { - final String settingsName = name + "TopComponent.settings"; //NOI18N - template = CreatedModifiedFiles.getTemplate("templateSettings.xml");//NOI18N - fileChanges.add(fileChanges.createLayerEntry("Windows2/Components/" + settingsName, template, replaceTokens, null, null)); // NOI18N - } - - if (!xmlLessTC) { - final String wstcrefName = name + "TopComponent.wstcref"; //NOI18N - template = CreatedModifiedFiles.getTemplate("templateWstcref.xml");//NOI18N - fileChanges.add(fileChanges.createLayerEntry("Windows2/Modes/" + mode + "/" + wstcrefName, // NOI18N - template, replaceTokens, null, null)); - } - - String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N - if (xmlLessTC) { - // nothing in layer - } else if (actionLessTC) { - String path = "Actions/Window/" + packageName.replace('.','-') + "-" + name + "Action.instance"; // NOI18N - { - Map attrs = new HashMap(); - attrs.put("instanceCreate", "methodvalue:org.openide.windows.TopComponent.openAction"); // NOI18N - attrs.put("component", "methodvalue:" + packageName + '.' + name + "TopComponent.findInstance"); // NOI18N - if (relativeIconPath != null) { - attrs.put("iconBase", relativeIconPath); // NOI18N - } - attrs.put("displayName", "bundlevalue:" + packageName + ".Bundle#CTL_" + name + "Action"); // NOI18N - fileChanges.add( - fileChanges.createLayerEntry( - path, - null, - null, - null, - attrs - ) - ); - } - - { - Map attrs = new HashMap(); - attrs.put("originalFile", path); // NOI18N - fileChanges.add( - fileChanges.createLayerEntry( - "Menu/Window/" + name + "Action.shadow", // NOI18N - null, - null, - null, - attrs - ) - ); - } - } else { - fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N - Collections.emptySet())); - } - // XXX use @Messages where available - fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "Action", // NOI18N - name)); //NOI18N - - fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "TopComponent", // NOI18N - name + " Window")); //NOI18N - fileChanges.add(fileChanges.bundleKey(bundlePath, "HINT_" + name + "TopComponent", // NOI18N - "This is a " + name + " window")); //NOI18N - model.setCreatedModifiedFiles(fileChanges); } --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/polishing.xsl +++ a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/polishing.xsl @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + --- a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/DesignSupportTest.java +++ a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/DesignSupportTest.java @@ -0,0 +1,76 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.apisupport.project.ui.wizard.winsys; + +import java.io.IOException; +import java.io.OutputStream; +import org.netbeans.junit.NbTestCase; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; + + +public class DesignSupportTest extends NbTestCase { + private FileObject fo; + + public DesignSupportTest(String n) { + super(n); + } + + @Override + protected void setUp() throws IOException { + FileSystem ms = FileUtil.createMemoryFileSystem(); + fo = ms.getRoot().createData("my.wsmode"); + OutputStream os = fo.getOutputStream(); + FileUtil.copy(DesignSupportTest.class.getResourceAsStream("testWsmode.xml"), os); + os.close(); + } + public void testReadingOfAMode() throws Exception { + String read = DesignSupport.readMode(fo); + if (read.contains("active-tc")) { + fail("No active-tc:\n" + read); + } + if (read.indexOf("path orientation") == -1) { + fail(" + + + + + + + + + + + + + + --- a/core.windows/arch.xml +++ a/core.windows/arch.xml @@ -583,6 +583,15 @@ Action obj = (Action)fo.getAttribute("instanceCreate"); + + Special property for apisupport project to run an application in a + design mode to define new layout. + In such mode user components are removed and replaced with uniform ones + allowing change of a mode name. Don't rely on this property much, it may + soon go away - as soon as apisupport is rewritten to have quasi-preview + editor. +

--- a/core.windows/nbproject/project.xml +++ a/core.windows/nbproject/project.xml @@ -67,7 +67,7 @@ 1.6
- + org.netbeans.modules.settings --- a/core.windows/src/org/netbeans/core/windows/Central.java +++ a/core.windows/src/org/netbeans/core/windows/Central.java @@ -557,6 +557,10 @@ WindowManagerImpl.getInstance().doFirePropertyChange( WindowManager.PROP_MODES, null, null); } + + final void setModeName(ModeImpl mode, String text) { + model.setModeName(mode, text); + } /** Removes mode from model and requests view (if needed). */ public void removeMode(ModeImpl mode) { --- a/core.windows/src/org/netbeans/core/windows/ModeImpl.java +++ a/core.windows/src/org/netbeans/core/windows/ModeImpl.java @@ -565,6 +565,10 @@ // Utility methods<< //////////////////// + public void setModeName(String text) { + getCentral().setModeName(this, text); + } + } --- a/core.windows/src/org/netbeans/core/windows/WindowSystemImpl.java +++ a/core.windows/src/org/netbeans/core/windows/WindowSystemImpl.java @@ -48,6 +48,7 @@ import java.awt.EventQueue; import org.netbeans.core.WindowSystem; +import org.netbeans.core.windows.design.DesignView; import org.netbeans.core.windows.services.DialogDisplayerImpl; import org.netbeans.core.windows.view.ui.MainWindow; import org.openide.util.lookup.ServiceProvider; @@ -64,6 +65,9 @@ @Override public void init() { assert !EventQueue.isDispatchThread(); + if (Boolean.getBoolean("org.netbeans.core.WindowSystem.designMode")) { // NOI18N + DesignView.initialize(); + } MainWindow.init(); } --- a/core.windows/src/org/netbeans/core/windows/design/Bundle.properties +++ a/core.windows/src/org/netbeans/core/windows/design/Bundle.properties @@ -0,0 +1,46 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2011 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2011 Sun Microsystems, Inc. + +CTL_DesignViewComponentTopComponent=Mode Component +HINT_DesignViewComponentTopComponent=Represents a mode and allows its rename +DesignViewComponent.modeName.text= +DesignViewComponent.jLabel1.text=Mode Name: +DesignViewComponent.jButton1.text=Rename Mode + --- a/core.windows/src/org/netbeans/core/windows/design/DesignView.java +++ a/core.windows/src/org/netbeans/core/windows/design/DesignView.java @@ -0,0 +1,174 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.core.windows.design; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.IOException; +import org.openide.awt.ActionID; +import org.openide.awt.ActionRegistration; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +/** + * + * @author Jaroslav Tulach + */ +public final class DesignView implements Runnable, PropertyChangeListener { + private static final DesignView INSTANCE = new DesignView(); + static int designModeCounter; + + private DesignView() { + } + + public static void initialize() { + INSTANCE.cleanToolbarsAndMenu(); + WindowManager.getDefault().invokeWhenUIReady(INSTANCE); + TopComponent.getRegistry().addPropertyChangeListener(INSTANCE); + } + + private void cleanToolbarsAndMenu() { + FileObject tb = FileUtil.getConfigFile("Toolbars"); + + if (tb != null) { + for (FileObject fileObject : tb.getChildren()) { + try { + fileObject.delete(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + FileObject shadow; + try { + shadow = tb.createFolder("DesignView").createData("org-netbeans-core-windows-model-NewMode.shadow"); + shadow.setAttribute("originalFile", "Actions/System/org-netbeans-core-windows-model-NewMode.instance"); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + FileObject mb = FileUtil.getConfigFile("Menu"); + + if (mb != null) { + for (FileObject fileObject : mb.getChildren()) { + try { + fileObject.delete(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + FileObject ws = FileUtil.getConfigFile("Windows2Local"); + + if (ws != null) { + try { + ws.delete(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + WindowManager.getDefault().invokeWhenUIReady(this); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (TopComponent.Registry.PROP_OPENED.equals(evt.getPropertyName())) { + for (Mode m : WindowManager.getDefault().getModes()) { + for (TopComponent topComponent : m.getTopComponents()) { + if (topComponent instanceof DesignViewComponent) { + continue; + } + topComponent.close(); + } + } + } + } + + @Override + public void run() { + BIG: for (Mode m : WindowManager.getDefault().getModes()) { + boolean found = false; + for (TopComponent topComponent : m.getTopComponents()) { + if (topComponent instanceof DesignViewComponent) { + found = true; + continue; + } + topComponent.close(); + } + if (!found) { + final DesignViewComponent mc = new DesignViewComponent(); + m.dockInto(mc); + mc.open(); + } + } + } + + @ActionID(category = "System", id = "org.netbeans.core.windows.model.NewMode") + @ActionRegistration(iconBase = "org/netbeans/core/windows/design/DesignView.png", + displayName = "#CTL_NewMode") + @Messages("CTL_NewMode=New Mode") + public static ActionListener newModeAction() { + return new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DesignViewComponent dvc = new DesignViewComponent(); + /* + WindowManagerImpl wmi = (WindowManagerImpl)WindowManager.getDefault(); + Mode m = wmi.createMode("mode_" + (++designModeCounter), + Constants.MODE_KIND_VIEW, Constants.MODE_KIND_VIEW, true, + new SplitConstraint[]{new SplitConstraint(Constants.HORIZONTAL, 1, 0.2)} + ); + m.dockInto(dvc); + */ + dvc.open(); + dvc.requestAttention(true); + } + }; + } +} --- a/core.windows/src/org/netbeans/core/windows/design/DesignViewComponent.form +++ a/core.windows/src/org/netbeans/core/windows/design/DesignViewComponent.form @@ -0,0 +1,109 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
--- a/core.windows/src/org/netbeans/core/windows/design/DesignViewComponent.java +++ a/core.windows/src/org/netbeans/core/windows/design/DesignViewComponent.java @@ -0,0 +1,209 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.core.windows.design; + +import org.openide.util.NbBundle; +import org.openide.windows.Mode; +import org.openide.windows.TopComponent; +import org.netbeans.api.settings.ConvertAsProperties; +import org.netbeans.core.windows.ModeImpl; +import org.openide.windows.WindowManager; + +@ConvertAsProperties( + dtd = "-//org.netbeans.core.windows.model//DesignViewComponent//EN", + autostore = false +) +@TopComponent.Description(preferredID = "DesignViewComponentTopComponent", + iconBase = "org/netbeans/core/windows/model/DesignView.png", + persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED +) +final class DesignViewComponent extends TopComponent { + DesignViewComponent() { + initComponents(); + setName(NbBundle.getMessage(DesignViewComponent.class, "CTL_DesignViewComponentTopComponent")); + setToolTipText(NbBundle.getMessage(DesignViewComponent.class, "HINT_DesignViewComponentTopComponent")); + putClientProperty("TopComponentAllowDockAnywhere", true); + refresh(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + modeName = new javax.swing.JTextField(); + jPanel1 = new javax.swing.JPanel(); + jPanel2 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + modeName.setText(org.openide.util.NbBundle.getMessage(DesignViewComponent.class, "DesignViewComponent.modeName.text", new Object[] {})); // NOI18N + modeName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + modeNameActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 500, Short.MAX_VALUE) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 88, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 500, Short.MAX_VALUE) + ); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 63, Short.MAX_VALUE) + ); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DesignViewComponent.class, "DesignViewComponent.jLabel1.text", new Object[] {})); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(DesignViewComponent.class, "DesignViewComponent.jButton1.text", new Object[] {})); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(modeName, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton1)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(9, 9, 9) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(modeName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(3, 3, 3) + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void refresh() { + Mode mode = WindowManager.getDefault().findMode(this); + if (mode != null) { + modeName.setText(mode.getName()); + setName(mode.getName()); + } + } + + private void modeNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modeNameActionPerformed + Mode mode = WindowManager.getDefault().findMode(this); + if (mode instanceof ModeImpl) { + ModeImpl mi = (ModeImpl)mode; + mi.setModeName(modeName.getText()); + } + + for (TopComponent tc : mode.getTopComponents()) { + if (tc instanceof DesignViewComponent) { + DesignViewComponent dvc = (DesignViewComponent)tc; + dvc.refresh(); + } + } + }//GEN-LAST:event_modeNameActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + modeNameActionPerformed(evt); + }//GEN-LAST:event_jButton1ActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JTextField modeName; + // End of variables declaration//GEN-END:variables + + @Override + public void componentOpened() { + refresh(); + } + + @Override + protected void componentActivated() { + refresh(); + } + + void writeProperties(java.util.Properties p) { + // better to version settings since initial version as advocated at + // http://wiki.apidesign.org/wiki/PropertyFiles + p.setProperty("version", "1.0"); + // TODO store your settings + } + + void readProperties(java.util.Properties p) { + String version = p.getProperty("version"); + // TODO read your settings according to their version + } +} --- a/core.windows/src/org/netbeans/core/windows/model/DefaultModeModel.java +++ a/core.windows/src/org/netbeans/core/windows/model/DefaultModeModel.java @@ -73,7 +73,7 @@ /** Programatic name of mode. */ - private final String name; + private String name; private final Set otherNames = new HashSet(3); @@ -123,7 +123,7 @@ this.permanent = permanent; this.topComponentSubModel = new TopComponentSubModel(kind); } - + ///////////////////////////////////// // Mutator methods >> ///////////////////////////////////// @@ -380,6 +380,11 @@ return topComponentSubModel.getOpenedTopComponents(); } } + + @Override + public final void setName(String name) { + this.name = name; + } // XXX @Override --- a/core.windows/src/org/netbeans/core/windows/model/DefaultModel.java +++ a/core.windows/src/org/netbeans/core/windows/model/DefaultModel.java @@ -796,6 +796,12 @@ return null; } } + + @Override + public final void setModeName(ModeImpl mode, String name) { + ModeModel modeModel = getModelForMode(mode); + modeModel.setName(name); + } /** Gets bounds. */ @Override --- a/core.windows/src/org/netbeans/core/windows/model/ModeModel.java +++ a/core.windows/src/org/netbeans/core/windows/model/ModeModel.java @@ -62,6 +62,8 @@ interface ModeModel { // Mutators + /** Change name of the mode */ + public void setName(String name); /** Sets state. */ public void setState(int state); /** Sets bounds. */ --- a/core.windows/src/org/netbeans/core/windows/model/Model.java +++ a/core.windows/src/org/netbeans/core/windows/model/Model.java @@ -108,6 +108,8 @@ public void addModeAroundEditor(ModeImpl mode, String side); /** Removes mode. */ public void removeMode(ModeImpl mode); + /** Renames a mode */ + public void setModeName(ModeImpl mode, String name); /** Sets mode constraints. */ public void setModeConstraints(ModeImpl mode, SplitConstraint[] constraints); /** Adds top component group. */