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: /*
043: * Created on Jul 15, 2003
044: *
045: */
046: package org.netbeans.modules.uml.ui.controls.newdialog;
047:
048: import java.awt.Frame;
049:
050: import org.netbeans.modules.uml.ui.support.NewDialogTabKind;
051: import org.netbeans.modules.uml.ui.support.wizard.IWizardSheet;
052:
053: /**
054: * @author sumitabhk
055: *
056: */
057: public class NewDialog implements INewDialog {
058: /// Should we run silent
059: protected boolean m_bRunSilent;
060:
061: /// What tabs should we display
062: protected boolean m_bWorkspaceTab;
063: protected boolean m_bProjectTab;
064: protected boolean m_bDiagramTab;
065: protected boolean m_bPackageTab;
066: protected boolean m_bElementTab;
067:
068: /// The various defaults
069: INewDialogWorkspaceDetails m_WorkspaceDetails = null;
070: INewDialogProjectDetails m_ProjectDetails = null;
071: INewDialogDiagramDetails m_DiagramDetails = null;
072: INewDialogPackageDetails m_PackageDetails = null;
073: INewDialogElementDetails m_ElementDetails = null;
074:
075: /// The default tab
076: int /*NewDialogTabKind*/m_DefaultTab;
077:
078: /// The results of this dialog
079: INewDialogTabDetails m_Results = null;
080:
081: /**
082: *
083: */
084: public NewDialog() {
085: super ();
086:
087: m_bRunSilent = false;
088:
089: m_bWorkspaceTab = true;
090: m_bProjectTab = true;
091: m_bDiagramTab = true;
092: m_bPackageTab = true;
093: m_bElementTab = true;
094:
095: m_DefaultTab = NewDialogTabKind.NDTK_ALL;
096:
097: // IMessenger pMsg = ProductHelper.getMessenger();
098: // if (pMsg != null)
099: // {
100: // m_bRunSilent = pMsg.getDisablingMessageing();
101: // }
102: }
103:
104: /**
105: * Display the dialog.
106: *
107: * @param parent[in] The HWND parent for this dialog
108: *
109: * @return HRESULT
110: */
111: public INewDialogTabDetails display(Frame parent) {
112: return display2(null, parent);
113: }
114:
115: /**
116: * Display the dialog.
117: *
118: * @param pValidateProcessor [in] The validator object used to make sure the tabs are valid
119: * for the new dialog.
120: * @param parent[in] The HWND parent for this dialog
121: *
122: * @return HRESULT
123: */
124: public INewDialogTabDetails display2(
125: INewDialogValidateProcessor pValidateProcessor, Frame parent) {
126: INewDialogTabDetails retObj = null;
127: try {
128: if (!m_bRunSilent) {
129: // Set the default tab to be the last tab used, unless the user has specifically
130: // said to set a default tab
131: if (m_DefaultTab == NewDialogTabKind.NDTK_ALL) {
132: // The default is the last tab used.
133: m_DefaultTab = NewDialogTabKind.NWIK_NEW_PACKAGE;
134:
135: //need to find a way to get last opened tab.
136: }
137:
138: JDefaultNewDialog dialog = null;
139: if (parent != null) {
140: String title = NewDialogResources
141: .getString("IDS_NEWDIALOG");
142: dialog = new JDefaultNewDialog(parent, title, true);
143: } else {
144: dialog = new JDefaultNewDialog();
145: }
146: dialog.init(pValidateProcessor);
147: dialog.init(null, null, null);
148: if (m_DiagramDetails != null) {
149: dialog.initWithDefaults(m_DiagramDetails);
150: retObj = m_DiagramDetails;
151: } else if (m_ElementDetails != null) {
152: dialog.initWithDefaults(m_ElementDetails);
153: retObj = m_ElementDetails;
154: } else if (m_PackageDetails != null) {
155: dialog.initWithDefaults(m_PackageDetails);
156: retObj = m_PackageDetails;
157: } else if (m_ProjectDetails != null) {
158: dialog.initWithDefaults(m_ProjectDetails);
159: retObj = m_ProjectDetails;
160: } else if (m_WorkspaceDetails != null) {
161: dialog.initWithDefaults(m_WorkspaceDetails);
162: retObj = m_WorkspaceDetails;
163: } else {
164: dialog.initWithDefaults(null);
165: }
166:
167: if (dialog.doModal() == IWizardSheet.PSWIZB_FINISH) {
168: retObj = dialog.getResult();
169: } else {
170: retObj = null;
171: }
172: }
173: } catch (Exception e) {
174: //Log.stackTrace(e);
175: }
176: m_Results = retObj;
177: return retObj;
178: }
179:
180: /* (non-Javadoc)
181: * @see org.netbeans.modules.uml.ui.controls.newdialog.INewDialog#putDefaultTab(int)
182: */
183: public long putDefaultTab(int nDefaultTab) {
184: m_DefaultTab = nDefaultTab;
185: return 0;
186: }
187:
188: /**
189: * Adds a tab to the dialog. If the user doesn't specify then by default
190: * all are on. Once the user adds a specific tab all others are turned off.
191: *
192: * @param nTabKind[in]
193: */
194: public long addTab(int nTabKind) {
195: boolean bThisTab = false;
196: if (nTabKind == NewDialogTabKind.NDTK_NONE) {
197: m_bWorkspaceTab = false;
198: m_bProjectTab = false;
199: m_bDiagramTab = false;
200: m_bPackageTab = false;
201: m_bElementTab = false;
202: } else if (nTabKind == NewDialogTabKind.NDTK_ALL) {
203: m_bWorkspaceTab = true;
204: m_bProjectTab = true;
205: m_bDiagramTab = true;
206: m_bPackageTab = true;
207: m_bElementTab = true;
208: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_WORKSPACE) {
209: bThisTab = m_bWorkspaceTab;
210: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_PROJECT) {
211: bThisTab = m_bProjectTab;
212: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_DIAGRAM) {
213: bThisTab = m_bDiagramTab;
214: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_PACKAGE) {
215: bThisTab = m_bPackageTab;
216: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_ELEMENT) {
217: bThisTab = m_bElementTab;
218: }
219:
220: if (bThisTab) {
221: if (m_bWorkspaceTab && m_bProjectTab && m_bDiagramTab
222: && m_bPackageTab && m_bElementTab) {
223: // All are set. Turn them all off and add just this guy
224: m_bWorkspaceTab = false;
225: m_bProjectTab = false;
226: m_bDiagramTab = false;
227: m_bPackageTab = false;
228: m_bElementTab = false;
229: }
230: bThisTab = true;
231: }
232:
233: return 0;
234: }
235:
236: /**
237: * Is this a tab that is gonna get displayed?
238: *
239: * @param nTabKind [in] The tab kind to see if it's gonna display. Don't use
240: * tab kinds of none or all.
241: * @param bIsTab [out,retval] TRUE if this tab is displayed.
242: */
243: public boolean isTab(int nTabKind) {
244: boolean result = false;
245: if (nTabKind == NewDialogTabKind.NWIK_NEW_WORKSPACE) {
246: result = (m_bWorkspaceTab) ? true : false;
247: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_PROJECT) {
248: result = (m_bProjectTab) ? true : false;
249: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_DIAGRAM) {
250: result = (m_bDiagramTab) ? true : false;
251: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_PACKAGE) {
252: result = (m_bPackageTab) ? true : false;
253: } else if (nTabKind == NewDialogTabKind.NWIK_NEW_ELEMENT) {
254: result = (m_bElementTab) ? true : false;
255: }
256: return result;
257: }
258:
259: /**
260: * Provides defaults to one of the tabs.
261: *
262: * @param pDetails[in]
263: *
264: * @return HRESULT
265: */
266: public long specifyDefaults(INewDialogTabDetails pDetails) {
267: if (pDetails instanceof INewDialogWorkspaceDetails) {
268: INewDialogWorkspaceDetails pWorkspace = (INewDialogWorkspaceDetails) pDetails;
269:
270: // Make sure this tab is on
271: m_bWorkspaceTab = true;
272: m_WorkspaceDetails = pWorkspace;
273: } else if (pDetails instanceof INewDialogProjectDetails) {
274: INewDialogProjectDetails pProject = (INewDialogProjectDetails) pDetails;
275:
276: // Make sure this tab is on
277: m_bProjectTab = true;
278: m_ProjectDetails = pProject;
279: } else if (pDetails instanceof INewDialogDiagramDetails) {
280: INewDialogDiagramDetails pDiagram = (INewDialogDiagramDetails) pDetails;
281:
282: // Make sure this tab is on
283: m_bDiagramTab = true;
284: m_DiagramDetails = pDiagram;
285: } else if (pDetails instanceof INewDialogPackageDetails) {
286: INewDialogPackageDetails pPackage = (INewDialogPackageDetails) pDetails;
287:
288: // Make sure this tab is on
289: m_bPackageTab = true;
290: m_PackageDetails = pPackage;
291: } else if (pDetails instanceof INewDialogElementDetails) {
292: INewDialogElementDetails pElement = (INewDialogElementDetails) pDetails;
293:
294: // Make sure this tab is on
295: m_bElementTab = true;
296: m_ElementDetails = pElement;
297: }
298:
299: return 0;
300: }
301:
302: /* (non-Javadoc)
303: * @see org.netbeans.modules.uml.ui.controls.newdialog.INewDialog#getResult()
304: */
305: public INewDialogTabDetails getResult() {
306: return m_Results;
307: }
308:
309: /**
310: * Returns the silent flag for this dialog. If silent then any Display calls will
311: * not display a dialog, but rather immediately return S_OK;
312: *
313: * @param pVal Has this dialog been silenced
314: *
315: * @return HRESULT
316: */
317: public boolean isRunSilent() {
318: return m_bRunSilent;
319: }
320:
321: /**
322: * Sets the silent flag for this dialog. If silent then any Display calls will
323: * not display a dialog, but rather immediately return S_OK;
324: *
325: * @param newVal Whether or not this dialog should be silent
326: *
327: * @return HRESULT
328: */
329: public void setIsRunSilent(boolean value) {
330: m_bRunSilent = value;
331: }
332:
333: }
|