0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: /*
0043: * ADRequirementsManager.java
0044: *
0045: * Created on June 24, 2004, 5:01 PM
0046: */
0047:
0048: package org.netbeans.modules.uml.requirements;
0049:
0050: import org.netbeans.modules.uml.core.IApplication;
0051: import org.netbeans.modules.uml.core.coreapplication.IDesignCenterSupport;
0052: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0053: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0054: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
0055: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
0056: import org.netbeans.modules.uml.core.metamodel.core.foundation.TypedFactoryRetriever;
0057: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0058: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0059: import org.netbeans.modules.uml.core.metamodel.structure.IRequirementArtifact;
0060: import org.netbeans.modules.uml.core.requirementsframework.IReqProviderDialog;
0061: import org.netbeans.modules.uml.core.requirementsframework.IRequirement;
0062: import org.netbeans.modules.uml.core.requirementsframework.IRequirementSource;
0063: import org.netbeans.modules.uml.core.requirementsframework.IRequirementsProvider;
0064: import org.netbeans.modules.uml.core.requirementsframework.ISatisfier;
0065: import org.netbeans.modules.uml.core.requirementsframework.ReqProviderDialog;
0066: import org.netbeans.modules.uml.core.requirementsframework.RequirementsException;
0067: import org.netbeans.modules.uml.core.requirementsframework.RequirementsManager;
0068: import org.netbeans.modules.uml.core.support.umlmessagingcore.UMLMessagingHelper;
0069: import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
0070: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
0071: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0072: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0073: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
0074: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
0075: import org.netbeans.modules.uml.ui.products.ad.application.ApplicationView;
0076: import org.netbeans.modules.uml.ui.support.DispatchHelper;
0077: import org.netbeans.modules.uml.ui.support.ElementReloader;
0078: import org.netbeans.modules.uml.ui.support.ProductHelper;
0079: import org.netbeans.modules.uml.ui.support.UIFactory;
0080: import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
0081: import org.netbeans.modules.uml.ui.support.commondialogs.IQuestionDialog;
0082: import org.netbeans.modules.uml.ui.support.commondialogs.MessageDialogKindEnum;
0083: import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
0084: import org.netbeans.modules.uml.ui.support.commondialogs.MessageResultKindEnum;
0085: import org.netbeans.modules.uml.ui.support.commonresources.CommonResourceManager;
0086: import org.netbeans.modules.uml.ui.support.commonresources.ICommonResourceManager;
0087: import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu;
0088: import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuItem;
0089: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaDropContext;
0090: import org.netbeans.modules.uml.designpattern.IActionProvider;
0091: import org.netbeans.modules.uml.designpattern.IDesignCenterSupportGUI;
0092: import java.awt.Frame;
0093: import java.awt.event.ActionEvent;
0094: import java.io.File;
0095: import java.util.HashMap;
0096: import java.util.Iterator;
0097: import java.util.List;
0098: import javax.swing.Action;
0099: import org.dom4j.Document;
0100: import org.dom4j.Element;
0101: import org.dom4j.IDResolver;
0102: import org.dom4j.Node;
0103: import org.openide.util.NbBundle;
0104:
0105: /**
0106: *
0107: * @author Trey Spiva
0108: */
0109: public class ADRequirementsManager extends RequirementsManager
0110: //implements IDesignCenterSupport, IDesignCenterSupportGUI, IViewActionDelegate, IActionProvider
0111: implements IDesignCenterSupport, IDesignCenterSupportGUI,
0112: IActionProvider {
0113: public static int sortPriority = 0;
0114:
0115: private ETList<IRequirementsProvider> m_ReqProviderAddIns = null;
0116:
0117: private HashMap<String, IRequirementsProvider> m_ProviderMap = new HashMap<String, IRequirementsProvider>();
0118:
0119: private HashMap<String, ETList<IRequirementSource>> m_RequirementSourcesMap = new HashMap<String, ETList<IRequirementSource>>();
0120:
0121: // Use this guy to get icons
0122: private ICommonResourceManager m_ResourceMgr;
0123:
0124: // The version of this addin
0125: private long m_Version = 0;
0126:
0127: private static IProjectTreeControl m_ProjectTree = null;
0128:
0129: private IProjectTreeItem m_ReqManagerTreeItem = null;
0130:
0131: // The config directory
0132: private String m_ConfigLoc = "";
0133:
0134: // The file that houses the design pattern projects to load in the design center
0135: private String m_File = "";
0136:
0137: // Addin's name
0138: private String m_FriendlyName;
0139:
0140: // The event handler for the Requirements Manager.
0141: private static ReqEventsSink m_EventsSink = null;
0142:
0143: // The cookies associated with advising for the above sinks
0144: private long m_DrawingAreaEventsCookie = 0;
0145: private long m_CoreProductInitEventsCookie = 0;
0146: private long m_ProjectTreeEventsCookie = 0;
0147:
0148: private static String m_Location = "";
0149: private static ADRequirementsManager m_RequirementsManager = null;
0150:
0151: // static
0152: // {
0153: // String configLoc = ProductHelper.getConfigManager().getDefaultConfigLocation();
0154: // m_Location = configLoc + "..";
0155: // m_Location += File.separatorChar + "Addins";
0156: // m_Location += File.separatorChar + "DesignCenter";
0157: // m_Location += File.separatorChar + "org.netbeans.modules.uml.ui.products.ad.requirements";
0158: // }
0159:
0160: /** Creates a new instance of ADRequirementsManager */
0161: public ADRequirementsManager() {
0162: initialize();
0163: }
0164:
0165: ////////////////////////////////////////////////////////////////////////////
0166: // IAddin Methods
0167:
0168: public long initialize(Object context) {
0169:
0170: initialize();
0171: return 0;
0172: }
0173:
0174: public static ADRequirementsManager instance() {
0175: return m_RequirementsManager;
0176: }
0177:
0178: public void initialize() {
0179: super .initialize();
0180: m_ResourceMgr = CommonResourceManager.instance();
0181:
0182: if (m_RequirementsManager == null) {
0183: m_RequirementsManager = this ;
0184: }
0185:
0186: createEventsSink();
0187: }
0188:
0189: public long deInitialize(Object context) {
0190: DispatchHelper helper = new DispatchHelper();
0191: helper.revokeDrawingAreaSink(m_EventsSink);
0192: helper.revokeInitSink(m_EventsSink);
0193: helper.revokeProjectTreeSink(m_EventsSink);
0194: m_EventsSink = null;
0195: setProjectTree(null);
0196:
0197: return 0;
0198: }
0199:
0200: public long unLoad(Object context) {
0201: return 0;
0202: }
0203:
0204: public String getID() {
0205: return "org.netbeans.modules.uml.ui.products.ad.requirements.ADRequirementsManager";
0206: }
0207:
0208: public String getVersion() {
0209: return Long.toString(m_Version);
0210: }
0211:
0212: public String getLocation() {
0213: return m_Location;
0214: }
0215:
0216: public String getName() {
0217: return NbBundle.getMessage(ADRequirementsManager.class,
0218: "REQUIREMENTS_MANAGER_NAME");
0219: }
0220:
0221: ////////////////////////////////////////////////////////////////////////////
0222: // IDesignCenterSupport Methods
0223:
0224: /** save the design center addin */
0225: public void save() {
0226: // There is nothing to save.
0227: }
0228:
0229: ////////////////////////////////////////////////////////////////////////////
0230: // IDesignCenterSupportGUI Methods
0231:
0232: /**
0233: * Get the top level of the project tree for this addin.
0234: *
0235: * @retun The project tree
0236: */
0237: public IProjectTreeControl getProjectTree() {
0238: IProjectTreeControl retVal = null;
0239: if ((m_RequirementsManager != null)
0240: && (m_RequirementsManager != this )) {
0241: retVal = m_RequirementsManager.getProjectTree();
0242: } else {
0243: retVal = m_ProjectTree;
0244: }
0245: return retVal;
0246: }
0247:
0248: /**
0249: * Set the top level of the project tree into this addin.
0250: *
0251: * @param newVal The new project tree
0252: */
0253: public void setProjectTree(IProjectTreeControl newVal) {
0254: if ((m_RequirementsManager != null)
0255: && (m_RequirementsManager != this )) {
0256: m_RequirementsManager.setProjectTree(newVal);
0257: } else {
0258: m_ProjectTree = newVal;
0259: }
0260: }
0261:
0262: /**
0263: * Called upon a request to expand this addin's items in the tree.
0264: *
0265: * @param pParent The currently selected tree Item.
0266: */
0267: public void populateTreeItem(Object pParent) {
0268: if (pParent instanceof IProjectTreeItem) {
0269: // Save the tree item so that it will be available when the ProviderDialog
0270: // callback ADRequirementsManagerImpl::StoreAddIn(...) is called.
0271: m_RequirementsManager
0272: .setTreeItem((IProjectTreeItem) pParent);
0273:
0274: //m_ReqManagerTreeItem = (IProjectTreeItem)pParent;
0275:
0276: // Reset nSortPriority on Entry and on Refresh.
0277: sortPriority = 0;
0278:
0279: // If a RequirementSources.etd file exist, load the provider addins from
0280: // the .etd file.
0281: if (requirementSourcesExist() == true) {
0282: loadReqProviderAddins(m_RequirementsManager
0283: .getTreeItem());
0284: }
0285: //If the Requirements node has no children, the Requirements Provider dialog will no longer
0286: //be displayed.
0287: /*
0288: else
0289: {
0290: IReqProviderDialog dlg = new ReqProviderDialog();
0291:
0292: IProxyUserInterface ui = ProductHelper.getProxyUserInterface();
0293: dlg.display(ui.getWindowHandle(), this);
0294: }
0295: */
0296: } else // Logic for Populating RequirementsProvider tree items.
0297: {
0298:
0299: }
0300: }
0301:
0302: public IProjectTreeItem getTreeItem() {
0303: return m_ReqManagerTreeItem;
0304: }
0305:
0306: public void setTreeItem(IProjectTreeItem item) {
0307: m_ReqManagerTreeItem = item;
0308: }
0309:
0310: ////////////////////////////////////////////////////////////////////////////
0311: // Protected methods
0312:
0313: /**
0314: * Loads the Requirements Provider addins from the registry key.
0315: */
0316: protected void loadAddIns() {
0317: // If the addins collection is NULL then I know that we have not previously
0318: // loaded the addins. If the addins collection has been created but is
0319: // empty then we do not have any providers.
0320: if (m_ReqProviderAddIns == null) {
0321: m_ReqProviderAddIns = new ETArrayList<IRequirementsProvider>();
0322:
0323: IRequirementsProvider[] addins = getAddIns();
0324: // IAddInDescriptor[] descs = getAddInDescriptors();
0325: // for(int index = 0; index < descs.length; index++)
0326: for (IRequirementsProvider provider : addins) {
0327: // IAddInDescriptor desc = descs[index];
0328: // IAddIn addin = initializeAddIn(desc, null, false);
0329:
0330: // if(addin != null)
0331: {
0332: // if(addin instanceof IRequirementsProvider)
0333: {
0334: // IRequirementsProvider reqProvider = (IRequirementsProvider)addin;
0335: String progID = provider.getProgID();
0336:
0337: // reqProvider.setProgID(progID);
0338: m_ProviderMap.put(progID, provider);
0339: }
0340: }
0341: }
0342: }
0343: }
0344:
0345: /**
0346: * Creates the event sinks for the Requirements Manager. For example it sets
0347: * up the IDrawingAreaEventsSink to facilitate drag/drop of requirements onto
0348: * the drawing area.
0349: */
0350: protected void createEventsSink() {
0351: if (m_EventsSink == null) {
0352: m_EventsSink = new ReqEventsSink(m_RequirementsManager);
0353:
0354: DispatchHelper helper = new DispatchHelper();
0355: helper.registerDrawingAreaEvents(m_EventsSink);
0356: helper.registerForInitEvents(m_EventsSink);
0357: helper.registerProjectTreeEvents(m_EventsSink);
0358: }
0359: }
0360:
0361: /**
0362: * Open the Requirement Sources file and load the Requirement Provider addins
0363: * that it specifies.
0364: *
0365: * @param treeItem The currently selected tree Item, parent of added
0366: * requirements providers.
0367: */
0368: protected void loadReqProviderAddins(IProjectTreeItem treeItem) {
0369: if (m_ReqSourcesFile.length() > 0) {
0370: // Load the RequirementSources.etd file into the DOM:its elements
0371: // will be used to create an addin for each Requirements provider.
0372: Document reqSorucesDoc = XMLManip.getDOMDocument(
0373: m_ReqSourcesFile, new IDResolver("id"));
0374:
0375: if (reqSorucesDoc != null) {
0376: List nodes = XMLManip.selectNodeList(reqSorucesDoc,
0377: "/RequirementSources/RequirementSource");
0378: if ((nodes != null) && (nodes.size() > 0)) {
0379: for (int index = 0; index < nodes.size(); index++) {
0380: Node reqSourceNode = (Node) nodes.get(index);
0381: if (reqSourceNode != null) {
0382: if (reqSourceNode instanceof Element) {
0383: Element reqSourceElem = (Element) reqSourceNode;
0384: IRequirementSource reqSource = new org.netbeans.modules.uml.core.requirementsframework.RequirementSource();
0385: convertXMLElementToReqSource(
0386: reqSourceElem, reqSource);
0387:
0388: if (reqSource != null) {
0389: loadReqProviderAddin(treeItem,
0390: reqSource);
0391: }
0392: }
0393: }
0394: }
0395: }
0396:
0397: }
0398: }
0399: }
0400:
0401: /**
0402: * Loads the Requirements Provider AddIn Source instance defined in the XML
0403: * <RequirementSource> element. The element is obtained from the
0404: * RequirementSources.etd file. Then, add the top-level contents of the
0405: * Requirements Source to the tree. Note: if content loading fails, the catch
0406: * logic will remove the Source's Tree Item from the tree.
0407: *
0408: * @param treeItem The currently selected tree Item, parent of new
0409: * requirement provider.
0410: * @param requirementSource The requirement source that represents a
0411: * requirements provider addin
0412: */
0413: protected void loadReqProviderAddin(IProjectTreeItem treeItem,
0414: IRequirementSource requirementSource) {
0415: IProjectTreeItem newItem = null;
0416: if ((treeItem != null) && (requirementSource != null)) {
0417: try {
0418: String progID = requirementSource.getProvider();
0419: IRequirementsProvider addin = getRequirementsProvider(progID);
0420:
0421: if (addin != null) {
0422: // Add a sub-item to the tree for this Requirements Source.
0423: newItem = loadTreeItem(treeItem, requirementSource);
0424: newItem.setAsAddinNode(true);
0425:
0426: // Add the requirement source to the list of RequirementSources
0427: // managed by this addin.
0428: addRequirementSourceContents(addin, newItem,
0429: requirementSource);
0430: }
0431: } catch (RequirementsException e) {
0432: if (e.getExceptionCode() == RequirementsException.RP_E_REQUIREMENTSOURCENOTFOUND) {
0433: Frame handle = null;
0434:
0435: IProxyUserInterface proxyUserInterface = ProductHelper
0436: .getProxyUserInterface();
0437: if (proxyUserInterface != null) {
0438: handle = proxyUserInterface.getWindowHandle();
0439: }
0440:
0441: String displayName = requirementSource
0442: .getDisplayName();
0443: String msg = NbBundle.getMessage(
0444: ADRequirementsManager.class,
0445: "IDS_REQUIREMENTSOURCENOTFOUND",
0446: displayName);
0447: String msgTitle = NbBundle.getMessage(
0448: ADRequirementsManager.class,
0449: "IDS_REQUIREMENTSOURCENOTFOUNDTITLE");
0450:
0451: IQuestionDialog question = UIFactory
0452: .createQuestionDialog();
0453: question.displaySimpleQuestionDialog(
0454: MessageDialogKindEnum.SQDK_OK,
0455: MessageIconKindEnum.EDIK_ICONWARNING, msg,
0456: MessageResultKindEnum.SQDRK_RESULT_YES,
0457: handle, msgTitle);
0458: }
0459:
0460: if (newItem != null) {
0461: IProjectTreeItem[] pRemovedItems = { newItem };
0462:
0463: IProjectTreeControl ctrl = getProjectTree();
0464: if (ctrl != null) {
0465: ctrl.removeFromTree(pRemovedItems);
0466: }
0467: }
0468: }
0469: }
0470: }
0471:
0472: ///////////////////////////////////////////////////////////////////////////////
0473: ///////////////////////////////////////////////////////////////////////////////
0474: ///////////////////////////////////////////////////////////////////////////////
0475: ///////////////////////////////////////////////////////////////////////////////
0476: ///////////////////////////////////////////////////////////////////////////////
0477: ///////////////////////////////////////////////////////////////////////////////
0478:
0479: /**
0480: *
0481: * Creates a sub-tree item for the passed in requirements source.
0482: *
0483: * @param *pTree[in] The parent tree item for new requirement provider Addin.
0484: * @param *pRequirementSource[in] Represents a requirements provider addin
0485: *
0486: * @return void
0487: *
0488: */
0489:
0490: public IProjectTreeItem loadTreeItem(IProjectTreeItem pTreeItem,
0491: IRequirementSource pRequirementSource) {
0492: IProjectTreeItem retVal = null;
0493:
0494: if ((null == pTreeItem) || (pRequirementSource == null)) {
0495: throw new IllegalArgumentException();
0496: }
0497:
0498: String strDispName = "";
0499: String strProgId = "";
0500:
0501: IProjectTreeControl ctrl = getProjectTree();
0502: if (ctrl != null) {
0503: strDispName = pRequirementSource.getDisplayName();
0504: strProgId = pRequirementSource.getProvider();
0505:
0506: //Action[] actions = {new AddSourceAction()};
0507: retVal = ctrl.addItem(pTreeItem, // Parent tree item
0508: "ReqProject", // Program Name
0509: strDispName, // displayed (new) tree item name
0510: 1, // Sort Priority
0511: null, // IElement* this tree item is
0512: strProgId); // Description not used for Req Mgr.
0513: //retVal.setActions(actions);
0514:
0515: if (retVal != null) {
0516: // TODO: Figure out what to do about the setDispatch.
0517: ctrl.setDispatch(retVal, pRequirementSource);
0518: ctrl.setSecondaryDescription(retVal, strProgId);
0519: setImage(retVal, "ReqProject");
0520: }
0521: }
0522:
0523: return retVal;
0524: }
0525:
0526: /**
0527: * Implements the IActionProvider interface.
0528: */
0529: public Action[] getActions() {
0530: Action[] actions = { new AddSourceAction() };
0531: return actions;
0532: }
0533:
0534: /**
0535: *
0536: * Determines if the RequirementsSouces.etd file exists,
0537: *
0538: * @return boolean Returns true if the file exists.
0539: *
0540: */
0541: public boolean requirementSourcesExist() {
0542: boolean bRtn = false;
0543:
0544: m_ReqSourcesFile = getReqSourcesFile();
0545: if (m_ReqSourcesFile.length() > 0) {
0546: bRtn = new File(m_ReqSourcesFile).exists();
0547: }
0548: return bRtn;
0549: }
0550:
0551: /**
0552: *
0553: * Callback from IReqProviderDialog, when the "Display Souces" button is pressed
0554: * on the Requirements Provider Dialog. The ReqProviderDialogImpl is in
0555: * the RequirementsFramework project. See PopulateTreeItem
0556: * for how the dialog is created and this requirements manager is set to
0557: * recieve callbacks from the dialog.
0558: *
0559: * @param desc[in] Descriptor for the addin selected in the Requirements Provider dialog.
0560: *
0561: * @return void
0562: *
0563: void storeAddIn( IAddInDescriptor* desc )
0564: {
0565: void hr = S_OK;
0566:
0567: return hr;
0568: }
0569: */
0570:
0571: /**
0572: *
0573: * Adds the Source Provider entry to the etd and to the tree.
0574: * requirements provider addin that manages it.
0575: *
0576: * @param *pReqSource[in] Represents a requirements provider addin
0577: *
0578: * @return void
0579: *
0580: */
0581: public void processSource(IRequirementSource pRequirementSource)
0582: throws RequirementsException {
0583: try {
0584: super .processSource(pRequirementSource);
0585:
0586: // Add a tree sub-element for this req source and put the requirements
0587: // source under management of the requirements source provider addin.
0588: if (m_RequirementsManager.getTreeItem() != null) {
0589: // TODO: Expand to Provider Description Node.
0590: loadReqProviderAddin(m_RequirementsManager
0591: .getTreeItem(), pRequirementSource);
0592: }
0593:
0594: } catch (RequirementsException e) {
0595: if (e.getExceptionCode() == RequirementsException.RP_E_DUPLICATESOURCE) {
0596: String msgText = NbBundle.getMessage(
0597: ADRequirementsManager.class,
0598: "IDS_DUPSOURCEMESSAGE");
0599: String msgTitle = NbBundle.getMessage(
0600: ADRequirementsManager.class,
0601: "IDS_DUPSOURCETITLE");
0602:
0603: Frame handle = ProductHelper.getProxyUserInterface()
0604: .getWindowHandle();
0605: IQuestionDialog question = UIFactory
0606: .createQuestionDialog();
0607: question.displaySimpleQuestionDialog(
0608: MessageDialogKindEnum.SQDK_OK,
0609: MessageIconKindEnum.EDIK_ICONEXCLAMATION,
0610: msgText, MessageResultKindEnum.SQDRK_RESULT_OK,
0611: handle, msgTitle);
0612: }
0613: throw e;
0614: }
0615: }
0616:
0617: /**
0618: * Message from the sink that something has been selected
0619: */
0620: public void handleSelection(IProductContextMenu pContextMenu,
0621: IProductContextMenuItem pSelectedItem) {
0622: if (null == pContextMenu && pSelectedItem == null) {
0623: throw new IllegalArgumentException();
0624: }
0625:
0626: try {
0627: if (pContextMenu != null) {
0628: Object pDisp = pContextMenu.getParentControl();
0629:
0630: if (pDisp instanceof IProjectTreeControl) {
0631: IProjectTreeControl pTreeControl = (IProjectTreeControl) pDisp;
0632: IProjectTreeItem[] projectTreeItems = pTreeControl
0633: .getSelected();
0634:
0635: ETList<IProjectTreeItem> projectTreeItems2 = new ETArrayList<IProjectTreeItem>();
0636:
0637: String strButtonSource = pSelectedItem
0638: .getButtonSource();
0639:
0640: if (strButtonSource.equals("MBK_REMOVE_SATISFIER")) {
0641: if (projectTreeItems.length > 0) {
0642: String strNodeName;
0643: String strParentNodeName;
0644:
0645: for (int lIdx = 0; lIdx < projectTreeItems.length; lIdx++) {
0646: // Get the Next Selected item.
0647: IProjectTreeItem projectTreeItem = projectTreeItems[lIdx];
0648:
0649: // Also get its Parent.
0650: IProjectTreeItem parentProjectTreeItem = pTreeControl
0651: .getParent(projectTreeItem);
0652:
0653: // Retrieve Names of Selected Node and its Parent.
0654: strParentNodeName = parentProjectTreeItem
0655: .getItemText();
0656: strNodeName = projectTreeItem
0657: .getItemText();
0658:
0659: // Filter out only 'Satisfiers' (happens when a multi-range selection is made from tree).
0660: if (strNodeName.equals(" Satisfiers")
0661: || strParentNodeName
0662: .equals(" Satisfiers")) {
0663: // Add elements to a second collection to be deleted later.
0664: // projectTreeItems2.add( projectTreeItem )
0665:
0666: if (strParentNodeName
0667: .equals(" Satisfiers")) {
0668:
0669: removeItemFromProxy(
0670: pTreeControl,
0671: projectTreeItem,
0672: parentProjectTreeItem);
0673:
0674: // Add elements to a second collection to be deleted later.
0675: projectTreeItems2
0676: .add(projectTreeItem);
0677: } else if (strNodeName
0678: .equals(" Satisfiers")) {
0679: // Remove all of the Children.
0680: ETList<IProjectTreeItem> childProjectTreeItems = pTreeControl
0681: .getChildren(projectTreeItem);
0682: long lChildCount = childProjectTreeItems
0683: .size();
0684:
0685: // Iterate through all the children.
0686: for (int childIndex = 0; childIndex < lChildCount; childIndex++) {
0687: IProjectTreeItem childProjectTreeItem = childProjectTreeItems
0688: .get(childIndex);
0689:
0690: // Delete the child from the Proxy file.
0691: removeItemFromProxy(
0692: pTreeControl,
0693: childProjectTreeItem,
0694: projectTreeItem);
0695:
0696: // Add elements to a second collection to be deleted later.
0697: projectTreeItems2
0698: .add(projectTreeItem);
0699: } // End For..Loop
0700: } // EndElse - Node is a Satisfiers folder
0701: } // EndIf - Node is a satisfier(s} folder
0702:
0703: } // EndIf - TreeItem selectedItems > 0
0704:
0705: // Delete the items from the second 'filtered' collection.
0706:
0707: if (projectTreeItems2.size() > 0) {
0708: IProjectTreeItem[] removeItems = new IProjectTreeItem[projectTreeItems2
0709: .size()];
0710: projectTreeItems2.toArray(removeItems);
0711: pTreeControl
0712: .removeFromTree(removeItems);
0713: }
0714: }
0715:
0716: } else if (strButtonSource
0717: .equals("MBK_ADD_REQUIREMENT_SOURCE")) {
0718: // Display the Requirement Providers dialog.
0719: IReqProviderDialog pDlg = new ReqProviderDialog();
0720: pDlg.display(null, this );
0721:
0722: } // End Switch
0723: }
0724: }
0725: } catch (RequirementsException e) {
0726: UMLMessagingHelper helper = new UMLMessagingHelper();
0727: helper.sendExceptionMessage(e);
0728: }
0729: }
0730:
0731: /**
0732: * Removes the Satisfer element from the Requirements Provider and also from
0733: * the Proxy file.
0734: *
0735: * @param pTreeControl [in] The DesignCenter's TreeControl
0736: * @param pProjectTreeItem [in] The Satisfier node
0737: * @param pParentProjectTreeItem [in] The 'Satisfiers Folder' node.
0738: */
0739: public void removeItemFromProxy(IProjectTreeControl pTreeControl,
0740: IProjectTreeItem pProjectTreeItem,
0741: IProjectTreeItem pParentProjectTreeItem)
0742: throws RequirementsException {
0743: if (null == pTreeControl || pProjectTreeItem == null
0744: || pParentProjectTreeItem == null) {
0745: throw new IllegalArgumentException();
0746: }
0747:
0748: try {
0749: // Satisfiers Folder node's parent is the Requirement.
0750: IProjectTreeItem cpRequirementParentProjectTreeItem = pTreeControl
0751: .getParent(pParentProjectTreeItem);
0752:
0753: IRequirement cpRequirement = getRequirementFromTreeItem(cpRequirementParentProjectTreeItem);
0754:
0755: String strSatisfierXMIID = pProjectTreeItem
0756: .getSecondaryDescription();
0757:
0758: ETList<ISatisfier> cpSatisfiers = cpRequirement
0759: .getSatisfiers();
0760:
0761: long lSatisfierCount = cpSatisfiers.size();
0762:
0763: for (int lIdx = 0; lIdx < lSatisfierCount; lIdx++) {
0764: ISatisfier cpSatisfier = cpSatisfiers.get(lIdx);
0765:
0766: String strSatisfierID = cpSatisfier.getXMIID();
0767: if (strSatisfierID.equals(strSatisfierXMIID) == true) {
0768: // Delete from IRequirement's collection.
0769: cpRequirement.removeSatisfier(cpSatisfier);
0770:
0771: // Delete from the Proxy File
0772: deleteProxy(cpRequirement, cpSatisfier);
0773:
0774: // Now remove the Requirement Artifact from the owning element.
0775:
0776: // Get the Element's ProjectID.
0777: String strProjectID = cpSatisfier.getProjectID();
0778: String strProjectName = cpSatisfier
0779: .getProjectName();
0780:
0781: // Get the current Application so we can ask it things.
0782: IApplication cpApplication = ProductHelper
0783: .getApplication();
0784:
0785: // Ask the App for the ProjectInstance using the element's toplevelid.
0786: IProject cpProject = cpApplication
0787: .getProjectByID(strProjectID);
0788:
0789: ElementReloader reloader = new ElementReloader();
0790: IElement pElement = reloader.getElement(
0791: strProjectID, strSatisfierID);
0792: if (pElement instanceof INamespace) {
0793: INamespace cpNamespace = (INamespace) pElement;
0794: if (cpNamespace != null) {
0795: ETList<INamedElement> cpNamedElements = cpNamespace
0796: .getOwnedElements();
0797:
0798: if ((cpNamedElements != null)
0799: && (cpNamedElements.size() > 0)) {
0800: long lCnt = cpNamedElements.size();
0801:
0802: String strRequirementID = cpRequirement
0803: .getID();
0804: String strRequirementSourceID = cpRequirement
0805: .getSourceID();
0806:
0807: for (int lIndx = 0; lIndx < lCnt; lIndx++) {
0808: INamedElement cpNamedElement = cpNamedElements
0809: .get(lIndx);
0810: if (cpNamedElement instanceof IRequirementArtifact) {
0811: IRequirementArtifact cpArtifact = (IRequirementArtifact) cpNamedElement;
0812: String strArtifactRequirementID = cpArtifact
0813: .getRequirementID();
0814:
0815: String strArtifactRequirementSourceID = cpArtifact
0816: .getRequirementSourceID();
0817:
0818: if ((strRequirementID
0819: .equals(strArtifactRequirementID) == true)
0820: && (strRequirementSourceID
0821: .equals(strArtifactRequirementSourceID) == true)) {
0822: cpArtifact.delete();
0823: break;
0824: }
0825: }
0826: }
0827: }
0828: }
0829: }
0830: break;
0831: }
0832: }
0833: } catch (RequirementsException err) {
0834: if (err.getExceptionCode() == RequirementsException.RP_E_SHAREDEDITNOTSUPPORTED) {
0835: Frame handle = null;
0836:
0837: IProxyUserInterface cpProxyUserInterface = ProductHelper
0838: .getProxyUserInterface();
0839: if (cpProxyUserInterface != null) {
0840: handle = cpProxyUserInterface.getWindowHandle();
0841: }
0842:
0843: String msgText = err.getLocalizedMessage();
0844: String msgTitle = NbBundle.getMessage(
0845: ADRequirementsManager.class,
0846: "IDS_REQUIRENTERRORTITLE");
0847:
0848: IQuestionDialog question = UIFactory
0849: .createQuestionDialog();
0850: question.displaySimpleQuestionDialog(
0851: MessageDialogKindEnum.SQDK_OK,
0852: MessageIconKindEnum.EDIK_ICONWARNING, msgText,
0853: MessageResultKindEnum.SQDRK_RESULT_OK, handle,
0854: msgTitle);
0855: }
0856: }
0857: }
0858:
0859: /////////////////////////////////////////////////////////////////////////////////////
0860: // IProjectTreeEventsSink
0861:
0862: /**
0863: * Forwarded msg from EventSink when user clicks on a TreeItem with an embedded
0864: * Requirement.
0865: */
0866:
0867: public void onItemExpanding(IProjectTreeItem pProjectTreeItem,
0868: IRequirement pRequirement) {
0869: if ((null == pProjectTreeItem) || (pRequirement == null)) {
0870: throw new IllegalArgumentException();
0871: }
0872:
0873: try {
0874: String strProviderID = pRequirement.getProviderID();
0875: String strSourceID = pRequirement.getSourceID();
0876:
0877: IRequirementSource cpRequirementSource = getSource(strSourceID);
0878:
0879: if (cpRequirementSource != null) {
0880: ETList<IRequirement> cpRequirements = pRequirement
0881: .getSubRequirements(cpRequirementSource);
0882:
0883: if (cpRequirements != null) {
0884: loadTreeItems(pProjectTreeItem, strProviderID,
0885: strSourceID, cpRequirements);
0886: }
0887:
0888: // Create a child TreeItem under the TreeItem for each Satisfier.
0889: ETList<ISatisfier> cpSatisfiers = pRequirement
0890: .getSatisfiers();
0891:
0892: if (cpSatisfiers != null) {
0893: long lSatisfierCount = cpSatisfiers.size();
0894:
0895: // Iterate through the Sources.
0896: for (int lIdx = 0; lIdx < lSatisfierCount; lIdx++) {
0897: ISatisfier cpSatisfier = cpSatisfiers.get(lIdx);
0898:
0899: IProjectTreeItem cpNewSatisfierTreeItem = loadTreeItem(
0900: pProjectTreeItem, cpSatisfier);
0901: }
0902: }
0903:
0904: }
0905: } catch (RequirementsException e) {
0906: UMLMessagingHelper helper = new UMLMessagingHelper();
0907: helper.sendExceptionMessage(e);
0908: }
0909: }
0910:
0911: /**
0912: *
0913: * Add the passed in Requirements Source to the map of RequirementSources managed
0914: * by the Provider..
0915: *
0916: * @param pAddin[in] Requirments Provider addin to add the Requirement Source to.
0917: * @param pReqSouce[in] Requirements source to add to the addin.
0918: *
0919: */
0920: public void addRequirementSourceContents(
0921: IRequirementsProvider cpRequirementsProvider,
0922: IProjectTreeItem pTreeItem,
0923: IRequirementSource pRequirementSource)
0924: throws RequirementsException {
0925: if (null == cpRequirementsProvider
0926: || (pRequirementSource == null)) {
0927: throw new IllegalArgumentException();
0928: }
0929:
0930: try {
0931: // if( pAddIn instanceof IRequirementsProvider)
0932: {
0933: // IRequirementsProvider cpRequirementsProvider = (IRequirementsProvider)pAddIn;
0934:
0935: String strProgID = cpRequirementsProvider.getProgID();
0936: String strRequirementSourceID = pRequirementSource
0937: .getID();
0938:
0939: // Get the Requirements Provider's associated RequirementSources.
0940: ETList<IRequirementSource> cpRequirementSources = m_RequirementSourcesMap
0941: .get(strProgID);
0942:
0943: if (cpRequirementSources != null) {
0944: cpRequirementSources.add(pRequirementSource);
0945: } else {
0946: cpRequirementSources = new ETArrayList<IRequirementSource>();
0947: cpRequirementSources.add(pRequirementSource);
0948:
0949: m_RequirementSourcesMap.put(strProgID,
0950: cpRequirementSources);
0951: }
0952:
0953: // Provider will use info in RequirementSource to create an IRequirements collection.
0954: ETList<IRequirement> cpRequirements = cpRequirementsProvider
0955: .loadRequirements(pRequirementSource);
0956:
0957: if (cpRequirements != null) {
0958: loadTreeItems(pTreeItem, strProgID,
0959: strRequirementSourceID, cpRequirements);
0960: }
0961:
0962: }
0963: } catch (RequirementsException err) {
0964: // I do not want to do anything.
0965: }
0966: }
0967:
0968: /**
0969: * Recursively Load Requirements and their Requirements collections.
0970: *
0971: * @param pTreeItem[in] Starting TreeItem, item that received 'AddNode' event.
0972: * @param strProgID[in] ProgID extracted from the AddIn.
0973: * @param strRequirementSourceID [in] Requirements source ID from .etreq file
0974: * @param pRequirements[in] Requirements collection built by the Provider.
0975: *
0976: * @return void
0977: *
0978: */
0979: public void loadTreeItems(IProjectTreeItem pTreeItem,
0980: String strProgID, String strRequirementSourceID,
0981: ETList<IRequirement> pRequirements) {
0982: if ((null == pTreeItem) || (pRequirements == null)) {
0983: throw new IllegalArgumentException();
0984: }
0985:
0986: // Add all Requirements in the returned collection to the tree.
0987: // Iterate through the Requirements.
0988: Iterator<IRequirement> iter = pRequirements.iterator();
0989: while (iter.hasNext() == true) {
0990: IRequirement cpRequirement = iter.next();
0991: cpRequirement.setProviderID(strProgID);
0992: cpRequirement.setSourceID(strRequirementSourceID);
0993:
0994: // Create a TreeItem for each Requirement.
0995: IProjectTreeItem cpNewTreeItem = loadTreeItem(pTreeItem,
0996: cpRequirement);
0997:
0998: // Create a child TreeItem under the TreeItem for each SubRequirement.
0999: ETList<IRequirement> cpSubRequirements = cpRequirement
1000: .getRequirements();
1001:
1002: if (cpSubRequirements != null) {
1003: loadTreeItems(cpNewTreeItem, strProgID,
1004: strRequirementSourceID, cpSubRequirements);
1005: }
1006:
1007: // Create a child TreeItem under the TreeItem for each Satisfier.
1008: ETList<ISatisfier> cpSatisfiers = cpRequirement
1009: .getSatisfiers();
1010: if (cpSatisfiers != null) {
1011: // Iterate through the Sources.
1012: Iterator<ISatisfier> satisfierIter = cpSatisfiers
1013: .iterator();
1014: while (satisfierIter.hasNext() == true) {
1015: ISatisfier cpSatisfier = satisfierIter.next();
1016:
1017: IProjectTreeItem cpNewSatisfierTreeItem = loadTreeItem(
1018: cpNewTreeItem, cpSatisfier);
1019: }
1020: }
1021: }
1022: }
1023:
1024: /**
1025: *
1026: * Revokes event sinks that were registered for the ADRequirements addin.
1027: *
1028: * @return void
1029: *
1030: */
1031: public void disconnectEventSinks() {
1032: /*
1033: try
1034: {
1035: CDispatcherHelper oDispatcherHelper;
1036: oDispatcherHelper.revokeDrawingAreaSink( m_nDrawingAreaEventsCookie );
1037: oDispatcherHelper.revokeInitSink( m_nCoreProductInitEventsCookie );
1038: }
1039: catch( _com_error& err )
1040: {
1041: hr = COMErrorManager.reportError( err );
1042: }
1043: */
1044: }
1045:
1046: /**
1047: *
1048: * Handles the IDrawingAreaEventsSink OnDrawingAreaPreDrop event
1049: * for the ADRequirements Addin. This event is Fired right before
1050: * items are dropped onto the diagram.
1051: *
1052: * @param pParentDiagram[in] The diagram where the drop occured
1053: * @param pContext[in] Deatails of what has been dropped onto the diagram
1054: * @param cell[in] The result cell from the original event.
1055: *
1056: * @return void
1057: *
1058: */
1059: public void onDrawingAreaPreDrop(IDiagram pParentDiagram,
1060: IDrawingAreaDropContext pContext, IResultCell cell) {
1061: }
1062:
1063: /**
1064: *
1065: * Handles the IDrawingAreaEventsSink OnDrawingAreaPostDrop event
1066: * for the ADRequirements Addin. This event is Fired after items
1067: * are are dropped onto the diagram.
1068: *
1069: * @param pParentDiagram[in] The diagram where the drop occured
1070: * @param pContext[in] Deatails of what has been dropped onto the diagram
1071: * @param cell[in] The result cell from the original event.
1072: *
1073: * @return void
1074: *
1075: */
1076: public void onDrawingAreaPostDrop(IDiagram pParentDiagram,
1077: IDrawingAreaDropContext pContext, IResultCell cell) {
1078: if ((null == pParentDiagram) || (pContext == null)) {
1079: throw new IllegalArgumentException();
1080: }
1081:
1082: // The presentation element dropped upon, could be null.
1083: IPresentationElement cpPresElement = pContext.getPEDroppedOn();
1084:
1085: if (cpPresElement != null) {
1086: ETArrayList<IPresentationElement> satisfiers = new ETArrayList<IPresentationElement>(
1087: 1);
1088: satisfiers.add(cpPresElement);
1089:
1090: // Get the DesignCenter's TreeControl.
1091: IProjectTreeControl cpProjectTreeControl = ProductHelper
1092: .getDesignCenterTree();
1093:
1094: // Ask the TreeControl for its selected items.
1095: IProjectTreeItem[] projectTreeItems = cpProjectTreeControl
1096: .getSelected();
1097:
1098: ETArrayList<IProjectTreeItem> itemsList = new ETArrayList<IProjectTreeItem>(
1099: projectTreeItems.length);
1100:
1101: for (int lIdx = 0; lIdx < projectTreeItems.length; lIdx++) {
1102: IProjectTreeItem projectTreeItem = projectTreeItems[lIdx];
1103: if (projectTreeItem != null)
1104: itemsList.add(projectTreeItem);
1105: }
1106:
1107: addSatisfiers(satisfiers, itemsList);
1108:
1109: } // EndIf - We have been dropped on a Presentation Element
1110:
1111: }
1112:
1113: /**
1114: * Associates the satisfiers with the requirements
1115: *
1116: */
1117: public void addSatisfiers(List<IPresentationElement> satisfiers,
1118: List<IProjectTreeItem> projectTreeItems) {
1119:
1120: if (satisfiers == null || projectTreeItems == null) {
1121: return;
1122: }
1123:
1124: Iterator<IPresentationElement> iter = satisfiers.iterator();
1125: while (iter.hasNext()) {
1126: IPresentationElement cpPresElement = iter.next();
1127:
1128: if (cpPresElement != null) {
1129: // Ask the PresentationElement for its model element.
1130: IElement cpElement = cpPresElement.getFirstSubject();
1131:
1132: if (cpElement != null) {
1133: String strElementName = "";
1134: String strElementType = "";
1135: String strElementXMIID = "";
1136:
1137: if (cpElement instanceof INamedElement) {
1138: INamedElement cpNamedElement = (INamedElement) cpElement;
1139:
1140: strElementName = cpNamedElement.getName();
1141: strElementType = cpNamedElement
1142: .getElementType();
1143: strElementXMIID = cpNamedElement.getXMIID();
1144: if ((strElementName == null)
1145: || (strElementName.length() <= 0)) {
1146: strElementName = "Unnamed ";
1147: strElementName += strElementType;
1148: }
1149: }
1150:
1151: Iterator<IProjectTreeItem> itemsIter = projectTreeItems
1152: .iterator();
1153: while (itemsIter.hasNext()) {
1154: IProjectTreeItem projectTreeItem = itemsIter
1155: .next();
1156:
1157: IRequirement cpRequirement = getRequirementFromTreeItem(projectTreeItem);
1158:
1159: if (cpRequirement != null) {
1160: String strRequirementID = cpRequirement
1161: .getID();
1162: String strRequirementName = cpRequirement
1163: .getName();
1164: String strRequirementProviderID = cpRequirement
1165: .getProviderID();
1166: String strRequirementSourceID = cpRequirement
1167: .getSourceID();
1168: String strRequirementProjectName = cpRequirement
1169: .getProjectName();
1170: String strRequirementModName = cpRequirement
1171: .getModName();
1172:
1173: // Add the requirement info as a RequirementArtifact on the model element
1174: // that the requirement was dropped on.
1175: TypedFactoryRetriever<IRequirementArtifact> fact = new TypedFactoryRetriever<IRequirementArtifact>();
1176: IRequirementArtifact cpRequirementArtifact = fact
1177: .createType("RequirementArtifact");
1178:
1179: if (cpRequirementArtifact != null) {
1180: cpRequirementArtifact
1181: .setRequirementID(strRequirementID);
1182: cpRequirementArtifact
1183: .setName(strRequirementName);
1184: cpRequirementArtifact
1185: .setRequirementProviderID(strRequirementProviderID);
1186: cpRequirementArtifact
1187: .setRequirementSourceID(strRequirementSourceID);
1188: cpRequirementArtifact
1189: .setRequirementProjectName(strRequirementProjectName);
1190: cpRequirementArtifact
1191: .setRequirementModName(strRequirementModName);
1192: }
1193:
1194: // Add the Artifact to the Model Element. If the cpElement is a namespace
1195: // then call add owned element so the element added to namespace event gets fired
1196: if (cpElement instanceof INamespace) {
1197: INamespace cpNamespaceElement = (INamespace) cpElement;
1198: cpNamespaceElement
1199: .addOwnedElement(cpRequirementArtifact);
1200: } else {
1201: cpElement
1202: .addElement(cpRequirementArtifact);
1203: }
1204:
1205: // Get the Element's ProjectID.
1206: String strTopLevelID = cpElement
1207: .getTopLevelId();
1208:
1209: // Get the current Application so we can ask it things.
1210: IApplication cpApplication = ProductHelper
1211: .getApplication();
1212:
1213: // Ask the App for the ProjectInstance using the element's toplevelid.
1214: IProject cpProject = cpApplication
1215: .getProjectByID(strTopLevelID);
1216:
1217: // Get the name of the project.
1218: String strProjectName = cpProject.getName();
1219:
1220: ISatisfier cpSatisfier = new org.netbeans.modules.uml.core.requirementsframework.Satisfier();
1221: cpSatisfier.setName(strElementName);
1222: cpSatisfier.setType(strElementType);
1223: cpSatisfier.setXMIID(strElementXMIID);
1224: cpSatisfier.setProjectName(strProjectName);
1225: cpSatisfier.setProjectID(strTopLevelID);
1226:
1227: // Add Satisfier element to the Owning Requirement element in the Proxy file.
1228: processProxy(cpRequirement, cpSatisfier);
1229:
1230: try {
1231: // Tell Requirement to Add the Satisfer to its collection.
1232: cpRequirement.addSatisfier(cpSatisfier);
1233:
1234: // Add a 'SatisfiedBy' node to the ProjectTreeItem.
1235: IProjectTreeItem cpNewTreeItem = loadTreeItem(
1236: projectTreeItem, cpSatisfier);
1237:
1238: } catch (RequirementsException err) {
1239: if (err.getExceptionCode() == RequirementsException.RP_E_SHAREDEDITNOTSUPPORTED) {
1240: Frame handle = null;
1241:
1242: IProxyUserInterface cpProxyUserInterface = ProductHelper
1243: .getProxyUserInterface();
1244: if (cpProxyUserInterface != null) {
1245: handle = cpProxyUserInterface
1246: .getWindowHandle();
1247: }
1248:
1249: String msgText = err
1250: .getLocalizedMessage();
1251: String msgTitle = NbBundle
1252: .getMessage(
1253: ADRequirementsManager.class,
1254: "IDS_REQUIRENTERRORTITLE");
1255:
1256: IQuestionDialog question = UIFactory
1257: .createQuestionDialog();
1258: question
1259: .displaySimpleQuestionDialog(
1260: MessageDialogKindEnum.SQDK_OK,
1261: MessageIconKindEnum.EDIK_ICONWARNING,
1262: msgText,
1263: MessageResultKindEnum.SQDRK_RESULT_OK,
1264: handle, msgTitle);
1265: }
1266: }
1267:
1268: } // EndIf - TreeItem has an IRequirement instance in its DispatchElement
1269:
1270: } // End While..Loop - Project Tree Iteration
1271:
1272: } // EndIf - We are a Model Element
1273:
1274: } // EndIf - Presentation Element
1275:
1276: } // End While..Loop - satisfiers PEs iteration
1277:
1278: }
1279:
1280: /**
1281: *
1282: * Handles the OnDrawingAreaPostDrop event
1283: * for the ADRequirementsManager Addin. This event is fired on when
1284: * the user right-clicks in the DesignCenter TreeControl.
1285: *
1286: * @param pMenu[in] The Context Menu
1287: * @return The menu titles
1288: */
1289: public ETList<String> onProjectTreeContextMenuPrepare(
1290: IProductContextMenu pMenu) {
1291: // This implementation will not return any menu titles.
1292: ETList<String> retVal = new ETArrayList<String>();
1293: //
1294: // Object parent = pMenu.getParentControl( );
1295: //
1296: // // Ensure that we come from a tree control.
1297: // if( parent instanceof IProjectTreeControl)
1298: // {
1299: // IProjectTreeControl pTreeControl = (IProjectTreeControl)parent;
1300: //
1301: // IProjectTreeItem[] projectTreeItems = pTreeControl.getSelected();
1302: // if( projectTreeItems.length > 0 )
1303: // {
1304: // // Get the First Selected item.
1305: // IProjectTreeItem projectTreeItem = projectTreeItems[0];
1306: //
1307: // // Retrieve Names of Selected Node and its Parent.
1308: // String strNodeName = projectTreeItem.getItemText();
1309: //
1310: // IProjectTreeItem parentProjectTreeItem = pTreeControl.getParent(projectTreeItem);
1311: //
1312: // if( parentProjectTreeItem != null)
1313: // {
1314: // String strParentNodeName = parentProjectTreeItem.getItemText();
1315: //
1316: // String strAddInFriendlyName = NbBundle.getMessage(ADRequirementsManager.class,"IDS_ADDIN_FRIENDLY_NAME");
1317: //
1318: // if( (strNodeName.equals(strAddInFriendlyName) == true) ||
1319: // (strParentNodeName.equals(strAddInFriendlyName) == true))
1320: // {
1321: // // Get the text for the apply button.
1322: // String name = m_Bundle.getString("IDS_ADD_REQUIREMENTSOURCE" );
1323: //
1324: // // Ddetermine whether or not this button should be greyed out or not.
1325: // boolean bSensitive = true;
1326: //
1327: // // Get the SubMenus of the passed in menu.
1328: // ETList < IProductContextMenuItem > pMenuItems = pMenu.getSubMenus();
1329: //
1330: // if(pMenuItems != null)
1331: // {
1332: // // Create the menu item.
1333: // IProductContextMenuItem pTemp = new ProductContextMenuItem();
1334: // pTemp.setMenuString( name );
1335: // pTemp.setButtonSource( "MBK_ADD_REQUIREMENT_SOURCE" ); //NOI18N
1336: // pTemp.setSelectionHandler( m_EventsSink );
1337: // pTemp.setSensitive( bSensitive );
1338: // pMenuItems.add( pTemp );
1339: // }
1340: //
1341: // }
1342: //
1343: // if( strNodeName.equals(" Satisfiers") || strParentNodeName.equals(" Satisfiers") )
1344: // {
1345: // // Get the text for the apply button.
1346: // String name = m_Bundle.getString("IDS_REMOVE_SATISFIER");
1347: //
1348: // // Ddetermine whether or not this button should be greyed out or not.
1349: // boolean bSensitive = true;
1350: //
1351: // // Get the SubMenus of the passed in menu.
1352: // ETList < IProductContextMenuItem > pMenuItems = pMenu.getSubMenus();
1353: //
1354: // if( pMenuItems != null)
1355: // {
1356: // // Create the menu item.
1357: // IProductContextMenuItem pTemp = new ProductContextMenuItem();
1358: //
1359: // if( pTemp != null)
1360: // {
1361: // pTemp.setMenuString( name );
1362: // pTemp.setButtonSource( "MBK_REMOVE_SATISFIER" );
1363: // pTemp.setSelectionHandler( m_EventsSink );
1364: // pTemp.setSensitive( bSensitive );
1365: // pMenuItems.add( pTemp );
1366: // }
1367: // }
1368: // }
1369: // }
1370: // }
1371: // }
1372: //
1373: return retVal;
1374: }
1375:
1376: public void onProjectTreeContextMenuPrepared(
1377: IProductContextMenu pMenu) {
1378: }
1379:
1380: /**
1381: * Extracts the Description attribute from the passed in XML string. The XML
1382: * String is returned from the clipboard after a drag/drop is performed.
1383: *
1384: * @param strXML[in] An XML String from the clipboard after a drag/drop
1385: * @return The returned value of the Description attribute.
1386: */
1387: public String extractDescriptionAttribute(String strXML) {
1388: String retVal = "";
1389:
1390: Document xmlDoc = XMLManip.loadXML(strXML);
1391:
1392: if (xmlDoc != null) {
1393:
1394: String strtPattern = "/DRAGGEDITEMS/GENERICELEMENT/@DESCSTRING";
1395: Node node = XMLManip.selectSingleNode(xmlDoc, strtPattern);
1396:
1397: if (node != null) {
1398: retVal = node.getText();
1399: }
1400: }
1401:
1402: return retVal;
1403: }
1404:
1405: /**
1406: *
1407: * Add a sub-tree item to the passed in IProjectTreeItem.
1408: *
1409: * @param pParent[in] Parent Tree item.
1410: * @param pSatisfier[in] Name of Satisifer to find or add
1411: * @return The newly created sub-tree item.
1412: */
1413: public IProjectTreeItem loadTreeItem(IProjectTreeItem pParent,
1414: ISatisfier pSatisfier) {
1415: IProjectTreeItem retVal = null;
1416:
1417: if (null == pParent) {
1418: throw new IllegalArgumentException();
1419: }
1420:
1421: boolean bRequirementIsSatisfied = false;
1422:
1423: String strName = pSatisfier.getName();
1424: String strXMIID = pSatisfier.getXMIID();
1425:
1426: IProjectTreeItem projectTreeItem = null;
1427:
1428: IProjectTreeControl ctrl = getProjectTree();
1429: if (ctrl != null) {
1430: ETList<IProjectTreeItem> projectTreeItems = ctrl
1431: .getChildren(pParent);
1432:
1433: // Get Child folder item 'Satisfier' and create it if it doesn't exist.
1434: long lChildCount = projectTreeItems.size();
1435:
1436: if (lChildCount == 0) {
1437: // Then there is no 'Satisfiers' container folder, so add it.
1438: projectTreeItem = loadTreeItem(pParent, " Satisfiers",
1439: " Satisfiers");
1440: } else {
1441: // Search children for the Satisfiers folder (some children may be SubRequirements).
1442:
1443: boolean bFoundSatisfersContainer = false;
1444:
1445: // Iterate through all the children, find container folder.
1446: for (int lIdx = 0; lIdx < lChildCount; lIdx++) {
1447: IProjectTreeItem cpChildProjectTreeItem = projectTreeItems
1448: .get(lIdx);
1449:
1450: String strNodeName = cpChildProjectTreeItem
1451: .getItemText();
1452: if (strNodeName.equals(" Satisfiers")) {
1453: projectTreeItem = cpChildProjectTreeItem;
1454: bFoundSatisfersContainer = true;
1455: break;
1456: }
1457:
1458: }
1459:
1460: if (!bFoundSatisfersContainer) {
1461: // Then there is no 'Satisfiers' container folder, so add it.
1462: projectTreeItem = loadTreeItem(pParent,
1463: " Satisfiers", " Satisfiers");
1464: } else {
1465: // Check that the Requirement is not already in Satisfier folder (Prevent adding duplicate).
1466: ETList<IProjectTreeItem> cpSatisfierProjectTreeItems = ctrl
1467: .getChildren(projectTreeItem);
1468:
1469: // Check each Satisfer node to see if the model element is already satisfying the Requirement.
1470: for (int lIdx = 0; lIdx < cpSatisfierProjectTreeItems
1471: .size(); lIdx++) {
1472: IProjectTreeItem cpSatisfierProjectTreeItem = cpSatisfierProjectTreeItems
1473: .get(lIdx);
1474: String strSatisfierXMIID = cpSatisfierProjectTreeItem
1475: .getSecondaryDescription();
1476:
1477: // If the name of any child within <Satisfiers> is the same as the input (ModelElement) arg,
1478: // then this Requirement is already satisified by the model element.
1479: if (strXMIID.equals(strSatisfierXMIID) == true) {
1480: bRequirementIsSatisfied = true;
1481: break;
1482: }
1483: }
1484:
1485: }
1486:
1487: }
1488: }
1489:
1490: if (!bRequirementIsSatisfied) {
1491: retVal = loadTreeItem(projectTreeItem, strName, strXMIID);
1492: }
1493:
1494: return retVal;
1495: }
1496:
1497: /**
1498: *
1499: * Add a sub-tree item to the passed in IProjectTreeItem.
1500: *
1501: * @param pTreeItem[in] Parent Tree item.
1502: * @param strProgID[in] Name of the RequirementsProvider managing the new sub-tree item.
1503: * @param strRequirementSourceID[in] ID of RequirementsSource
1504: * @param pRequirement[in] an instance of IRequirement
1505: * @param ppNewTreeItem[in] Return the newly created sub-tree item.
1506: *
1507: * @return void
1508: *
1509: */
1510: public IProjectTreeItem loadTreeItem(IProjectTreeItem pTreeItem,
1511: IRequirement pRequirement) {
1512: IProjectTreeItem retVal = null;
1513: if ((null == pTreeItem) || (pRequirement == null)) {
1514: throw new IllegalArgumentException();
1515: }
1516:
1517: IProjectTreeControl ctrl = getProjectTree();
1518: if (ctrl != null) {
1519: String strRequirementName = pRequirement.getName();
1520: String strRequirementType = pRequirement.getType();
1521:
1522: String programName = "ReqRequirement";
1523: if (strRequirementType.equals("Category") == true) {
1524: programName = "ReqCategory";
1525: }
1526: retVal = ctrl.addItem(pTreeItem, // Parent tree item
1527: programName, strRequirementName, // Displayed tree item name
1528: ++sortPriority, // Sort Priority
1529: null, // IElement* this tree item represents
1530: strRequirementName); // Description.
1531:
1532: if (retVal != null) {
1533: // Add the text of the requirement
1534: ctrl.setDispatch(retVal, pRequirement);
1535: setImage(retVal, programName);
1536:
1537: // Action[] actions = { new RemoveSatisfierAction(retVal, ctrl) };
1538: // retVal.setActions(actions);
1539: }
1540: }
1541:
1542: return retVal;
1543: }
1544:
1545: /**
1546: *
1547: * Add a sub-tree item to the passed in IProjectTreeItem.
1548: *
1549: * @param pTreeItem[in] Parent Tree item.
1550: * @param strName[in] Name of either 1) New folder (will be equal to "Satisfiers"), or
1551: 2) the model element name being satisfied
1552: * @param strXMIID[in] ID of model element
1553: * @param ppNewTreeItem[in] Return the newly created sub-tree item.
1554: *
1555: * @return void
1556: *
1557: */
1558: public IProjectTreeItem loadTreeItem(IProjectTreeItem pTreeItem,
1559: String strName, String strXMIID) {
1560: IProjectTreeItem retVal = null;
1561:
1562: if (null == pTreeItem) {
1563: throw new IllegalArgumentException();
1564: }
1565:
1566: IProjectTreeControl ctrl = getProjectTree();
1567: if (ctrl != null) {
1568: String prgName = "ReqModelElement";
1569: if (strName.equals(" Satisfiers") == true) {
1570: prgName = "ReqModelElementFolder";
1571: }
1572:
1573: retVal = ctrl.addItem(pTreeItem, // Parent tree item
1574: prgName, // Program Name
1575: strName, // Displayed tree item name
1576: 1, // Sort Priority
1577: null, // IElement* this tree item represents
1578: strXMIID); // Not used for Req Provider.
1579:
1580: if (retVal != null) {
1581: Action[] actions = { new RemoveSatisfierAction(retVal,
1582: ctrl) };
1583: retVal.setActions(actions);
1584:
1585: // Add the text of the requirement.
1586: if (strName.equals(" Satisfiers") == true) {
1587: String strItemText = pTreeItem.getItemText();
1588: ctrl.setSecondaryDescription(retVal, strItemText);
1589:
1590: setImage(retVal, "ReqModelElementFolder");
1591: } else {
1592: ctrl.setSecondaryDescription(retVal, strXMIID);
1593: setImage(retVal, "ReqModelElement");
1594: }
1595: }
1596:
1597: }
1598:
1599: return retVal;
1600: }
1601:
1602: public IRequirement getRequirementFromTreeItem(
1603: IProjectTreeItem pTreeItem) {
1604: IRequirement retVal = null;
1605:
1606: if (null == pTreeItem) {
1607: throw new IllegalArgumentException();
1608: }
1609:
1610: Object cpDispatch = pTreeItem.getData();
1611:
1612: if (cpDispatch instanceof IRequirement) {
1613: retVal = (IRequirement) cpDispatch;
1614: }
1615:
1616: return retVal;
1617: }
1618:
1619: /**
1620: * Given a key String this looks the String up in the resource manager and returns
1621: * the icon that should be used for that type.
1622: *
1623: * @param pTreeItem [in] Contains the HTREEITEM that is to receive the icon
1624: * @param sIconType [in] The keyString that should be used to lookup the icon (usually the element name or folder name)
1625: */
1626: public void setImage(IProjectTreeItem pTreeItem, String sIconType) {
1627: if ((pTreeItem == null) || (sIconType.length() <= 0)) {
1628: throw new IllegalArgumentException();
1629: }
1630:
1631: boolean bFound = false;
1632:
1633: IProjectTreeControl ctrl = getProjectTree();
1634: if ((m_ResourceMgr != null) && (ctrl != null)) {
1635: long nIcon = 0;
1636:
1637: ctrl.setNodeName(pTreeItem, sIconType);
1638: // String sLibrary = m_ResourceMgr.getIconDetailsForElementType(sIconType);
1639: // CommonResourceManager resource = CommonResourceManager.instance();
1640: // Icon c = resource.getIconForElementType(sIconType);
1641: //
1642: // //if (nIcon && sLibrary.length() )
1643: // if (sLibrary.length() > 0)
1644: // {
1645: //// ctrl.setImage(pTreeItem,
1646: //// sLibrary,
1647: //// nIcon);
1648: // bFound = true;
1649: // }
1650: }
1651:
1652: if (!bFound) {
1653: // UMLMessagingHelper messageService(_Module.getModuleInstance(), IDS_MESSAGINGFACILITY);
1654: // messageService.sendWarningMessage(_Module.getModuleInstance(), IDS_COULDNOTSETIMAGE ) ;
1655: }
1656: }
1657:
1658: ////////////////////////////////////////////////////////////////////////////
1659: // IViewDelegate Methods
1660:
1661: public void init(ApplicationView view) {
1662: }
1663:
1664: public void run(ActionEvent e) {
1665: if (e.getActionCommand().equals(
1666: NbBundle.getMessage(ADRequirementsManager.class,
1667: "IDS_ADD_REQUIREMENTSOURCE")) == true) {
1668: IReqProviderDialog dlg = new ReqProviderDialog();
1669:
1670: IProxyUserInterface ui = ProductHelper
1671: .getProxyUserInterface();
1672: dlg.display(ui.getWindowHandle(), this );
1673: } else if (e.getActionCommand().equals(
1674: NbBundle.getMessage(ADRequirementsManager.class,
1675: "IDS_REMOVE_SATISFIER")) == true) {
1676: IProjectTreeControl tree = m_RequirementsManager
1677: .getProjectTree();
1678: if ((tree != null)
1679: && (tree.getConfigMgrName().equals("DesignCenter") == true)) {
1680: IProjectTreeItem[] selItems = tree.getSelected();
1681: if (selItems.length >= 1) {
1682: removeSatisfiers(tree, selItems);
1683: }
1684: }
1685: }
1686: }
1687:
1688: // public void selectionChanged(PluginAction action, ISelection selection)
1689: // {
1690: // }
1691:
1692: // public boolean validate(ApplicationView view, IContributionItem item, IMenuManager mgr)
1693: // {
1694: // boolean retVal = false;
1695: //
1696: // if(view instanceof IProjectTreeControl)
1697: // {
1698: // IProjectTreeControl tree = (IProjectTreeControl)view;
1699: // if(tree.getConfigMgrName().equals("DesignCenter") == true)
1700: // {
1701: // IProjectTreeItem[] selItems = tree.getSelected();
1702: // if((selItems != null) && (selItems.length >= 1))
1703: // {
1704: // String label = item.getLabel();
1705: // if(label.equals(NbBundle.getMessage(ADRequirementsManager.class, "IDS_ADD_REQUIREMENTSOURCE")) == true)
1706: // {
1707: // if(selItems.length == 1)
1708: // {
1709: // Object data = selItems[0].getData();
1710: // if(data instanceof IRequirementSource)
1711: // {
1712: // retVal = true;
1713: // }
1714: // else if(data instanceof IRequirementsManager)
1715: // {
1716: // retVal = true;
1717: // }
1718: // }
1719: // }
1720: // else if(label.equals(NbBundle.getMessage(ADRequirementsManager.class, "IDS_REMOVE_SATISFIER")) == true)
1721: // {
1722: // ITreeItem[] path = selItems[0].getPath();
1723: // ITreeItem selItem = path[path.length - 1];
1724: // String itemName = selItem.getName();
1725: // if((itemName.equals("ReqModelElement") == true) ||
1726: // (itemName.equals("ReqModelElementFolder") == true))
1727: // {
1728: // retVal = true;
1729: // }
1730: // }
1731: // }
1732: //
1733: // }
1734: // }
1735: //
1736: // return retVal;
1737: // }
1738:
1739: protected void removeSatisfiers(IProjectTreeControl pTreeControl,
1740: IProjectTreeItem[] projectTreeItems) {
1741: if (projectTreeItems.length > 0) {
1742: try {
1743: String strNodeName;
1744: String strParentNodeName;
1745:
1746: ETList<IProjectTreeItem> projectTreeItems2 = new ETArrayList<IProjectTreeItem>();
1747: for (int lIdx = 0; lIdx < projectTreeItems.length; lIdx++) {
1748: // Get the Next Selected item.
1749: IProjectTreeItem projectTreeItem = projectTreeItems[lIdx];
1750:
1751: // Also get its Parent.
1752: IProjectTreeItem parentProjectTreeItem = pTreeControl
1753: .getParent(projectTreeItem);
1754:
1755: // Retrieve Names of Selected Node and its Parent.
1756: strParentNodeName = parentProjectTreeItem
1757: .getItemText();
1758: strNodeName = projectTreeItem.getItemText();
1759:
1760: // Filter out only 'Satisfiers' (happens when a multi-range selection is made from tree).
1761: if (strNodeName.equals(" Satisfiers")
1762: || strParentNodeName.equals(" Satisfiers")) {
1763: // Add elements to a second collection to be deleted later.
1764: // projectTreeItems2.add( projectTreeItem )
1765:
1766: if (strParentNodeName.equals(" Satisfiers")) {
1767:
1768: removeItemFromProxy(pTreeControl,
1769: projectTreeItem,
1770: parentProjectTreeItem);
1771:
1772: // Add elements to a second collection to be deleted later.
1773: projectTreeItems2.add(projectTreeItem);
1774: } else if (strNodeName.equals(" Satisfiers")) {
1775: // Remove all of the Children.
1776: ETList<IProjectTreeItem> childProjectTreeItems = pTreeControl
1777: .getChildren(projectTreeItem);
1778: long lChildCount = childProjectTreeItems
1779: .size();
1780:
1781: // Iterate through all the children.
1782: for (int childIndex = 0; childIndex < lChildCount; childIndex++) {
1783: IProjectTreeItem childProjectTreeItem = childProjectTreeItems
1784: .get(childIndex);
1785:
1786: // Delete the child from the Proxy file.
1787: removeItemFromProxy(pTreeControl,
1788: childProjectTreeItem,
1789: projectTreeItem);
1790:
1791: // Add elements to a second collection to be deleted later.
1792: projectTreeItems2.add(projectTreeItem);
1793: } // End For..Loop
1794: } // EndElse - Node is a Satisfiers folder
1795: } // EndIf - Node is a satisfier(s} folder
1796:
1797: } // EndIf - TreeItem selectedItems > 0
1798:
1799: // Delete the items from the second 'filtered' collection.
1800:
1801: if (projectTreeItems2.size() > 0) {
1802: IProjectTreeItem[] removeItems = new IProjectTreeItem[projectTreeItems2
1803: .size()];
1804: projectTreeItems2.toArray(removeItems);
1805: pTreeControl.removeFromTree(removeItems);
1806: }
1807: } catch (RequirementsException e) {
1808:
1809: }
1810: }
1811: }
1812: }
|