001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.designpattern;
043:
044: import java.awt.Dimension;
045: import java.awt.GridBagConstraints;
046: import java.awt.GridBagLayout;
047: import java.awt.Insets;
048: import java.awt.SystemColor;
049: import java.awt.event.ActionEvent;
050: import java.io.File;
051:
052: import javax.swing.JCheckBox;
053: import javax.swing.JTextArea;
054: import javax.swing.JTextField;
055:
056: import org.netbeans.modules.uml.common.generics.ETPairT;
057: import org.netbeans.modules.uml.core.metamodel.infrastructure.ICollaboration;
058: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
059: import org.netbeans.modules.uml.core.support.umlutils.ETList;
060: import org.netbeans.modules.uml.ui.support.ProductHelper;
061: import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
062: import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
063: import org.netbeans.modules.uml.ui.support.wizard.IWizardSheet;
064: import org.netbeans.modules.uml.ui.support.wizard.WizardInteriorPage;
065:
066: public class WizardOptions extends WizardInteriorPage {
067:
068: private static final String PG_CAPTION = DefaultDesignPatternResource
069: .getString("IDS_WIZARDCAPTION");
070: private static final String PG_TITLE = DefaultDesignPatternResource
071: .getString("IDS_OPTIONS");
072: private static final String PG_SUBTITLE = DefaultDesignPatternResource
073: .getString("IDS_OPTIONSHELP");
074:
075: private Wizard m_Wizard = null;
076:
077: private JCheckBox m_Create = new JCheckBox();
078: private JTextField m_DiagramName = new JTextField();
079: private JTextArea helpCaption = new JTextArea();
080:
081: public WizardOptions(IWizardSheet parent, String caption,
082: String headerTitle, String headerSubTitle) {
083: super (parent, caption, headerTitle, headerSubTitle);
084: createUI();
085: }
086:
087: public WizardOptions(IWizardSheet parent) {
088: this (parent, PG_CAPTION, PG_TITLE, PG_SUBTITLE);
089: }
090:
091: protected void createUI() {
092: super .createUI();
093:
094: pnlContents.setLayout(new GridBagLayout());
095:
096: m_Create.setText(DefaultDesignPatternResource
097: .determineText(DefaultDesignPatternResource
098: .getString("IDS_CREATECLASSDIAGRAM")));
099: DefaultDesignPatternResource.setMnemonic(m_Create,
100: DefaultDesignPatternResource
101: .getString("IDS_CREATECLASSDIAGRAM"));
102: m_Create.getAccessibleContext().setAccessibleDescription(
103: DefaultDesignPatternResource
104: .getString("ACSD_CREATE_CHECKBOX"));
105:
106: helpCaption.setLineWrap(true);
107: helpCaption.setOpaque(false);
108: helpCaption.setPreferredSize(new Dimension(300, 30));
109: helpCaption.setMinimumSize(new Dimension(300, 30));
110: helpCaption.setFont(new java.awt.Font("SansSerif", 0, 10));
111: helpCaption.setEditable(false);
112: helpCaption.setFocusable(false);
113: helpCaption.getAccessibleContext()
114: .setAccessibleName(
115: DefaultDesignPatternResource
116: .getString("ACSN_TEXTAREA"));
117: helpCaption.getAccessibleContext()
118: .setAccessibleDescription(
119: DefaultDesignPatternResource
120: .getString("ACSD_TEXTAREA"));
121:
122: m_DiagramName.setEnabled(false);
123: m_DiagramName.getAccessibleContext().setAccessibleName(
124: DefaultDesignPatternResource
125: .getString("ACSN_DIAGRAMNAME"));
126: m_DiagramName.getAccessibleContext().setAccessibleDescription(
127: DefaultDesignPatternResource
128: .getString("ACSD_DIAGRAMNAME"));
129:
130: pnlContents.add(m_Create, new GridBagConstraints(0, 0, 1, 1,
131: 0.0, 0.0, GridBagConstraints.WEST,
132: GridBagConstraints.NONE, new Insets(20, 7, 3, 205), 32,
133: 0));
134: pnlContents.add(m_DiagramName, new GridBagConstraints(0, 1, 1,
135: 1, 1.0, 0.0, GridBagConstraints.WEST,
136: GridBagConstraints.HORIZONTAL,
137: new Insets(0, 10, 0, 10), 284, 0));
138: pnlContents.add(helpCaption, new GridBagConstraints(0, 2, 1, 1,
139: 1.0, 1.0, GridBagConstraints.WEST,
140: GridBagConstraints.BOTH, new Insets(5, 20, 200, 40),
141: 47, 1));
142:
143: pnlContents.setBorder(new javax.swing.border.EmptyBorder(
144: new java.awt.Insets(5, 5, 5, 5)));
145:
146: this .addActionListeners();
147: this .onInitDialog();
148: }
149:
150: private void addActionListeners() {
151:
152: m_Create.addActionListener(new java.awt.event.ActionListener() {
153: public void actionPerformed(java.awt.event.ActionEvent evt) {
154: m_Create_actionPerformed(evt);
155: }
156: });
157:
158: }
159:
160: private void m_Create_actionPerformed(ActionEvent e) {
161: onCreateDiagram();
162: }
163:
164: /**
165: * Called when dialog is initialized
166: *
167: *
168: *
169: * @return BOOL
170: *
171: */
172: protected boolean onInitDialog() {
173: super .onInitDialog();
174:
175: IWizardSheet parent = getParentSheet();
176: m_Wizard = (Wizard) parent;
177:
178: return true; // return TRUE unless you set the focus to a control
179: }
180:
181: /**
182: * Called when the user clicks back
183: *
184: *
185: *
186: * @return LRESULT Whether or not to continue to the next page
187: *
188: */
189: public void onWizardBack() {
190:
191: if (m_Wizard != null) {
192: m_Wizard.m_RefreshPages = false;
193: }
194: super .onWizardBack();
195: }
196:
197: /**
198: * Called when the user clicks next
199: *
200: *
201: *
202: * @return LRESULT Whether or not to continue to the next page
203: *
204: */
205: public void onWizardNext() {
206: // validate the page information
207: ETList<String> errorList = validatePage();
208: if (errorList != null && errorList.size() == 0) {
209: IDesignPatternDetails pDetails = m_Wizard.getDetails();
210: if (pDetails != null) {
211: if (m_Create.isSelected()) {
212: pDetails.setCreateDiagram(true);
213: } else {
214: pDetails.setCreateDiagram(false);
215: }
216: // store the diagram name
217: String diagName = m_DiagramName.getText();
218: pDetails.setDiagramName(diagName);
219: super .onWizardNext();
220: }
221: } else if (errorList != null && errorList.size() > 0) {
222: // display the errors
223: String msg = DesignPatternUtilities
224: .formatErrorMessage(errorList);
225: DesignPatternUtilities.displayErrorMessage(m_Wizard, msg);
226: }
227: }
228:
229: /**
230: * Performs page validations -
231: *
232: *
233: * @param errList[out] An array of errors that occurred on the page
234: *
235: * @return HRESULT
236: *
237: */
238: private ETList<String> validatePage() {
239: ETList<String> tempList = new ETArrayList<String>();
240: if (m_Create.isSelected()) {
241: String diagName = m_DiagramName.getText();
242: IProxyDiagramManager pDiagManager = ProxyDiagramManager
243: .instance();
244: if (pDiagManager != null) {
245: ETPairT<Boolean, String> pResult = pDiagManager
246: .isValidDiagramName(diagName);
247: if (pResult != null) {
248: boolean bIsCorrect = pResult.getParamOne()
249: .booleanValue();
250: if (!bIsCorrect) {
251: String err = DesignPatternUtilities
252: .translateString("IDS_INVALIDDIAGRAMNAME");
253: tempList.add(err);
254: }
255: }
256: }
257: }
258: return tempList;
259: }
260:
261: private void onCreateDiagram() {
262: if (m_Create.isSelected()) {
263: m_DiagramName.setEnabled(true);
264: populateDiagramName();
265: m_DiagramName.requestFocus();
266: m_DiagramName.selectAll();
267: } else {
268: m_DiagramName.setText("");
269: m_DiagramName.setEnabled(false);
270: }
271: }
272:
273: /**
274: * Populate the diagram name edit box
275: *
276: * @return HRESULT
277: */
278: private void populateDiagramName() {
279: if (m_Wizard != null) {
280: IDesignPatternDetails pDetails = m_Wizard.getDetails();
281: if (pDetails != null) {
282: ICollaboration pCollab = pDetails.getCollaboration();
283: if (pCollab != null) {
284: String name = pCollab.getName();
285: name += DefaultDesignPatternResource
286: .getString("IDS_DIAGRAM");
287: m_DiagramName.setText(name);
288: }
289: }
290: }
291: }
292:
293: }
|