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: * DoorsReqProvider.java
044: *
045: * Created on July 2, 2004, 7:04 AM
046: */
047:
048: package org.netbeans.modules.uml.requirements.doorsprovider;
049:
050: //import org.netbeans.modules.uml.core.addinframework.IAddInDescriptor;
051: import java.awt.Dialog;
052: import org.netbeans.modules.uml.core.metamodel.structure.IRequirementArtifact;
053: import org.netbeans.modules.uml.core.requirementsframework.IRequirement;
054: import org.netbeans.modules.uml.core.requirementsframework.IRequirementSource;
055: import org.netbeans.modules.uml.core.requirementsframework.RequirementSource;
056: import org.netbeans.modules.uml.core.requirementsframework.IRequirementsProvider;
057: import org.netbeans.modules.uml.core.requirementsframework.RequirementsException;
058: import org.netbeans.modules.uml.core.requirementsframework.RequirementUtility;
059: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
060: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
061: import org.netbeans.modules.uml.core.support.umlutils.ETList;
062: import org.netbeans.modules.uml.ui.support.ProductHelper;
063: import org.netbeans.modules.uml.ui.support.UIFactory;
064: import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
065: import org.netbeans.modules.uml.ui.support.commondialogs.IQuestionDialog;
066: import org.netbeans.modules.uml.ui.support.commondialogs.MessageDialogKindEnum;
067: import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
068: import org.netbeans.modules.uml.ui.support.commondialogs.MessageResultKindEnum;
069: import org.netbeans.modules.uml.ui.support.commondialogs.IErrorDialog;
070: import java.awt.Frame;
071: import org.dom4j.Document;
072: import org.dom4j.Node;
073: import org.openide.DialogDescriptor;
074: import org.openide.DialogDisplayer;
075: import org.openide.NotifyDescriptor;
076: import org.openide.util.NbBundle;
077:
078: /**
079: *
080: * @author Trey Spiva
081: */
082: public class DoorsReqProvider implements IDoorsReqProvider,
083: IRequirementsProvider {
084: private String m_ProgID = "org.netbeans.modules.uml.ui.products.ad.requirementsprovider.doorprovider";
085: private static boolean m_bProviderAvailable = true;
086:
087: //private BundleSupport m_Bundle = new BundleSupport("org/netbeans/modules/uml/requirements/doorsprovider/Bundle");
088:
089: /** Creates a new instance of DoorsReqProvider */
090: public DoorsReqProvider() {
091: }
092:
093: public String getLocation() {
094: return "";
095: }
096:
097: public String getID() {
098: return "";
099: }
100:
101: public String getName() {
102: return "DoorsReqProvider";
103: }
104:
105: public String getProgID() {
106: return m_ProgID;
107: }
108:
109: public void setProgID(String sProgID) {
110: m_ProgID = sProgID;
111: }
112:
113: public String getDisplayName() {
114: return "DOORS Requirements Provider";
115: }
116:
117: public String getDescription() {
118: return NbBundle.getMessage(DoorsReqProvider.class, ""
119: + "IDS_DOORS_Requirement_Provider_Desc");
120: }
121:
122: /**
123: * Called when the addin is initialized.
124: */
125: public long initialize(Object context) {
126: return 0;
127: }
128:
129: /**
130: * Called when the addin is deinitialized.
131: */
132: public long deInitialize(Object context) {
133: return 0;
134: }
135:
136: /**
137: *
138: * Called when the addin is unloaded.
139: *
140: * @param context[in]
141: *
142: * @return void
143: *
144: */
145: public long unLoad(Object context) {
146: return 0;
147: }
148:
149: /**
150: * Get the version of the addin.
151: */
152: public String getVersion() {
153: return "1.0";
154: }
155:
156: /**
157: * Build and return an IRequirementSource.
158: *
159: * @param pAddInDescriptor Descriptor, from Registry, contains ProgID and Friendly
160: * Name to be put into IRequirementSource and .etd file.
161: * @return Addr of IRequirementSource ptr.
162: */
163: public IRequirementSource displaySources( /*IAddInDescriptor pAddInDescriptor*/)
164: throws RequirementsException
165:
166: {
167: IRequirementSource retVal = null;
168:
169: // We support doors only on windows. Display a popup and return.
170: if (!java.io.File.separator.equals("\\")) {
171: IErrorDialog errDialog = UIFactory.createErrorDialog();
172: errDialog.display(NbBundle.getMessage(
173: DoorsReqProvider.class, "IDS_OSNOTSUPPORTED"), "");
174: throw new RequirementsException(NbBundle.getMessage(
175: DoorsReqProvider.class, "IDS_OSNOTSUPPORTED"));
176: }
177:
178: // if( null == pAddInDescriptor)
179: // {
180: // throw new IllegalArgumentException();
181: // }
182:
183: retVal = new RequirementSource();
184:
185: IProxyUserInterface ui = ProductHelper.getProxyUserInterface();
186: Frame parent = null;
187: if (ui != null) {
188: parent = ui.getWindowHandle();
189: }
190: try {
191: String dlgTitle = NbBundle.getMessage(
192: DoorsReqProvider.class, "IDS_DOORS_DLG_TITLE");
193: DoorsProjectDialog doorsProjPanel = new DoorsProjectDialog();
194: if (!doorsProjPanel.hasError()) {
195: DialogDescriptor dialogDescriptor = new DialogDescriptor(
196: doorsProjPanel, dlgTitle);
197: Dialog dialog = DialogDisplayer.getDefault()
198: .createDialog(dialogDescriptor); // OK/CANCEL dialog
199: dialog.getAccessibleContext().setAccessibleDescription(
200: dlgTitle);
201: try {
202: dialog.setVisible(true);
203: Object bttnPressed = dialogDescriptor.getValue();
204: if (bttnPressed == DialogDescriptor.OK_OPTION) {
205: String doorsLocation = doorsProjPanel
206: .performAction(bttnPressed);
207: retVal.setLocation(doorsLocation);
208:
209: // Currently handling whether the Requirement source requires a login or not.
210: retVal.setRequiresLogin(false);
211:
212: // Set a unique ID for the requirement source. For Doors, project name is unique.
213: // Use the 'location' (name) field set in the dialog.
214: retVal.setID(retVal.getLocation());
215:
216: // pAddInDescriptor.getFriendlyName( &cbsFriendlyName )
217: String strFriendlyName = "DOORS - "
218: + retVal.getLocation();
219:
220: // Set the name displayed in the design center tree for the requirements source.
221: retVal.setDisplayName(strFriendlyName);
222:
223: // Set the prog Id for the requirement source provider.
224: //retVal.setProvider( pAddInDescriptor.getProgID());
225: retVal.setProvider(getProgID());
226: } else {
227: throw new RequirementsException(
228: RequirementsException.RP_E_NO_SELECTION,
229: NbBundle.getMessage(
230: DoorsReqProvider.class,
231: "IDS_NOSELECTION"));
232: }
233: } finally {
234: dialog.dispose();
235: }
236: }
237: // DoorsProjectDialog dpDialog = new DoorsProjectDialog(parent, true);
238: // dpDialog.setVisible(true);
239: //
240: // if( dpDialog.wasAccepted() == true )
241: // {
242: // retVal.setLocation( dpDialog.getDoorsLocation( ) );
243: //
244: // // Currently handling whether the Requirement source requires a login or not.
245: // retVal.setRequiresLogin( false );
246: //
247: // // Set a unique ID for the requirement source. For Doors, project name is unique.
248: // // Use the 'location' (name) field set in the dialog.
249: // retVal.setID( retVal.getLocation() );
250: //
251: // // pAddInDescriptor.getFriendlyName( &cbsFriendlyName )
252: // String strFriendlyName = "DOORS - " + retVal.getLocation();
253: //
254: // // Set the name displayed in the design center tree for the requirements source.
255: // retVal.setDisplayName( strFriendlyName );
256: //
257: // // Set the prog Id for the requirement source provider.
258: // //retVal.setProvider( pAddInDescriptor.getProgID());
259: // retVal.setProvider( getProgID());
260: // }
261: // else
262: // {
263: // throw new RequirementsException(RequirementsException.RP_E_NO_SELECTION,
264: // NbBundle.getMessage(DoorsReqProvider.class,"IDS_NOSELECTION"));
265: // }
266: } catch (UnsatisfiedLinkError ee) { //ee.printStackTrace();
267: String msg = NbBundle.getMessage(DoorsReqProvider.class,
268: "IDS_REQUIREMENTLIBRARYNOTFOUND");
269: NotifyDescriptor d = new NotifyDescriptor.Message(msg,
270: NotifyDescriptor.ERROR_MESSAGE);
271: DialogDisplayer.getDefault().notify(d);
272:
273: throw new RequirementsException(
274: RequirementsException.RP_E_REQUIREMENTLIBRARYNOTFOUND,
275: msg);
276: } catch (NoClassDefFoundError e) {
277: String msg = NbBundle.getMessage(DoorsReqProvider.class,
278: "IDS_REQUIREMENTLIBRARYNOTFOUND");
279: NotifyDescriptor d = new NotifyDescriptor.Message(msg,
280: NotifyDescriptor.ERROR_MESSAGE);
281: DialogDisplayer.getDefault().notify(d);
282:
283: throw new RequirementsException(
284: RequirementsException.RP_E_REQUIREMENTLIBRARYNOTFOUND,
285: msg);
286: }
287:
288: return retVal;
289: }
290:
291: // String getConfigScriptLocation() {
292: // Properties prop = System.getProperties();
293: // String value = prop.getProperty("netbeans.dirs");
294: // String [] clusterDirs = value.split(";");
295: // String dir = "";
296: // for (int i = 0; i < clusterDirs.length; i++) {
297: // dir = clusterDirs[i];
298: // if (dir != null && dir.indexOf("uml") != -1) {
299: // break;
300: // }
301: // }
302: // return dir;
303: // }
304: /**
305: * Given a RequirementSource, populate an IRequirements collection.
306: *
307: * @param IRequirementSource A RequirementSource that each derived provider should know
308: * how to handle.
309: * @retturn A collection of IRequirements.
310: */
311: public ETList<IRequirement> loadRequirements(
312: IRequirementSource pRequirementSource)
313: throws RequirementsException {
314: ETList<IRequirement> retVal = new ETArrayList<IRequirement>();
315:
316: if (null == pRequirementSource) {
317: throw new IllegalArgumentException();
318: }
319:
320: try {
321: if (m_bProviderAvailable == true) {
322: // Ask the RequirementsSource for its project.
323: String strReqFile = pRequirementSource.getLocation();
324:
325: // Call Doors object to execute DXL GetProjectXML2 function.
326: //DIDoorsDXLPtr pDoors( CLSID_DoorsDXL );
327:
328: String strRequest = "#include \"GetProjectInfo.dxl\";";
329: strRequest += "GetProjectXML2(\"";
330: strRequest += strReqFile;
331: strRequest += "\")";
332:
333: //pDoors.runStr( strRequest )
334: //String strResult = pDoors.getresult();
335: String strResult = DoorUtility
336: .sendRequestToDoors(strRequest);
337:
338: if (strResult.equals("ProjectNotFound") == true) {
339: throw new RequirementsException(
340: RequirementsException.RP_E_REQUIREMENTSOURCENOTFOUND,
341: NbBundle.getMessage(DoorsReqProvider.class,
342: "IDS_REQUIREMENTSOURCENOTFOUND"));
343: } else {
344: // Load the returned XML into a doc and send off to the ProcessChild to
345: // build a nested IRequirements structure.
346:
347: Document pDoc = XMLManip.loadXML(strResult);
348:
349: if (pDoc != null) {
350: String strPattern = "/RequirementsProject";
351: Node node = XMLManip.selectSingleNode(pDoc,
352: strPattern);
353:
354: if (node != null) {
355: retVal = RequirementUtility
356: .processChildElements(node,
357: DoorsRequirement.class,
358: null);
359: }
360: }
361: }
362: } else {
363: throw new RequirementsException(
364: RequirementsException.RP_E_REQUIREMENTSOURCENOTFOUND,
365: NbBundle.getMessage(DoorsReqProvider.class,
366: "IDS_REQUIREMENTSOURCENOTFOUND"));
367: }
368: } catch (RequirementsException e) {
369: Frame hwnd = null;
370: IProxyUserInterface cpProxyUserInterface = ProductHelper
371: .getProxyUserInterface();
372:
373: if (cpProxyUserInterface != null) {
374: hwnd = cpProxyUserInterface.getWindowHandle();
375: }
376:
377: String msgText = NbBundle.getMessage(
378: DoorsReqProvider.class,
379: "IDS_DOORSNOTAVAILABLEMESSAGE");
380: String msgTitle = NbBundle.getMessage(
381: DoorsReqProvider.class,
382: "IDS_DOORSNOTAVAILABLETITLE");
383:
384: IQuestionDialog cpQuestionDialog = UIFactory
385: .createQuestionDialog();
386:
387: cpQuestionDialog.displaySimpleQuestionDialog(
388: MessageDialogKindEnum.SQDK_OK,
389: MessageIconKindEnum.EDIK_ICONWARNING, msgText,
390: MessageResultKindEnum.SQDRK_RESULT_YES, hwnd,
391: msgTitle);
392: m_bProviderAvailable = false;
393: } catch (Exception e) {
394: e.printStackTrace();
395: }
396:
397: return retVal;
398: }
399:
400: /**
401: *
402: * Given a RequirementID, find the Requirement
403: *
404: * @param IRequirementArtifact Requirement Artifact
405: * @param IRequirementSource Requirement Source - not needed by this Provider derived type
406: * @return The requirement
407: */
408: public IRequirement getRequirement(
409: IRequirementArtifact pRequirementArtifact,
410: IRequirementSource pRequirementSource) {
411: IRequirement retVal = null;
412: if ((pRequirementArtifact == null)
413: || (pRequirementSource == null)) {
414: throw new IllegalArgumentException();
415: }
416:
417: try {
418: if (m_bProviderAvailable == true) {
419: //Ask the RequirementArtifact for its project and module.
420:
421: String strProjectName = pRequirementArtifact
422: .getRequirementProjectName();
423: String strModName = pRequirementArtifact
424: .getRequirementModName();
425: String strID = pRequirementArtifact.getRequirementID();
426:
427: // String strResult;
428: //
429: // DIDoorsDXLPtr pDoors( CLSID_DoorsDXL );
430:
431: // Call Doors object to execute DXL GetObjectByIDAsXML function.
432:
433: String strRequest = "#include \"GetProjectInfo.dxl\";";
434: strRequest += "getObjectByIDAsXML2(\"";
435: strRequest += strProjectName;
436: strRequest += "\", \"";
437: strRequest += strModName;
438: strRequest += "\", ";
439: strRequest += strID;
440: strRequest += ")";
441:
442: // pDoors.runStr( strRequest )
443: // strResult = pDoors.getresult();
444: String strResult = DoorUtility
445: .sendRequestToDoors(strRequest);
446:
447: // Load the returned XML into a doc and send off to the ProcessChild to
448: // build a nested IRequirements structure.
449: Document pDoc = XMLManip.loadXML(strResult);
450:
451: if (pDoc != null) {
452: String strPattern = "/RequirementsProject";
453: Node node = XMLManip.selectSingleNode(pDoc,
454: strPattern);
455:
456: if (node != null) {
457: // There should a <RequirementsProject> container node and one <Requirement> child node.
458: ETList<IRequirement> cpRequirements = RequirementUtility
459: .processChildElements(node,
460: DoorsRequirement.class, null);
461:
462: if (cpRequirements != null) {
463: // One and Only.
464: if (cpRequirements.size() > 0) {
465: retVal = cpRequirements.get(0);
466: }
467: }
468: }
469: }
470: }
471: } catch (Exception e) {
472: Frame hwnd = null;
473: IProxyUserInterface cpProxyUserInterface = ProductHelper
474: .getProxyUserInterface();
475:
476: if (cpProxyUserInterface != null) {
477: hwnd = cpProxyUserInterface.getWindowHandle();
478: }
479:
480: String msgText = NbBundle.getMessage(
481: DoorsReqProvider.class,
482: "IDS_DOORSNOTAVAILABLEMESSAGE");
483: String msgTitle = NbBundle.getMessage(
484: DoorsReqProvider.class,
485: "IDS_DOORSNOTAVAILABLETITLE");
486:
487: IQuestionDialog cpQuestionDialog = UIFactory
488: .createQuestionDialog();
489: cpQuestionDialog.displaySimpleQuestionDialog(
490: MessageDialogKindEnum.SQDK_OK,
491: MessageIconKindEnum.EDIK_ICONWARNING, msgText,
492: MessageResultKindEnum.SQDRK_RESULT_YES, hwnd,
493: msgTitle);
494: m_bProviderAvailable = false;
495: }
496: return retVal;
497: }
498:
499: /** save the design center addin */
500: public void save() {
501: // There is nothing to save.
502: }
503: }
|