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: package org.netbeans.modules.uml.ui.products.ad.applicationcore;
0043:
0044: import java.awt.Frame;
0045: import java.io.File;
0046: import java.io.IOException;
0047: import java.util.Enumeration;
0048: import java.util.Hashtable;
0049: import org.netbeans.modules.uml.core.IApplication;
0050: import org.netbeans.modules.uml.core.coreapplication.CoreProduct;
0051: import org.netbeans.modules.uml.core.coreapplication.ICoreMessenger;
0052: import org.netbeans.modules.uml.core.coreapplication.IDiagramCleanupManager;
0053: import org.netbeans.modules.uml.core.eventframework.EventDispatchNameKeeper;
0054: import org.netbeans.modules.uml.core.metamodel.core.foundation.FactoryRetriever;
0055: import org.netbeans.modules.uml.core.metamodel.core.foundation.ICreationFactory;
0056: import org.netbeans.modules.uml.core.metamodel.core.foundation.IVersionableElement;
0057: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0058: import org.netbeans.modules.uml.core.roundtripframework.codegeneration.ICodeGeneration;
0059: import org.netbeans.modules.uml.core.roundtripframework.codegeneration.IParseInformationCache;
0060: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0061: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0062: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElement;
0063: import org.netbeans.modules.uml.core.support.umlutils.InvalidArguments;
0064: import org.netbeans.modules.uml.ui.controls.drawingarea.DrawingAreaEventDispatcherImpl;
0065: import org.netbeans.modules.uml.ui.controls.drawingarea.IDrawingAreaEventDispatcher;
0066: import org.netbeans.modules.uml.ui.controls.drawingarea.IUIDiagram;
0067: import org.netbeans.modules.uml.ui.controls.editcontrol.EditControlEventDispatcher;
0068: import org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventDispatcher;
0069: import org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventDispatcher;
0070: import org.netbeans.modules.uml.ui.controls.filter.ProjectTreeFilterDialogEventDispatcher;
0071: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
0072: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeEventDispatcher;
0073: import org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeEventDispatcherImpl;
0074: import org.netbeans.modules.uml.ui.products.ad.diagramlisteners.DiagramBackupCleaner;
0075: import org.netbeans.modules.uml.ui.products.ad.diagramlisteners.IDiagramBackupCleaner;
0076: import org.netbeans.modules.uml.ui.support.DispatchHelper;
0077: import org.netbeans.modules.uml.ui.support.ProductHelper;
0078: import org.netbeans.modules.uml.ui.support.QuestionResponse;
0079: import org.netbeans.modules.uml.ui.support.applicationmanager.AcceleratorManager;
0080: import org.netbeans.modules.uml.ui.support.applicationmanager.IAcceleratorManager;
0081: import org.netbeans.modules.uml.ui.support.applicationmanager.IPresentationResourceMgr;
0082: import org.netbeans.modules.uml.ui.support.applicationmanager.IPresentationTypesMgr;
0083: import org.netbeans.modules.uml.ui.support.applicationmanager.IProductDiagramManager;
0084: import org.netbeans.modules.uml.ui.support.applicationmanager.IProductProjectManager;
0085: import org.netbeans.modules.uml.ui.support.applicationmanager.IProgressCtrl;
0086: import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
0087: import org.netbeans.modules.uml.ui.support.commondialogs.IQuestionDialog;
0088: import org.netbeans.modules.uml.ui.support.commondialogs.MessageDialogKindEnum;
0089: import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
0090: import org.netbeans.modules.uml.ui.support.commondialogs.MessageResultKindEnum;
0091: import org.netbeans.modules.uml.ui.support.diagramsupport.IPresentationFinder;
0092: import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
0093: import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
0094: import org.netbeans.modules.uml.ui.support.messaging.IProgressDialog;
0095: import org.netbeans.modules.uml.ui.support.messaging.ProgressDialog;
0096: import org.netbeans.modules.uml.ui.support.messaging.IMessenger;
0097: import org.netbeans.modules.uml.ui.support.messaging.Messenger;
0098: import org.netbeans.modules.uml.ui.support.messaging.ProgressDialogNoUI;
0099: import org.netbeans.modules.uml.core.scm.ISCMEventDispatcher;
0100: import org.netbeans.modules.uml.core.scm.ISCMIntegrator;
0101: import org.netbeans.modules.uml.core.scm.SCMObjectCreator;
0102: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeModel;
0103: import org.netbeans.modules.uml.ui.swing.commondialogs.SwingQuestionDialogImpl;
0104: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
0105: import org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor;
0106: import org.openide.ErrorManager;
0107:
0108: /**
0109: * @author sumitabhk
0110: *
0111: */
0112: public class ADProduct extends CoreProduct implements IADProduct {
0113: /// This is the project tree
0114: private IProjectTreeControl m_ProjectTree = null;
0115:
0116: // This is the project tree model. Can be used in place of m_ProjectTree
0117: private IProjectTreeModel mProjectTreeModel;
0118:
0119: /// This is the design center tree
0120: private IProjectTreeControl m_DesignCenterTree = null;
0121:
0122: /// This is the property editor
0123: private IPropertyEditor m_PropertyEditor = null;
0124:
0125: /// This is the messenger used to create our various error/question/prompt dialogs
0126: private IMessenger m_Messenger = null;
0127:
0128: /// The controller of all AddIns for this Product
0129: // private AddInControllerEx m_AddInController = null;
0130:
0131: /// The Diagram Manager which opens/closes and creates new diagrams in a gui
0132: private IProductDiagramManager m_DiagramManager = null;
0133:
0134: /// The Project Manager which controls the current project in the gui
0135: private IProductProjectManager m_ProjectManager = null;
0136:
0137: /// The addin manager
0138: // private IAddInManager m_AddInManager = null;
0139:
0140: /// The presentation finder that allows you to find presentation elements on closed diagrams
0141: private IPresentationFinder m_PresentationFinder = null;
0142:
0143: /// The current SCC interface
0144: private ISCMIntegrator m_SCMIntegrator = null;
0145:
0146: /// This guy listens to WSProject closes and cleans the diagram backup directory
0147: private IDiagramBackupCleaner m_DiagramBackupCleaner = null;
0148:
0149: /// Allows the users to display progress to the users through a ProgressCtrl
0150: private IProgressCtrl m_ProgressCtrl = null;
0151:
0152: /// Allows the users to display progress to the users through a Progress Dialog
0153: private IProgressDialog m_ProgressDialog = null;
0154:
0155: /// Watches for specific accerator keycodes and forwards them to interested windows
0156: private IAcceleratorManager m_AcceleratorMgr = null;
0157:
0158: /// Allows user to perform various funtions on the gui
0159: private IProxyUserInterface m_ProxyUserInterface = null;
0160:
0161: /// The diagram currently being serialized
0162: private IDiagram m_Diagram = null;
0163:
0164: //private Hashtable<String, Object> m_Diagrams = null;
0165: private Hashtable m_Diagrams = new Hashtable();
0166:
0167: /// This is the guy that handles various event sinks
0168: private ProductEventHandler m_ButtonHandler = null;
0169:
0170: /// The cache of parse information gathered from source files
0171: private IParseInformationCache m_ParseInfoCache = null;
0172:
0173: /// The Application's singleton Code Generation object
0174: private ICodeGeneration m_CodeGeneration = null;
0175:
0176: //holds ids to IDispatch* mappings
0177: private Hashtable/*<Integer, Object>*/m_ControlMap = new Hashtable();
0178:
0179: /// The cross diagram clipboard string. Used until TS gets copy/paste between diagrams working
0180: private String m_CrossDiagramClipboardString = "";
0181:
0182: /// The vba integrator
0183: private Object m_VBAIntegrator = null;
0184:
0185: private IPresentationTypesMgr m_PresentationTypesMgr = null;
0186:
0187: private IPresentationResourceMgr m_PresentationResourceMgr = null;
0188:
0189: /**
0190: *
0191: */
0192: public ADProduct() {
0193: super ();
0194: }
0195:
0196: /**
0197: * Returns the ParseInfoCache used for storing/caching Parsed Source Code information
0198: *
0199: * @param pVal[out] the currently used IParseInformationCache object
0200: *
0201: * @return HRESULT
0202: */
0203: public IParseInformationCache getParseInformationCache() {
0204: return m_ParseInfoCache;
0205: }
0206:
0207: /**
0208: * Sets the ParseInfoCache used for storing/caching Parsed Source Code information
0209: *
0210: * @param newVal[in] the new IParseInformationCache object
0211: *
0212: * @return HRESULT
0213: */
0214: public void setParseInformationCache(IParseInformationCache value) {
0215: m_ParseInfoCache = value;
0216: }
0217:
0218: /**
0219: * gets the ADProduct's code generation object
0220: */
0221: public ICodeGeneration getCodeGeneration() {
0222: return m_CodeGeneration;
0223: }
0224:
0225: /**
0226: * Sets the code generation object for the ADProduct
0227: */
0228: public void setCodeGeneration(ICodeGeneration value) {
0229: m_CodeGeneration = value;
0230: }
0231:
0232: /**
0233: * Creates a new Application and initializes the addins if asked.
0234: * If bInitializeAddins is false then call IProduct::InitializeAddIns.
0235: *
0236: * @param bInitializeAddins[in]
0237: * @param app[out]
0238: */
0239: public IApplication initialize2(boolean bInitializeAddins) {
0240: if (m_Application == null) {
0241: createApplication();
0242: registerToDispatchers();
0243:
0244: // Retrieve the SCMIntegrator, resulting in its
0245: // creation
0246: ISCMIntegrator gator = getSCMIntegrator();
0247: if (bInitializeAddins) {
0248: // initializeAddIns();
0249: }
0250: }
0251: return m_Application;
0252: }
0253:
0254: /**
0255: * Creates an IADApplication which represents the UML Metamodel for this application.
0256: */
0257: private void createApplication() {
0258: if (m_Application == null) {
0259: IApplication app = super .initialize();
0260: }
0261: }
0262:
0263: public IApplication initialize() {
0264: return initialize2(true);
0265: }
0266:
0267: /**
0268: *
0269: * Creates the IADProduct, specific to the UML design domain.
0270: *
0271: * @param app[out] The application
0272: *
0273: * @return HRESULT
0274: *
0275: */
0276: protected IApplication createProductApplication() {
0277: m_Application = new ADApplication();
0278: return m_Application;
0279: }
0280:
0281: /**
0282: * Returns the project tree that's in effect for the Describe product.
0283: *
0284: * @param pVal[out]
0285: */
0286: public IProjectTreeControl getProjectTree() {
0287: return m_ProjectTree;
0288: }
0289:
0290: /**
0291: * Sets the project tree that's in effect for the Describe product.
0292: *
0293: * @param newVal[in]
0294: */
0295: public void setProjectTree(IProjectTreeControl newVal) {
0296: if (m_ProjectTree != null) {
0297: m_ProjectTree = null;
0298: }
0299: m_ProjectTree = newVal;
0300: }
0301:
0302: /**
0303: * Returns the project tree model
0304: *
0305: * @param pVal[out]
0306: */
0307: public IProjectTreeModel getProjectTreeModel() {
0308: return mProjectTreeModel;
0309: }
0310:
0311: /**
0312: * Sets the project tree model
0313: *
0314: * @param newVal[in]
0315: */
0316: public void setProjectTreeModel(IProjectTreeModel newTreeModel) {
0317: mProjectTreeModel = newTreeModel;
0318: }
0319:
0320: /**
0321: * Returns the design center tree that's in effect for the Describe product.
0322: *
0323: * @param pVal[out]
0324: */
0325: public IProjectTreeControl getDesignCenterTree() {
0326: return m_DesignCenterTree;
0327: }
0328:
0329: /**
0330: * Sets the design center tree that's in effect for the Describe product.
0331: *
0332: * @param newVal[in]
0333: */
0334: public void setDesignCenterTree(IProjectTreeControl newVal) {
0335: if (m_DesignCenterTree != null) {
0336: m_DesignCenterTree = null;
0337: }
0338: m_DesignCenterTree = newVal;
0339: }
0340:
0341: /**
0342: * Returns the property editor that's in effect for the Describe product. This is the one in the
0343: * MFC GUI.
0344: *
0345: * @param pVal[out]
0346: */
0347: public IPropertyEditor getPropertyEditor() {
0348: return m_PropertyEditor;
0349: }
0350:
0351: /**
0352: * Sets the property editor that's in effect for the Describe product. This is the one in the
0353: * MFC GUI.
0354: *
0355: * @param newVal[in]
0356: */
0357: public void setPropertyEditor(IPropertyEditor newVal) {
0358: m_PropertyEditor = newVal;
0359: }
0360:
0361: /**
0362: * Returns the Diagram Manager which opens/closes and creates new diagrams in a gui.
0363: *
0364: * @param pVal[out]
0365: */
0366: public IProductDiagramManager getDiagramManager() {
0367: return m_DiagramManager;
0368: }
0369:
0370: /**
0371: * Allows users to get/set the current project.
0372: *
0373: * @param newVal[in]
0374: */
0375: public void setDiagramManager(IProductDiagramManager newVal) {
0376: m_DiagramManager = newVal;
0377: }
0378:
0379: /**
0380: * Allows users to get/set the current project.
0381: *
0382: * @param pVal[out]
0383: */
0384: public IProductProjectManager getProjectManager() {
0385: return m_ProjectManager;
0386: }
0387:
0388: /**
0389: * Sets the Diagram Manager which opens/closes and creates new diagrams in a gui.
0390: *
0391: * @param newVal[in]
0392: */
0393: public void setProjectManager(IProductProjectManager newVal) {
0394: m_ProjectManager = newVal;
0395: }
0396:
0397: /**
0398: * Allows user to perform various funtions on the gui.
0399: *
0400: * @param pVal[out]
0401: */
0402: public IProxyUserInterface getProxyUserInterface() {
0403: return m_ProxyUserInterface;
0404: }
0405:
0406: /**
0407: * Allows user to perform various funtions on the gui.
0408: *
0409: * @param newVal[in]
0410: */
0411: public void setProxyUserInterface(IProxyUserInterface newVal) {
0412: m_ProxyUserInterface = newVal;
0413: }
0414:
0415: /**
0416: * Allows user to perform various funtions on the gui.
0417: *
0418: * @param pVal[out]
0419: */
0420: // public IAddInManager getAddInManager()
0421: // {
0422: // if (m_AddInManager == null && m_AddInController != null)
0423: // {
0424: // Object obj = m_AddInController.getAddInManager();
0425: // if (obj != null && obj instanceof IAddInManager)
0426: // {
0427: // m_AddInManager = (IAddInManager)obj;
0428: // }
0429: // }
0430: // return m_AddInManager;
0431: // }
0432: /**
0433: * Allows user to perform various funtions on the gui.
0434: *
0435: * @param newVal[in]
0436: */
0437: // public void setAddInManager(IAddInManager newVal)
0438: // {
0439: // m_AddInManager = newVal;
0440: // }
0441: /**
0442: * Adds a drawing area to our list of open drawings.
0443: */
0444: public void addDiagram(IDiagram pDiagram) {
0445: if (pDiagram != null) {
0446: if (pDiagram instanceof IUIDiagram) {
0447: IUIDiagram diag = (IUIDiagram) pDiagram;
0448: IDrawingAreaControl control = diag.getDrawingArea();
0449: if (control != null) {
0450: String fileName = control.getFilename();
0451: if (fileName != null && fileName.length() > 0) {
0452: removeDiagram(pDiagram);
0453: String id = getDiagramFileID(fileName);
0454: IDiagram existingDia = getDiagram(id);
0455: if (existingDia == null) {
0456: m_Diagrams.put(id, pDiagram);
0457: }
0458: }
0459: }
0460: }
0461: }
0462: }
0463:
0464: // utility to normalize diagram file name which is used as a key
0465: private String getDiagramFileID(String fileName) {
0466: String id = "";
0467: File file = new File(fileName);
0468: try {
0469: id = file.getCanonicalPath();
0470: } catch (IOException e) {
0471: ErrorManager.getDefault().notify(e);
0472: }
0473: return id;
0474: }
0475:
0476: /**
0477: * Removes a drawing area to our list of open drawings.
0478: */
0479: public void removeDiagram(IDiagram pDiagram) {
0480: if (pDiagram != null) {
0481: if (pDiagram instanceof IUIDiagram) {
0482: IUIDiagram diag = (IUIDiagram) pDiagram;
0483: IDrawingAreaControl control = diag.getDrawingArea();
0484:
0485: if (control != null) {
0486: String fileName = control.getFilename();
0487: if (fileName != null && fileName.length() > 0) {
0488: String id = getDiagramFileID(fileName);
0489: Object obj = m_Diagrams.get(id);
0490: if (obj != null) {
0491: m_Diagrams.remove(id);
0492: }
0493: }
0494: }
0495: }
0496: }
0497: }
0498:
0499: /**
0500: * Returns an open drawing area based on the filename.
0501: *
0502: * @param pDiagram[out]
0503: */
0504: public IDiagram getDiagram(String sFilename) {
0505: IDiagram retDia = null;
0506: if (sFilename != null && sFilename.length() > 0) {
0507: Object obj = m_Diagrams.get(getDiagramFileID(sFilename));
0508: if (obj != null && obj instanceof IDiagram) {
0509: retDia = (IDiagram) obj;
0510: }
0511: }
0512: return retDia;
0513: }
0514:
0515: /**
0516: * Returns all open drawing ares in a safe array.
0517: *
0518: * @param pDiagrams[out]
0519: */
0520: public ETList<IDiagram> getAllDrawingAreas() {
0521: ETList<IDiagram> retObj = null;
0522: if (m_Diagrams != null && m_Diagrams.size() > 0) {
0523: retObj = new ETArrayList<IDiagram>();
0524: Enumeration iter = m_Diagrams.elements();
0525: while (iter.hasMoreElements()) {
0526: Object obj = iter.nextElement();
0527: if (obj != null && obj instanceof IDiagram) {
0528: retObj.add((IDiagram) obj);
0529: }
0530: }
0531: }
0532: return retObj;
0533: }
0534:
0535: /* (non-Javadoc)
0536: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProduct#displayAddInDialog(int)
0537: */
0538: public void displayAddInDialog(int parentHwnd) {
0539: // TODO Auto-generated method stub
0540: }
0541:
0542: /**
0543: * Gets an addin based on the clsid.
0544: *
0545: * @param pAddIN[out]
0546: */
0547: // public IAddIn getAddIn(String progID)
0548: // {
0549: // IAddIn retObj = null;
0550: // IAddInManager pAddinMan = getAddInManager();
0551: // if (pAddinMan != null)
0552: // {
0553: // retObj = pAddinMan.retrieveAddIn(progID);
0554: // }
0555: // return retObj;
0556: // }
0557: /**
0558: * Establish additional EventDispatchers by adding them to the internal
0559: * EventDispatchController.
0560: */
0561: protected void establishDispatchers() {
0562: super .establishDispatchers();
0563: if (m_DispatchController != null) {
0564: // Add the DrawingAreaDispatcher
0565: IDrawingAreaEventDispatcher pDrawDisp = new DrawingAreaEventDispatcherImpl();
0566: m_DispatchController.addDispatcher(EventDispatchNameKeeper
0567: .drawingAreaName(), pDrawDisp);
0568:
0569: // Add the ProjectTree dispatcher
0570: IProjectTreeEventDispatcher pProjectDisp = new ProjectTreeEventDispatcherImpl();
0571: m_DispatchController.addDispatcher(EventDispatchNameKeeper
0572: .projectTreeName(), pProjectDisp);
0573:
0574: // Add the EditControl dispatcher
0575: IEditControlEventDispatcher pEditDisp = new EditControlEventDispatcher();
0576: m_DispatchController.addDispatcher(EventDispatchNameKeeper
0577: .editCtrlName(), pEditDisp);
0578:
0579: // Add the Project Tree Filter Dialog dispatcher
0580: IProjectTreeFilterDialogEventDispatcher pFilterDisp = new ProjectTreeFilterDialogEventDispatcher();
0581: m_DispatchController.addDispatcher(EventDispatchNameKeeper
0582: .projectTreeFilterDialogName(), pFilterDisp);
0583:
0584: // Add the VBA dispatcher
0585: //IVBAIntegrationEventDispatcher pVBADisp = new
0586:
0587: // Add the SCM Events dispatch
0588: ISCMEventDispatcher pSCMDisp = (ISCMEventDispatcher) SCMObjectCreator
0589: .getInstanceFromRegistry("uml/scm/SCMEventDispatcher"); //new SCMEventDispatcher();
0590: if (pSCMDisp != null) {
0591: m_DispatchController.addDispatcher(
0592: EventDispatchNameKeeper.SCM(), pSCMDisp);
0593: }
0594:
0595: // create the Accelerator Manager
0596: // Put the accelerator manager so that users can register their accelerator tables
0597: if (m_AcceleratorMgr == null) {
0598: m_AcceleratorMgr = new AcceleratorManager();
0599: }
0600: }
0601: }
0602:
0603: /**
0604: * Creates the listeners for the diagrams.
0605: */
0606: private void establishDiagramListeners() {
0607: // Create the listener that cleans up our diagrams backup area
0608: m_DiagramBackupCleaner = new DiagramBackupCleaner();
0609: }
0610:
0611: /**
0612: *
0613: * Revokes all the EventDispatchers installed by this product.
0614: *
0615: * @return
0616: */
0617: private void revokeDispatchers() {
0618: if (m_DispatchController != null) {
0619: revokeDiagramListeners();
0620: //super.revokeDispatchers();
0621:
0622: m_DispatchController
0623: .removeDispatcher(EventDispatchNameKeeper
0624: .drawingAreaName());
0625: m_DispatchController
0626: .removeDispatcher(EventDispatchNameKeeper
0627: .projectTreeName());
0628: m_DispatchController
0629: .removeDispatcher(EventDispatchNameKeeper
0630: .editCtrlName());
0631: m_DispatchController
0632: .removeDispatcher(EventDispatchNameKeeper
0633: .projectTreeFilterDialogName());
0634: m_DispatchController
0635: .removeDispatcher(EventDispatchNameKeeper.SCM());
0636: m_DispatchController
0637: .removeDispatcher(EventDispatchNameKeeper.vBA());
0638: }
0639: }
0640:
0641: /**
0642: * Creates the listeners for the diagrams.
0643: */
0644: private void revokeDiagramListeners() {
0645: if (m_DispatchController != null) {
0646: if (m_DiagramBackupCleaner != null) {
0647: m_DiagramBackupCleaner.revoke();
0648: m_DiagramBackupCleaner = null;
0649: }
0650: }
0651: }
0652:
0653: /**
0654: *
0655: * Deinitalizes all loaded addins.
0656: *
0657: * @return HRESULT
0658: *
0659: */
0660: // public void deInitAddIns()
0661: // {
0662: // m_AddInController.unloadAddIns();
0663: // }
0664: /**
0665: * Returns the IApplication that this product wraps.
0666: *
0667: * @param pVal[out] The returned IApplication
0668: */
0669: public IApplication getApplication() {
0670: IApplication retVal = null;
0671: if (m_Application != null) {
0672: if (m_Application instanceof IADApplication) {
0673: IADApplication adApp = (IADApplication) m_Application;
0674: retVal = adApp.getApplication();
0675: }
0676: }
0677: return retVal;
0678: }
0679:
0680: /**
0681: * Sets the IApplication that this product wraps.
0682: *
0683: * @param newVal[in] The new IApplication to wrap
0684: */
0685: public void setApplication(IApplication newVal) {
0686: if (newVal != null) {
0687: if (newVal instanceof IADApplication) {
0688: m_Application = (IADApplication) newVal;
0689: }
0690: }
0691: }
0692:
0693: /**
0694: * Returns a shared IMessenger object for the product. Using a shared messenger allows
0695: * the application to be silenced during long operations.
0696: *
0697: * @param pVal[out] The returned messenger.
0698: */
0699: public IMessenger getMessenger() {
0700: if (m_Messenger == null) {
0701: m_Messenger = new Messenger();
0702: }
0703: return m_Messenger;
0704: }
0705:
0706: /**
0707: * Returns a shared IMessenger object for the product. Using a shared messenger allows
0708: * the application to be silenced during long operations.
0709: *
0710: * @param pVal[out] The returned messenger.
0711: */
0712: public ICoreMessenger getCoreMessenger() {
0713: if (m_Messenger == null) {
0714: m_Messenger = new Messenger();
0715: }
0716: return m_Messenger;
0717: }
0718:
0719: /**
0720: *
0721: * Initializes all addins found in the registry.
0722: *
0723: * @return HRESULT
0724: *
0725: */
0726: public void initializeAddIns() {
0727: // if (m_AddInController == null)
0728: // {
0729: // m_AddInController = new AddInControllerEx();
0730: // }
0731: //
0732: // if(m_AddInController != null)
0733: // {
0734: // //m_AddInController.loadAddins();
0735: // m_AddInController.loadStartUps(this);
0736: // }
0737: }
0738:
0739: /**
0740: * The current SCC interface.
0741: *
0742: * @param pVal[out]
0743: */
0744: public ISCMIntegrator getSCMIntegrator() {
0745: if (m_SCMIntegrator == null) {
0746: m_SCMIntegrator = (ISCMIntegrator) SCMObjectCreator
0747: .getInstanceFromRegistry("uml/scm/SCMIntegrator");//new SCMIntegrator();
0748: }
0749: return m_SCMIntegrator;
0750: }
0751:
0752: /**
0753: * Returns the Progress Controller
0754: *
0755: * @param pVal[out]
0756: */
0757: public IProgressCtrl getProgressCtrl() {
0758: return m_ProgressCtrl;
0759: }
0760:
0761: /**
0762: * Returns the Progress Dialog
0763: *
0764: * @param pVal[out]
0765: */
0766: public IProgressDialog getProgressDialog() {
0767: if (m_ProgressDialog == null) {
0768: if (isGUIProduct()) {
0769: IProxyUserInterface proxyUI = ProductHelper
0770: .getProxyUserInterface();
0771: if (proxyUI != null) {
0772: Frame parent = proxyUI.getWindowHandle();
0773: if (parent != null) {
0774: // In Java we never display a modal progress dlg. (Kevin).
0775: m_ProgressDialog = (parent != null) ? new ProgressDialog(
0776: parent, "Progress", false)
0777: : new ProgressDialog();
0778: }
0779: }
0780: }
0781:
0782: if (null == m_ProgressDialog) {
0783: m_ProgressDialog = new ProgressDialogNoUI();
0784: }
0785: }
0786: return m_ProgressDialog;
0787: }
0788:
0789: /**
0790: * Sets the Progress controller.
0791: *
0792: * @param newVal[in]
0793: */
0794: public void setProgressCtrl(IProgressCtrl newVal) {
0795: m_ProgressCtrl = newVal;
0796: }
0797:
0798: /**
0799: * Returns the Accelerator Manager so a window can register itself.
0800: *
0801: * @param pManager[out]
0802: */
0803: public IAcceleratorManager getAcceleratorManager() {
0804: return m_AcceleratorMgr;
0805: }
0806:
0807: /**
0808: * Sets the Accelerator Manager for the application.
0809: *
0810: * @param pManager[in]
0811: */
0812: public void setAcceleratorManager(IAcceleratorManager newVal) {
0813: m_AcceleratorMgr = newVal;
0814: }
0815:
0816: /**
0817: * Returns the Accelerator Manager so a window can register itself.
0818: *
0819: * @param pDiagram[out]
0820: */
0821: public IDiagram getSerializingDiagram() {
0822: return m_Diagram;
0823: }
0824:
0825: /**
0826: * Sets the Accelerator Manager for the application.
0827: *
0828: * @param pDiagram[in]
0829: */
0830: public void setSerializingDiagram(IDiagram newVal) {
0831: m_Diagram = newVal;
0832: }
0833:
0834: /**
0835: * AddControl(UINT ID, IDispatch* pUnk)
0836: *
0837: * Adds key=ID and value=IDispatch* to map for future retrieval.
0838: *
0839: * @param pDisp[in]
0840: *
0841: */
0842: public void addControl(int nID, Object pControl) {
0843: if (nID >= 0) {
0844: //Check to see if this ID already is in the map
0845: Object obj = getControl(nID);
0846: if (obj == null) {
0847: m_ControlMap.put(new Integer(nID), pControl);
0848: }
0849: }
0850: }
0851:
0852: /*
0853: * GetControl(UINT ID, IDispatch ** ppUnk).
0854: *
0855: * Queries for the IDispatch pointer to a control given an Id.
0856: *
0857: * @param ppDisp[out]
0858: */
0859: public Object getControl(int nID) {
0860: Object retObj = null;
0861: retObj = m_ControlMap.get(new Integer(nID));
0862: return retObj;
0863: }
0864:
0865: /**
0866: * RemoveControl(UINT ID)
0867: *
0868: * Removes a key=ID and value=IDispatch* from the a map.
0869: *
0870: */
0871: public void removeControl(int nID) {
0872: Integer intVal = new Integer(nID);
0873: Object obj = m_ControlMap.get(intVal);
0874: if (obj != null) {
0875: m_ControlMap.remove(intVal);
0876: }
0877: }
0878:
0879: /**
0880: * Until TS gets copy/paste between diagrams working, this is the text string that tells what the
0881: * user last copied. It's produced by CDragAndDropSupport in MFCSupport.dll.
0882: *
0883: * @param sClipString[out,retval] The clip string from another diagram
0884: */
0885: public String getCrossDiagramClipboard() {
0886: return m_CrossDiagramClipboardString;
0887: }
0888:
0889: /**
0890: * Until TS gets copy/paste between diagrams working, this is the text string that tells what the
0891: * user last copied. It's produced by CDragAndDropSupport in MFCSupport.dll.
0892: *
0893: * @param sClipString [in] The clip string from another diagram
0894: */
0895: public void setCrossDiagramClipboard(String value) {
0896: m_CrossDiagramClipboardString = value;
0897: }
0898:
0899: /**
0900: * Returns the design center tree that's in effect for the Describe product.
0901: *
0902: * @param pVal[out] The VBA integrator
0903: */
0904: public Object getVBAIntegrator() {
0905: return m_VBAIntegrator;
0906: }
0907:
0908: /**
0909: * Sets the design center tree that's in effect for the Describe product.
0910: *
0911: * @param newVal[in] The VBA integrator
0912: */
0913: public void setVBAIntegrator(Object value) {
0914: if (m_VBAIntegrator != null) {
0915: m_VBAIntegrator = null;
0916: }
0917: m_VBAIntegrator = value;
0918: }
0919:
0920: /**
0921: * Register to all our various dispatchers.
0922: */
0923: private void registerToDispatchers() {
0924: if (m_ButtonHandler == null) {
0925: m_ButtonHandler = new ProductEventHandler();
0926: m_ButtonHandler.setProductToAdvise(this );
0927:
0928: DispatchHelper helper = new DispatchHelper();
0929: helper.registerElementDisposalEvents(m_ButtonHandler);
0930: helper.registerForPreferenceManagerEvents(m_ButtonHandler);
0931: helper.registerForProjectEvents(m_ButtonHandler);
0932: }
0933: }
0934:
0935: /**
0936: * Revokes from the various dispatchers.
0937: */
0938: private void revokeFromDispatchers() {
0939: if (m_ButtonHandler != null) {
0940: try {
0941: DispatchHelper helper = new DispatchHelper();
0942: helper.revokeElementDisposalEventsSink(m_ButtonHandler);
0943: helper.revokePreferenceManagerSink(m_ButtonHandler);
0944: helper.revokeProjectSink(m_ButtonHandler);
0945: } catch (InvalidArguments e) {
0946: // TODO Auto-generated catch block
0947: e.printStackTrace();
0948: }
0949: }
0950: }
0951:
0952: /**
0953: * Deletes these elements from closed diagrams.
0954: *
0955: * @param pElements[in]
0956: */
0957: public void onDisposedElements(ETList<IVersionableElement> pElements) {
0958: IProxyDiagramManager pDiaMan = ProxyDiagramManager.instance();
0959: pDiaMan.markPresentationTargetsAsDeleted(pElements);
0960: }
0961:
0962: private ETList<IPropertyElement> getColors(
0963: ETList<IPropertyElement> allElems, boolean reload) {
0964: //Have To Do
0965: return null;
0966: }
0967:
0968: private ETList<IPropertyElement> getFonts(
0969: ETList<IPropertyElement> allElems, boolean reload) {
0970: //Have To Do
0971: return null;
0972: }
0973:
0974: /**
0975: * Handler for IPreferenceManagerEventsSink event informing us that a preference has changed.
0976: *
0977: * @param pVal[out] the currently used IParseInformationCache object
0978: *
0979: * @return HRESULT
0980: */
0981: public void onPreferencesChange(ETList<IPropertyElement> pElements) {
0982: if (pElements != null && getNumNonReadonlyDiagrams() > 0) {
0983: // Create a temporary list because we may modify it.
0984: ETList<IPropertyElement> pTempList = pElements;
0985:
0986: // See if any of these elements deal with fonts or colors. If so then ask the user
0987: // if fonts and colors should be applied to the open diagrams.
0988: ETList<IPropertyElement> colorProps = getColors(pElements,
0989: false);
0990: ETList<IPropertyElement> fontProps = getFonts(pElements,
0991: false);
0992:
0993: int colorCount = 0;
0994: int fontCount = 0;
0995: if (colorProps != null) {
0996: colorCount = colorProps.size();
0997: }
0998: if (fontProps != null) {
0999: fontCount = fontProps.size();
1000: }
1001:
1002: if (colorCount > 0 || fontCount > 0) {
1003: // Ask the user if changing colors is ok
1004: String message = "";//loadString(IDS_CHANGEOPENDIAGRAMS);
1005: String title = "";//loadString(IDS_CHANGEOPENDIAGRAMSTITLE);
1006: IQuestionDialog pDialog = new SwingQuestionDialogImpl();
1007: QuestionResponse result = pDialog
1008: .displaySimpleQuestionDialogWithCheckbox(
1009: MessageDialogKindEnum.SQDK_YESNO,
1010: MessageIconKindEnum.EDIK_ICONWARNING,
1011: message, "", title,
1012: MessageResultKindEnum.SQDRK_RESULT_YES,
1013: true);
1014: if (result.getResult() == MessageResultKindEnum.SQDRK_RESULT_NO) {
1015: // Remove the colors and fonts
1016: colorProps = null;
1017: fontProps = null;
1018: colorProps = getColors(pElements, true);
1019: fontProps = getFonts(pElements, true);
1020: }
1021: }
1022:
1023: // Now go over the diagrams and tell them about the changes
1024: if (m_Diagrams != null) {
1025: Enumeration iter = m_Diagrams.elements();
1026: while (iter.hasMoreElements()) {
1027: IDiagram pDiagram = (IDiagram) iter.nextElement();
1028: boolean readOnly = false;
1029: readOnly = pDiagram.getReadOnly();
1030:
1031: if (!readOnly) {
1032: // Notify the diagram of the changes
1033: IDrawingAreaControl pDrawingAreaControl = null;
1034: if (pDiagram instanceof IUIDiagram) {
1035: pDrawingAreaControl = ((IUIDiagram) pDiagram)
1036: .getDrawingArea();
1037: }
1038: if (pDrawingAreaControl != null) {
1039: IPropertyElement[] elements = new IPropertyElement[pElements
1040: .size()];
1041: for (int i = 0; i < pElements.size(); i++) {
1042: elements[i] = pElements.get(i);
1043: }
1044:
1045: pDrawingAreaControl
1046: .preferencesChanged(elements);
1047: }
1048: }
1049: }
1050: }
1051: }
1052: }
1053:
1054: /**
1055: * Returns the number of diagrams that aren't readonly
1056: */
1057: private int getNumNonReadonlyDiagrams() {
1058: int numNonReadonly = 0;
1059: if (m_Diagrams != null) {
1060: Enumeration iter = m_Diagrams.elements();
1061: while (iter.hasMoreElements()) {
1062: IDiagram dia = (IDiagram) iter.nextElement();
1063: boolean readOnly = dia.getReadOnly();
1064: if (!readOnly) {
1065: numNonReadonly++;
1066: }
1067: }
1068: }
1069: return numNonReadonly;
1070: }
1071:
1072: /**
1073: *
1074: * This method will always return true in the out parameter, indicating
1075: * that this product is part of a larger GUI shell.
1076: *
1077: * @param pVal[out] true
1078: *
1079: * @return S_OK
1080: *
1081: */
1082: public boolean isGUIProduct() {
1083: return true;
1084: }
1085:
1086: /**
1087: * Gets the Products DiagramCleanupManager.
1088: *
1089: * @param pVal[out] The DiagramCleanupManager
1090: *
1091: * @return HRESULT
1092: */
1093: public IDiagramCleanupManager getDiagramCleanupManager() {
1094: return ProxyDiagramManager.instance();
1095: }
1096:
1097: public IPresentationTypesMgr getPresentationTypesMgr() {
1098: if (m_PresentationTypesMgr == null) {
1099: ICreationFactory pCreationFactory = FactoryRetriever
1100: .instance().getCreationFactory();
1101: if (pCreationFactory != null) {
1102: Object value = pCreationFactory.retrieveEmptyMetaType(
1103: "PresentationTypes", "PresentationTypesMgr",
1104: null);
1105:
1106: if (value instanceof IPresentationTypesMgr) {
1107: m_PresentationTypesMgr = (IPresentationTypesMgr) value;
1108: }
1109: }
1110: }
1111:
1112: return m_PresentationTypesMgr;
1113: }
1114:
1115: public IPresentationResourceMgr getPresentationResourceMgr() {
1116: if (m_PresentationResourceMgr == null) {
1117: ICreationFactory pCreationFactory = FactoryRetriever
1118: .instance().getCreationFactory();
1119:
1120: if (pCreationFactory != null) {
1121: Object value = pCreationFactory.retrieveEmptyMetaType(
1122: "PresentationTypes", "PresentationResourceMgr",
1123: null);
1124:
1125: if (value instanceof IPresentationResourceMgr) {
1126: m_PresentationResourceMgr = (IPresentationResourceMgr) value;
1127: }
1128: }
1129: }
1130: return m_PresentationResourceMgr;
1131: }
1132: }
|