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.swing.propertyeditor;
0043:
0044: import java.lang.reflect.Constructor;
0045: import java.lang.reflect.InvocationTargetException;
0046: import java.lang.reflect.Method;
0047: import java.awt.BorderLayout;
0048: import java.awt.Component;
0049: import java.awt.Container;
0050: import java.awt.Dimension;
0051: import java.awt.Graphics;
0052: import java.awt.GridBagConstraints;
0053: import java.awt.GridBagLayout;
0054: import java.awt.event.ActionEvent;
0055: import java.awt.event.ActionListener;
0056: import java.awt.event.FocusEvent;
0057: import java.awt.event.KeyEvent;
0058: import java.beans.PropertyChangeEvent;
0059: import java.util.Collection;
0060: import java.util.HashMap;
0061: import java.util.Iterator;
0062: import java.util.TreeMap;
0063: import java.util.StringTokenizer;
0064: import java.util.Vector;
0065:
0066: import javax.swing.Icon;
0067: import javax.swing.ImageIcon;
0068: import javax.swing.JComboBox;
0069: import javax.swing.JMenu;
0070: import javax.swing.JPanel;
0071: import javax.swing.JPopupMenu;
0072: import javax.swing.JScrollPane;
0073: import javax.swing.JSplitPane;
0074: import javax.swing.JTextField;
0075: import javax.swing.JToolTip;
0076: import javax.swing.JTree;
0077: import javax.swing.LookAndFeel;
0078: import javax.swing.SwingUtilities;
0079: import javax.swing.table.TableCellEditor;
0080: import javax.swing.tree.DefaultMutableTreeNode;
0081: import javax.swing.tree.TreeNode;
0082: import javax.swing.tree.TreePath;
0083:
0084: import org.dom4j.Node;
0085:
0086: import org.netbeans.modules.uml.common.ETSystem;
0087: import org.netbeans.modules.uml.core.IApplication;
0088: import org.netbeans.modules.uml.core.configstringframework.ConfigStringHelper;
0089: import org.netbeans.modules.uml.core.configstringframework.ConfigStringTranslator;
0090: import org.netbeans.modules.uml.core.configstringframework.IConfigStringTranslator;
0091: import org.netbeans.modules.uml.core.coreapplication.CoreProductManager;
0092: import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
0093: import org.netbeans.modules.uml.core.coreapplication.IPreferenceManager2;
0094: import org.netbeans.modules.uml.core.eventframework.EventDispatchNameKeeper;
0095: import org.netbeans.modules.uml.core.eventframework.EventDispatchRetriever;
0096: import org.netbeans.modules.uml.core.eventframework.IEventPayload; //import org.netbeans.modules.uml.core.coreapplication.CoreProductManager;
0097: //import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
0098: //import org.netbeans.modules.uml.core.coreapplication.IPreferenceManager2;
0099: import org.netbeans.modules.uml.core.metamodel.core.foundation.ConfigManager;
0100: import org.netbeans.modules.uml.core.metamodel.core.foundation.CreationFactory;
0101: import org.netbeans.modules.uml.core.metamodel.core.foundation.FactoryRetriever;
0102: import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
0103: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0104: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElementLifeTimeEventDispatcher;
0105: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0106: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
0107: import org.netbeans.modules.uml.core.metamodel.core.foundation.IReference; //import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
0108: //import org.netbeans.modules.uml.core.metamodel.core.foundation.ICreationFactory;
0109: //import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0110: //import org.netbeans.modules.uml.core.metamodel.core.foundation.INameCollisionHandler;
0111: //import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0112: //import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
0113: //import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0114: import org.netbeans.modules.uml.core.preferenceframework.IPreferenceAccessor;
0115: import org.netbeans.modules.uml.core.preferenceframework.PreferenceAccessor; //import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ILanguage;
0116: import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ILanguage;
0117: import org.netbeans.modules.uml.core.support.umlsupport.ICustomValidator;
0118: import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
0119: import org.netbeans.modules.uml.core.support.umlsupport.IStrings; //import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
0120: //import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
0121: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0122: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0123: import org.netbeans.modules.uml.core.support.umlutils.EnumTranslator;
0124: import org.netbeans.modules.uml.core.support.umlutils.IEnumTranslator;
0125: import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinition;
0126: import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinitionFactory;
0127: import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinitionFilter;
0128: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElement;
0129: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElementManager;
0130: import org.netbeans.modules.uml.core.support.umlutils.InvalidArguments;
0131: import org.netbeans.modules.uml.core.support.umlutils.PropertyDefinitionFactory;
0132: import org.netbeans.modules.uml.core.support.umlutils.PropertyDefinitionFilter;
0133: import org.netbeans.modules.uml.core.support.umlutils.PropertyElementManager;
0134: import org.netbeans.modules.uml.core.workspacemanagement.IWSProject;
0135: import org.netbeans.modules.uml.core.workspacemanagement.IWorkspace; //import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0136: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0137: import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
0138: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IBehavioralFeature;
0139: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
0140: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperationSignatureChangeContextManager;
0141: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IParameter;
0142: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.OperationSignatureChangeContextManager;
0143: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0144: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
0145: import org.netbeans.modules.uml.ui.support.applicationmanager.INameCollisionListener;
0146: import org.netbeans.modules.uml.ui.support.applicationmanager.IProductDiagramManager;
0147: import org.netbeans.modules.uml.ui.support.applicationmanager.NameCollisionListener;
0148: import org.netbeans.modules.uml.ui.support.DispatchHelper;
0149: import org.netbeans.modules.uml.ui.support.QuestionResponse;
0150: import org.netbeans.modules.uml.ui.support.SimpleQuestionDialogKind;
0151: import org.netbeans.modules.uml.ui.support.SimpleQuestionDialogResultKind;
0152: import org.netbeans.modules.uml.ui.support.commondialogs.IQuestionDialog;
0153: import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
0154: import org.netbeans.modules.uml.ui.support.commonresources.CommonResourceManager;
0155: import org.netbeans.modules.uml.ui.support.commonresources.ICommonResourceManager;
0156: import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
0157: import org.netbeans.modules.uml.ui.support.ProductHelper;
0158: import org.netbeans.modules.uml.ui.swing.commondialogs.SwingQuestionDialogImpl;
0159: import org.netbeans.modules.uml.ui.swing.treetable.JDefaultMutableTreeNode;
0160: import org.netbeans.modules.uml.ui.swing.treetable.JDescribeComboBox;
0161: import org.netbeans.modules.uml.ui.swing.treetable.JPropertyTreeTable;
0162: import org.netbeans.modules.uml.ui.swing.treetable.JTreeTable;
0163: import org.netbeans.modules.uml.ui.swing.treetable.PropertyTreeTableModel;
0164: import org.netbeans.modules.uml.ui.swing.treetable.TreeTableCellEditor; //import org.netbeans.modules.uml.core.workspacemanagement.IWorkspace;
0165: //import org.netbeans.modules.uml.core.workspacemanagement.IWSProject;
0166: import org.netbeans.modules.uml.ui.support.drawingproperties.IColorProperty;
0167: import org.netbeans.modules.uml.ui.support.drawingproperties.IDrawingPropertyProvider;
0168: import org.netbeans.modules.uml.ui.support.drawingproperties.IFontProperty;
0169: import org.netbeans.modules.uml.ui.support.drawingproperties.IPropertyContainer;
0170: import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
0171: import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
0172: import org.netbeans.modules.uml.ui.support.finddialog.FindController;
0173: import org.netbeans.modules.uml.ui.support.finddialog.IFindController;
0174: import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder;
0175: import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
0176: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
0177:
0178: /**
0179: * @author sumitabhk
0180: *
0181: */
0182: public class PropertyEditor extends JPanel implements IPropertyEditor,
0183: ActionListener {
0184: public static int EDITOR_ALL = 0;
0185: public static int EDITOR_DATA = 1;
0186: public static int EDITOR_PRES = 2;
0187: public static int EDITOR_SEL = 3;
0188: private static String[][] m_MenuItems = {
0189: { PropertyEditorResources
0190: .getString("PropertyEditor.Fill_Down_Menu") }, //$NON-NLS-1$
0191: { PropertyEditorResources
0192: .getString("PropertyEditor.Create_Menu") }, //$NON-NLS-1$
0193: {
0194: PropertyEditorResources
0195: .getString("PropertyEditor.Create_Menu"), PropertyEditorResources.getString("PropertyEditor.Delete_Menu") }, //$NON-NLS-1$ //$NON-NLS-2$
0196: { PropertyEditorResources
0197: .getString("PropertyEditor.Delete_Menu") }, //$NON-NLS-1$
0198: { PropertyEditorResources
0199: .getString("PropertyEditor.Associate_Menu") }, //$NON-NLS-1$
0200: {
0201: PropertyEditorResources
0202: .getString("PropertyEditor.Create_Menu"), PropertyEditorResources.getString("PropertyEditor.Delete_Menu") }, //$NON-NLS-1$ //$NON-NLS-2$
0203: {
0204: PropertyEditorResources
0205: .getString("PropertyEditor.Create_Menu"), PropertyEditorResources.getString("PropertyEditor.Delete_Menu"), PropertyEditorResources.getString("PropertyEditor.InsertBefore_Menu") }, //$NON-NLS-1$ //$NON-NLS-2$
0206: {
0207: PropertyEditorResources
0208: .getString("PropertyEditor.Delete_Menu"), PropertyEditorResources.getString("PropertyEditor.Navigate_Menu") } //$NON-NLS-1$ //$NON-NLS-2$
0209: };
0210:
0211: private IPropertyDefinitionFactory m_Factory = null;
0212: private IPropertyElementManager m_PropEleMgr = null;
0213: private IProject m_Project = null;
0214: private ICommonResourceManager m_ResourceMgr = null;
0215: private Vector<IPropertyElement> m_Elements = new Vector<IPropertyElement>();
0216: private Vector<IPropertyDefinition> m_Definitions = new Vector<IPropertyDefinition>();
0217: private Vector<IPropertyElement> m_LoadedImages = new Vector<IPropertyElement>();
0218: private PropertyEditorFilter m_Filter = null;
0219: private boolean m_bSinksConnected = false;
0220: private boolean m_RespondToReload = false;
0221: private boolean m_InDelayedAction = false;
0222: private boolean m_IsShowingSelected = false;
0223: private Object m_PropertyGrid = null;
0224: /// The event handler for the various controls and the core UML metamodel
0225: private PropertyEditorEventsSink m_EventsSink = null;
0226: private INameCollisionListener m_NameCollisionListener = null;
0227: private IPropertyEditorCollisionHandler m_CollisionHandler = null;
0228: private JComboBox m_FilterCombo = null;
0229: private JToolTip m_ToolTip = null;
0230: private JPopupMenu m_Menu = new JPopupMenu();
0231: private JDefaultMutableTreeNode m_root = null;
0232: private PropertyTreeTableModel m_Model = null;
0233: private JTreeTable m_Tree = null;
0234: private int m_CurRow = 0;
0235: private int m_LastRow = 0;
0236: private boolean m_Reordered = false;
0237: private String m_ListBuffer = null;
0238: private Object m_CurLoadedObject = null;
0239: DispatchHelper m_DispatchHelper = new DispatchHelper();
0240:
0241: //private static PropertyEditor m_Instance = null;
0242:
0243: private int m_Mode = 0;
0244: private boolean focusChange = false;
0245: private boolean m_processingRecord = false;
0246: private JDefaultMutableTreeNode m_RecordNode = null;
0247:
0248: //this variable captures the row where user right clicked.
0249: private int m_RightClickRow = 0;
0250:
0251: private int m_EditableColor = 0;
0252: private int m_ReadOnlyColor = 0;
0253:
0254: private IOperationSignatureChangeContextManager m_SigChange = null;
0255:
0256: // public static PropertyEditor instance()
0257: // {
0258: // if (m_Instance == null)
0259: // {
0260: // m_Instance = new PropertyEditor();
0261: // }
0262: // return m_Instance;
0263: // }
0264: /**
0265: *
0266: */
0267: public PropertyEditor() {
0268: super ();
0269: GridBagLayout gbl = new GridBagLayout();
0270: // double[] rowVals = {0, 1};
0271: // double[] colVals = {0, 0.5, 0.5};
0272: // gbl.rowWeights = rowVals;
0273: // gbl.columnWeights = colVals;
0274: setLayout(new GridBagLayout());
0275: init();
0276: //m_Menu.setLightWeightPopupEnabled(true);
0277: // PropertyEditorEventsSink eventSink = new PropertyEditorEventsSink(this);
0278: // m_DispatchHelper.registerProjectTreeEvents(eventSink);
0279: // m_DispatchHelper.registerDrawingAreaCompartmentEvents(eventSink);
0280: // m_DispatchHelper.registerDrawingAreaSelectionEvents(eventSink);
0281: // m_DispatchHelper.registerDrawingAreaEvents(eventSink);
0282:
0283: //register for events
0284: initialize();
0285: }
0286:
0287: private void init() {
0288: if (m_Factory == null) {
0289: getPropertyDefinitionFactory();
0290: }
0291:
0292: ICoreProduct prod = CoreProductManager.instance()
0293: .getCoreProduct();
0294: IConfigManager conMan = prod != null ? prod.getConfigManager()
0295: : null;
0296: if (conMan != null) {
0297: String home = conMan.getDefaultConfigLocation();
0298: String file = home;
0299: file += "PropertyDefinitions.etc"; //$NON-NLS-1$
0300: m_Factory.setDefinitionFile(file);
0301: //m_Factory.buildDefinitionsUsingFile();
0302: }
0303:
0304: if (m_PropEleMgr == null) {
0305: getPropertyElementManager();
0306: }
0307: m_PropEleMgr.setPDFactory(m_Factory);
0308:
0309: m_ResourceMgr = CommonResourceManager.instance();
0310:
0311: m_Filter = new PropertyEditorFilter();
0312: m_Filter.build();
0313:
0314: // help box
0315: initializeHelpBox();
0316: // buttons
0317: initializeButtons();
0318: // grid stuff
0319: initializeGrid();
0320: // combo box, must be after the grid, because we use the mode which is determined
0321: // in the grid stuff
0322: initializeComboBox();
0323: // fill in the grid
0324: populateGrid();
0325: }
0326:
0327: public void prepareToShow() {
0328: removeAll();
0329: if (m_Tree != null) {
0330: //ETSystem.out.println("Tree is not null so displaying it");
0331:
0332: //JSplitPane sPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
0333: JScrollPane pane = new JScrollPane(m_Tree);
0334: //sPane.add(m_FilterCombo);
0335: //sPane.add(pane);
0336:
0337: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
0338: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0339: gridBagConstraints.weightx = 0.1;
0340: gridBagConstraints.weighty = 0.0;
0341: gridBagConstraints.gridx = 0;
0342: gridBagConstraints.gridy = 0;
0343: //add(sPane, gridBagConstraints);
0344: add(m_FilterCombo, gridBagConstraints);
0345:
0346: gridBagConstraints = new java.awt.GridBagConstraints();
0347: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0348: gridBagConstraints.weightx = 0.9;
0349: gridBagConstraints.weighty = 1.0;
0350: gridBagConstraints.gridx = 0;
0351: gridBagConstraints.gridy = 1;
0352: add(pane, gridBagConstraints);
0353:
0354: refresh();
0355: }
0356: }
0357:
0358: /**
0359: *
0360: */
0361: private void initializeHelpBox() {
0362: // TODO Auto-generated method stub
0363:
0364: }
0365:
0366: /**
0367: *
0368: */
0369: private void initializeButtons() {
0370: // TODO Auto-generated method stub
0371:
0372: }
0373:
0374: /**
0375: *
0376: */
0377: private void initializeComboBox() {
0378: if (m_FilterCombo == null) {
0379: m_FilterCombo = new JComboBox();
0380: }
0381: if (m_Filter != null) {
0382: //get common map
0383: Iterator iter = m_Filter.getCommonMapIter();
0384: if (iter != null) {
0385: while (iter.hasNext()) {
0386: Object obj = iter.next();
0387: if (obj != null) {
0388: String value = obj.toString();
0389: //ETSystem.out.println("Combo box value " + value);
0390: m_FilterCombo.addItem(value);
0391: }
0392: }
0393: }
0394: //Add another item to access filter dialog
0395: m_FilterCombo.addItem("..."); //$NON-NLS-1$
0396: setFilterComboBoxValue();
0397:
0398: m_FilterCombo.addActionListener(this );
0399: }
0400: }
0401:
0402: /**
0403: * Set up value in Filter combo box
0404: *
0405: * @return void
0406: */
0407: private void setFilterComboBoxValue() {
0408: if (m_FilterCombo != null) {
0409:
0410: //kris richards - "DefaultFilter" pref expunged. Set to "PSK_DATA"
0411: String filter = "PSK_DATA";
0412: m_FilterCombo.setSelectedItem(filter);
0413:
0414: }
0415: }
0416:
0417: /**
0418: *
0419: */
0420: private void initializeGrid() {
0421: // TODO Auto-generated method stub
0422:
0423: }
0424:
0425: /**
0426: * Initializes the property editor by creating an event sink and then listening to
0427: * drawing area select/deselect events
0428: *
0429: * @return HRESULT
0430: *
0431: */
0432: public long initialize() {
0433: // Set up sinks
0434: connectSinks(true);
0435:
0436: // register for accelerator keys for navigation within the grid
0437: registerAccelerators();
0438: registerAcceleratorsNoFocus();
0439:
0440: // Create the name collision listener
0441: m_NameCollisionListener = new NameCollisionListener();
0442: m_CollisionHandler = new PropertyEditorCollisionHandler();
0443:
0444: m_NameCollisionListener.setHandler(m_CollisionHandler);
0445: m_CollisionHandler.setPropertyEditor(this );
0446:
0447: return 0;
0448: }
0449:
0450: /**
0451: *
0452: */
0453: private void registerAcceleratorsNoFocus() {
0454: // TODO Auto-generated method stub
0455:
0456: }
0457:
0458: /**
0459: *
0460: */
0461: private void registerAccelerators() {
0462: // TODO Auto-generated method stub
0463:
0464: }
0465:
0466: /**
0467: * Gets the property definitions for the editor
0468: */
0469: public Vector<IPropertyDefinition> getPropertyDefinitions() {
0470: return m_Definitions;
0471: }
0472:
0473: /**
0474: * Sets the property definitions for the editor
0475: */
0476: public void setPropertyDefinitions(Vector<IPropertyDefinition> value) {
0477: m_Definitions = value;
0478: }
0479:
0480: /**
0481: * Gets the property elements for the editor
0482: */
0483: public Vector<IPropertyElement> getPropertyElements() {
0484: return m_Elements;
0485: }
0486:
0487: /**
0488: * Sets the property elements for the editor
0489: */
0490: public void setPropertyElements(Vector<IPropertyElement> value) {
0491: m_Elements = value;
0492: m_root = null;
0493: m_Model = null;
0494: populateGrid();
0495: }
0496:
0497: /* (non-Javadoc)
0498: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#clear()
0499: */
0500: public long clear() {
0501: if (m_Elements != null) {
0502: m_Elements.clear();
0503: }
0504: if (m_LoadedImages != null) {
0505: m_LoadedImages.clear();
0506: }
0507: if (m_Definitions != null) {
0508: m_Definitions.clear();
0509: }
0510:
0511: m_Model = null;
0512: m_root = null;
0513: m_Tree = null;
0514: doLayout();
0515: m_ListBuffer = ""; //$NON-NLS-1$
0516: m_IsShowingSelected = false;
0517: m_LastRow = 0;
0518: m_CurRow = 0;
0519: endSignatureChange();
0520:
0521: if (m_PropEleMgr != null) {
0522: // The manager can hold onto elements so when
0523: // the workspace closes make sure to clear out
0524: // it.
0525: m_PropEleMgr.setModelElement(null);
0526: m_PropEleMgr.setPresentationElement(null);
0527: }
0528:
0529: m_CurLoadedObject = null;
0530:
0531: //populateGrid();
0532: return 0;
0533: }
0534:
0535: /**
0536: * Gets the property element manager for the editor. Creates one if necessary.
0537: */
0538: public IPropertyElementManager getPropertyElementManager() {
0539: if (m_PropEleMgr == null) {
0540: m_PropEleMgr = new PropertyElementManager();
0541: }
0542: return m_PropEleMgr;
0543: }
0544:
0545: /**
0546: * Begin the process of saving the information in the property editor
0547: *
0548: * @return HRESULT
0549: *
0550: */
0551: public long save() {
0552: if (m_Tree != null) {
0553: int count = m_Tree.getRowCount();
0554:
0555: // loop through the information in the grid by row
0556: for (int i = 0; i < count; i++) {
0557: // get the property element at the currently processed row
0558: IPropertyElement pEle = getElementAtGridRow(i);
0559: if (pEle != null) {
0560: // has this property element been marked as modified
0561: boolean isMod = pEle.getModified();
0562: if (isMod) {
0563: // get the corresponding definition
0564: IPropertyDefinition pDef = pEle
0565: .getPropertyDefinition();
0566: if (pDef != null) {
0567: // just another check to see if we should set some data
0568: String cType = pDef.getControlType();
0569: if (cType != null && cType.length() > 0) {
0570: setRowData(i, pDef, pEle);
0571: }
0572: }
0573: }
0574: } else {
0575: IColorProperty pColorProperty = getColorPropertyAtGridRow(i);
0576: IFontProperty pFontProperty = getFontPropertyAtGridRow(i);
0577:
0578: if (pColorProperty != null) {
0579: // boolean isMod = pColorProperty.isModified();
0580: // if (isMod)
0581: {
0582: // pColorProperty.save();
0583: }
0584: } else if (pFontProperty != null) {
0585: // boolean isMod = pFontProperty.isModified();
0586: // if (isMod)
0587: {
0588: // pFontProperty.save();
0589: }
0590: }
0591: }
0592: }
0593: }
0594: return 0;
0595: }
0596:
0597: /**
0598: * Returns the font property at this grid row
0599: *
0600: * @param[in] row The row to retrieve the property element from
0601: * @param[out] pProperty The found font property
0602: *
0603: * @return HRESULT
0604: *
0605: */
0606: private IFontProperty getFontPropertyAtGridRow(int row) {
0607: IFontProperty retProp = null;
0608:
0609: if (row > 0 && m_Model != null) {
0610: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
0611: if (node != null) {
0612: Object obj = node.getUserObject();
0613: if (obj instanceof IFontProperty) {
0614: retProp = (IFontProperty) obj;
0615: }
0616: }
0617: }
0618:
0619: return retProp;
0620: }
0621:
0622: /**
0623: * Returns the color property at this grid row
0624: *
0625: * @param[in] row The row to retrieve the property element from
0626: * @param[out] pProperty The found color property
0627: *
0628: * @return HRESULT
0629: *
0630: */
0631: private IColorProperty getColorPropertyAtGridRow(int row) {
0632: IColorProperty retProp = null;
0633:
0634: if (row > 0 && m_Model != null) {
0635: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
0636: if (node != null) {
0637: Object obj = node.getUserObject();
0638: if (obj instanceof IColorProperty) {
0639: retProp = (IColorProperty) obj;
0640: }
0641: }
0642: }
0643:
0644: return retProp;
0645: }
0646:
0647: /**
0648: * Begin to store the data in the property element
0649: *
0650: * @param[in] row The row in the grid that we are currently setting the data on
0651: * @param[in] pDef The property definition associated with the element at this row
0652: * @param[in] pEle The property element at this row
0653: *
0654: * @return HRESULT
0655: *
0656: */
0657: private void setRowData(int i, IPropertyDefinition pDef,
0658: IPropertyElement pEle) {
0659: beginEditContext();
0660: if (m_Model != null) {
0661: // Block other events
0662: PropertyEditorBlocker.block();
0663: try {
0664: // get the model element associated with the property element
0665: Object pDisp = pEle.getElement();
0666: if (pDisp != null) {
0667: // if we are in an operation or any subelement of an operation
0668: // we need to start a signature change on it. RT needs all operation
0669: // changes to be at once, not one at a time
0670: IOperation pTempOp = getOperationFromPropertyElement(pEle);
0671: if (pTempOp != null) {
0672: if (m_SigChange == null) {
0673: m_SigChange = new OperationSignatureChangeContextManager();
0674: m_SigChange.startSignatureChange(pTempOp);
0675: }
0676: }
0677: // if there is a model element, we will just need to do set datas
0678: m_PropEleMgr.processData(pDisp, pDef, pEle);
0679:
0680: // the actual processing of the data would have done a set, but someone else may
0681: // have cancelled the put and unfortunately the put_ is successful, so we don't have
0682: // any way of knowing that it failed
0683: // After we did a put_, we did a get and refilled the element, so we need to refresh the
0684: // grid with the element's value
0685: m_PropEleMgr.interpretElementValue(pEle);
0686: String value = pEle.getValue();
0687: //refresh the element value in the grid.
0688: } else {
0689: // no model element, so we will need to create one
0690: // this also handles the setting of the data of the newly created model element
0691: // go up the property element chain and find the first model element that you come to
0692: Object pDisp2 = getModelElement(pEle);
0693: if (pDisp2 != null) {
0694: // go up the property element chain and find the first one that has the ability to insert
0695: IPropertyElement pInsertEle = getInsertElement(pEle);
0696: if (pInsertEle != null) {
0697: // get the corresponding definition for the insert element
0698: IPropertyDefinition pInsertDef = pInsertEle
0699: .getPropertyDefinition();
0700: if (pInsertDef != null) {
0701: // process the data for the found model element and the insert information
0702: // ie. This will do a IClass::CreateAttribute
0703: m_PropEleMgr.processData(pDisp2,
0704: pInsertDef, pInsertEle);
0705:
0706: // so now we have the newly created IDispatch
0707: Object pNewDisp = pInsertEle
0708: .getElement();
0709:
0710: // we are having problems in RT when dealing with the sets of an operation
0711: // the change events cannot handle single changes to the signature
0712: // a context was created to handle this and was being used by everything
0713: // but the property editor, so now we are special casing an operation
0714:
0715: IOperation pTempOp = getOperationFromPropertyElement(pInsertEle);
0716: if (pTempOp != null) {
0717: if (m_SigChange == null) {
0718: // create and start the signature context
0719: m_SigChange = new OperationSignatureChangeContextManager();
0720: m_SigChange
0721: .startSignatureChange(pTempOp);
0722: }
0723: }
0724: // if (pNewDisp instanceof IOperation)
0725: // {
0726: // IOperation op1 = (IOperation)pNewDisp;
0727: // // create and start the signature context
0728: // IOperationSignatureChangeContextManager sigChange = new OperationSignatureChangeContextManager();
0729: // //sigChange.startSignatureChange(op1);
0730: // }
0731: // else if (pNewDisp instanceof IParameter)
0732: // {
0733: // IParameter parm1 = (IParameter)pNewDisp;
0734: // // create and start the signature context
0735: // IOperationSignatureChangeContextManager sigChange = new OperationSignatureChangeContextManager();
0736: // IBehavioralFeature pOp2 = parm1.getBehavioralFeature();
0737: // if (pOp2 instanceof IOperation)
0738: // {
0739: // IOperation pOp3 = (IOperation)pOp2;
0740: // sigChange.startSignatureChange(pOp3);
0741: // }
0742: // }
0743:
0744: // this was originally kicked off
0745: // because information was entered into the property editor, so we still need
0746: // to process that
0747: m_PropEleMgr.processData(pNewDisp,
0748: pDef, pEle);
0749: }
0750: }
0751: }
0752: }
0753: } finally {
0754: PropertyEditorBlocker.unblock();
0755: }
0756: }
0757: endEditContext();
0758: }
0759:
0760: /**
0761: * Method to navigate up the property element chain to retrieve the property element that represents
0762: * the one that should be inserted into (the one with an insert method)
0763: *
0764: * @param[in] pEle The property element in which to get the insert element that it belongs to
0765: * @param[out] pInsertEle The property element that is the element in which to perform the insert
0766: *
0767: * @return HRESULT
0768: *
0769: */
0770: private IPropertyElement getInsertElement(IPropertyElement pEle) {
0771: IPropertyElement retEle = null;
0772:
0773: if (pEle != null) {
0774: // get the corresponding definition
0775: IPropertyDefinition pDef = pEle.getPropertyDefinition();
0776: if (pDef != null) {
0777: // get the insert method
0778: String insMethod = pDef.getCreateMethod();
0779: if (insMethod == null || insMethod.length() == 0) {
0780: IPropertyElement parentEle = pEle.getParent();
0781: if (parentEle != null) {
0782: retEle = getInsertElement(parentEle);
0783: }
0784: } else {
0785: retEle = pEle;
0786: }
0787: }
0788: }
0789: return retEle;
0790: }
0791:
0792: /**
0793: * Method to navigate up the property element chain to retrieve the property element that represents
0794: * the one that should be deleted from (the one with a delete method)
0795: *
0796: * @param[in] pEle The property element in which to get the insert element that it belongs to
0797: * @param[out] pInsertEle The property element that is the element in which to perform the insert
0798: *
0799: * @return HRESULT
0800: *
0801: */
0802: private IPropertyElement getDeleteElement(IPropertyElement pEle) {
0803: IPropertyElement retEle = null;
0804:
0805: if (pEle != null) {
0806: // get the corresponding definition
0807: IPropertyDefinition pDef = pEle.getPropertyDefinition();
0808: if (pDef != null) {
0809: // get the delete method
0810: String delMethod = pDef.getDeleteMethod();
0811: if (delMethod == null || delMethod.length() == 0) {
0812: IPropertyElement parentEle = pEle.getParent();
0813: if (parentEle != null) {
0814: retEle = getDeleteElement(parentEle);
0815: }
0816: } else {
0817: retEle = pEle;
0818: }
0819: }
0820: }
0821: return retEle;
0822: }
0823:
0824: /**
0825: * Method to navigate up the property element chain to retrieve the first model element in the chain
0826: *
0827: * @param[in] pEle The property element in which to get the model element
0828: * @param[out] pModEle The model element
0829: *
0830: * @return HRESULT
0831: *
0832: */
0833: private Object getModelElement(IPropertyElement pEle) {
0834: Object retObj = null;
0835: if (pEle != null) {
0836: // get the model element
0837: Object pDisp = pEle.getElement();
0838: if (pDisp == null) {
0839: IPropertyElement parentEle = pEle.getParent();
0840: if (parentEle != null) {
0841: retObj = getModelElement(parentEle);
0842: }
0843: } else {
0844: retObj = pDisp;
0845: }
0846: }
0847: return retObj;
0848: }
0849:
0850: /**
0851: * Gets the property definition factory for the editor. Creates one if necessary.
0852: */
0853: public IPropertyDefinitionFactory getPropertyDefinitionFactory() {
0854: if (m_Factory == null) {
0855: m_Factory = new PropertyDefinitionFactory();
0856: }
0857: if (m_Factory != null) {
0858: ICoreProduct prod = CoreProductManager.instance()
0859: .getCoreProduct();
0860: IConfigManager conMan = prod != null ? prod
0861: .getConfigManager() : null;
0862: if (conMan != null) {
0863: String home = conMan.getDefaultConfigLocation();
0864: String file = home + "PropertyDefinitions.etc"; //$NON-NLS-1$
0865: m_Factory.setDefinitionFile(file);
0866: }
0867: }
0868: return m_Factory;
0869: }
0870:
0871: /* (non-Javadoc)
0872: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#setProject(org.netbeans.modules.uml.core.metamodel.structure.IProject)
0873: */
0874: public void setProject(IProject value) {
0875: m_Project = value;
0876: }
0877:
0878: /* (non-Javadoc)
0879: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#setFocus()
0880: */
0881: public long setFocus() {
0882: // TODO Auto-generated method stub
0883: return 0;
0884: }
0885:
0886: /* (non-Javadoc)
0887: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#populateGrid()
0888: */
0889: public long populateGrid() {
0890: if (m_Elements != null && m_Elements.size() > 0) {
0891: int count = m_Elements.size();
0892: m_root = new JDefaultMutableTreeNode("Root"); //$NON-NLS-1$
0893: for (int i = 0; i < count; i++) {
0894: IPropertyElement pEle = m_Elements.elementAt(i);
0895: String topName = calculateTopElementName(pEle);
0896: pEle.getPropertyDefinition().setPropertyEditorShowName(
0897: topName);
0898: JDefaultMutableTreeNode node = new JDefaultMutableTreeNode(
0899: pEle, true);
0900: node.setIsRoot(true);
0901: buildSubElementsThatNeedToDisplay(pEle, node);
0902: node.setExpanded(true);
0903: m_root.add(node);
0904: //m_Model.expand(i, true);
0905: }
0906: //ETSystem.out.println("Going to show the property Element " + pEle.getName());
0907: //m_root = new JDefaultMutableTreeNode(pEle, true);
0908: m_Model = null;
0909: m_Model = new PropertyTreeTableModel(m_root, this );
0910: //Vector<Object> subEles = m_Elements;
0911: //subEles.remove(0);
0912: //m_Model.setChildren(subEles);
0913: m_Tree = null;
0914: m_Tree = new JPropertyTreeTable(m_Model, this );
0915: m_Tree.getTree().setRootVisible(false);
0916: m_Model.setTreeTable(m_Tree);
0917: for (int i = count - 1; i >= 0; i--) {
0918: m_Model.expand(i, true);
0919: }
0920: } else {
0921: m_root = new JDefaultMutableTreeNode();
0922: m_Model = new PropertyTreeTableModel(m_root, this );
0923: m_Tree = new JPropertyTreeTable(m_Model, this );
0924: m_Model.setTreeTable(m_Tree);
0925: }
0926: prepareToShow();
0927: return 0;
0928: }
0929:
0930: /**
0931: * Add a top level property element to the grid
0932: *
0933: * @param[in] pElement The property element to add
0934: *
0935: * @return HRESULT
0936: *
0937: */
0938: public JDefaultMutableTreeNode addTopElementToGrid(
0939: IPropertyElement pEle) {
0940: JDefaultMutableTreeNode retNode = null;
0941:
0942: if (m_Model != null) {
0943: // for the state diagram, we ran into the case where even though the elements
0944: // were of the same element type, we wanted to display their kind (initial, final)
0945: // so do some special processing before determining the main display name
0946: // add the main element row to the grid
0947: String name = calculateTopElementName(pEle);
0948: String value = pEle.getValue();
0949: retNode = new JDefaultMutableTreeNode(pEle);
0950: }
0951:
0952: return retNode;
0953: }
0954:
0955: /**
0956: * Reload the particular property element that is associated with the passed in
0957: * model element
0958: *
0959: * @param[in] pDisp The model element that needs to be reloaded
0960: *
0961: * @return HRESULT
0962: *
0963: */
0964: public long reloadElement(Object pDisp) {
0965: // check this first to determine if we should even try to reload
0966: if (m_RespondToReload) {
0967: // We were just casting the information to an IElement, but this did not work
0968: // in the case of an IProject, so had to add an extra check here so that we
0969: // know what to cast it too
0970: if (pDisp instanceof IPresentationElement) {
0971: IPresentationElement pres = (IPresentationElement) pDisp;
0972: IElement pEle = pres.getFirstSubject();
0973: if (pEle != null) {
0974: reloadElement2(pEle);
0975: }
0976: } else if (pDisp instanceof IElement) {
0977: IElement pEle = (IElement) pDisp;
0978: reloadElement2(pEle);
0979: } else if (pDisp instanceof IWSProject) {
0980: IWSProject proj = (IWSProject) pDisp;
0981: reloadProject(proj);
0982: } else if (pDisp instanceof IProxyDiagram) {
0983: IProxyDiagram diag = (IProxyDiagram) pDisp;
0984: reloadDiagram(diag);
0985: }
0986: }
0987: m_InDelayedAction = false;
0988: return 0;
0989: }
0990:
0991: /**
0992: * Reload the particular property element that is associated with the passed in IElement
0993: *
0994: * @param[in] pElement The IElement that needs to be reloaded
0995: *
0996: * @return HRESULT
0997: *
0998: */
0999: private void reloadElement2(IElement pEle) {
1000: PropertyEditorBlocker.block();
1001: try {
1002: // loop through the elements currently in the property editor
1003: if (m_Elements != null) {
1004: int count = m_Elements.size();
1005: for (int i = 0; i < count; i++) {
1006: IPropertyElement propEle = m_Elements.get(i);
1007: boolean bReload = false;
1008:
1009: // get the model elements from the property element
1010: Object pDisp = propEle.getElement();
1011: IElement pToReload = null;
1012:
1013: // is the dispatch on the property element a presentation element
1014: // if so, need to get its model element before continuing
1015: if (pDisp instanceof IPresentationElement) {
1016: IPresentationElement presEle = (IPresentationElement) pDisp;
1017: IElement pModelEle = presEle.getFirstSubject();
1018: if (pModelEle != null) {
1019: bReload = shouldReloadElement(pEle,
1020: pModelEle);
1021: pToReload = pModelEle;
1022: }
1023: } else {
1024: if (pDisp instanceof IElement) {
1025: IElement element = (IElement) pDisp;
1026: bReload = shouldReloadElement(pEle, element);
1027: pToReload = element;
1028: }
1029: }
1030:
1031: // we have now determined whether or not the property editor should
1032: // be reloaded because an element that is displayed in it
1033: if (bReload && !m_InDelayedAction) {
1034: IPropertyDefinition pDef = propEle
1035: .getPropertyDefinition();
1036: // build a new property element (refresh its data)
1037: if (pToReload != null) {
1038: IPropertyElement propEle2 = m_PropEleMgr
1039: .buildElement(pToReload, pDef,
1040: propEle);
1041: filterPropertyElement(propEle2);
1042:
1043: // remove the old one
1044: m_Elements.removeElementAt(i);
1045: // add the new one
1046: m_Elements.add(propEle2);
1047: // refresh the grid
1048: setPropertyElements(m_Elements);
1049: break;
1050: }
1051: }
1052: }
1053: }
1054: } finally {
1055: PropertyEditorBlocker.unblock();
1056: }
1057: }
1058:
1059: /**
1060: * Determines whether or not the property editor should reload its data
1061: *
1062: *
1063: * @param pCurr[in] The element that has changed as a result of some user action in the tool
1064: * @param pCurrInEditor[in] The element currently displayed in the editor
1065: * @param bReload[in] Whether or not the property editor should reload its data
1066: *
1067: * @return HRESULT
1068: *
1069: */
1070: private boolean shouldReloadElement(IElement pEle,
1071: IElement pModelEle) {
1072: boolean bReload = false;
1073:
1074: // does this property element have the same model element as the one passed in
1075: boolean isSame = pEle.isSame(pModelEle);
1076: if (isSame) {
1077: bReload = true;
1078: } else {
1079: // may not be the same, but if it is a child of what is in the property editor, we
1080: // still want to reload it
1081: boolean isOwned = pModelEle.isOwnedElement(pEle);
1082: if (isOwned) {
1083: bReload = true;
1084: } else {
1085: // one more check to see if the element coming in for the reload
1086: // owns what is in the property editor. if it does then reload
1087: // it
1088: boolean isChild = isElementChildElement(pEle, pModelEle);
1089: if (isChild) {
1090: bReload = true;
1091: }
1092: }
1093: }
1094:
1095: return bReload;
1096: }
1097:
1098: /**
1099: * Checks to see if the passed in parent element contains the passed in child element. It does
1100: * not have to be an owned element, it checks by dom node containment (whether it is under the
1101: * structure or not)
1102: *
1103: *
1104: * @param pParent[in] Element that is the parent element
1105: * @param pChild[in] Element that is the child element
1106: * @param bIsChild[in] Whether or not it is a child of the parent
1107: *
1108: * @return HRESULT
1109: *
1110: */
1111: private boolean isElementChildElement(IElement parent,
1112: IElement child) {
1113: boolean bIsChild = false;
1114: Node parNode = parent.getNode();
1115: if (parNode != null) {
1116: String id = child.getXMIID();
1117: if (id != null && id.length() > 0) {
1118: String pattern = ".//*[@xmi.id=\'"; //$NON-NLS-1$
1119: pattern += id;
1120: pattern += "\']"; //$NON-NLS-1$
1121: Node foundNode = parNode.selectSingleNode(pattern);
1122: if (foundNode != null) {
1123: bIsChild = true;
1124: }
1125: }
1126: }
1127: return bIsChild;
1128: }
1129:
1130: /**
1131: * Reload the particular property element that is associated with the passed in project
1132: *
1133: * @param[in] pProject The IWSProject that needs to be reloaded
1134: *
1135: * @return HRESULT
1136: *
1137: */
1138: private void reloadProject(IWSProject proj) {
1139: m_PropEleMgr.setModelElement(proj);
1140: // remove everything in the property editor first because
1141: // this was causing memory leaks if the project was closed
1142: // and stuff still was being displayed in the editor
1143: if (m_Elements != null) {
1144: m_Elements.removeAllElements();
1145: m_Elements = null;
1146: m_Elements = new Vector<IPropertyElement>();
1147:
1148: // is what is being passed in an open or closed project
1149: // this will be determined by asking the application for the project with
1150: // this name, if we get one back it is open
1151: IApplication app = ProductHelper.getApplication();
1152: if (app != null) {
1153: String name = proj.getName();
1154: IProject pProj = app.getProjectByName(name);
1155: if (pProj != null) {
1156: // but now we actually want to build the information for an IProject, not a IWSProject
1157: // which is what we have
1158: // so get the definition for an IProject
1159: IPropertyDefinition pDef = m_Factory
1160: .getPropertyDefinitionForElement(
1161: "Project", pProj); //$NON-NLS-1$
1162: if (pDef != null) {
1163: // build a new property element (refresh its data)
1164: m_PropEleMgr.setModelElement(pProj);
1165: IPropertyElement propEle2 = m_PropEleMgr
1166: .buildElement(pProj, pDef, null);
1167: filterPropertyElement(propEle2);
1168: // add the new one
1169: m_Elements.add(propEle2);
1170: // refresh the grid
1171: setPropertyElements(m_Elements);
1172: }
1173: } else {
1174: IPropertyDefinition pDef = m_Factory
1175: .getPropertyDefinitionForElement(
1176: "WSProject", proj); //$NON-NLS-1$
1177: if (pDef != null) {
1178: if (m_PropEleMgr != null) {
1179: // build a new property element (refresh its data)
1180: IPropertyElement propEle2 = m_PropEleMgr
1181: .buildElement(proj, pDef, null);
1182: filterPropertyElement(propEle2);
1183:
1184: if (m_Elements == null) {
1185: m_Elements = new Vector<IPropertyElement>();
1186: }
1187:
1188: // add the new one
1189: m_Elements.add(propEle2);
1190: // refresh the grid
1191: setPropertyElements(m_Elements);
1192: }
1193: }
1194: }
1195: }
1196: }
1197: }
1198:
1199: /**
1200: * Reload the particular property element that is associated with the passed in diagram
1201: *
1202: * @param[in] pElement The diagram that needs to be reloaded
1203: *
1204: * @return HRESULT
1205: */
1206: private void reloadDiagram(IProxyDiagram diag) {
1207: PropertyEditorBlocker.block();
1208: try {
1209: // loop through the elements currently in the property editor
1210: if (m_Elements != null) {
1211: int count = m_Elements.size();
1212: for (int i = 0; i < count; i++) {
1213: IPropertyElement propElement = m_Elements.get(i);
1214:
1215: // get the model elements from the property element
1216: Object pDisp = propElement.getElement();
1217: if (pDisp instanceof IDiagram) {
1218: IDiagram pEle = (IDiagram) pDisp;
1219: IDiagram dia1 = diag.getDiagram();
1220: if (dia1 != null) {
1221: // does this property element have the same model element as the one passed in
1222: boolean isSame = dia1.isSame(pEle);
1223: if (isSame) {
1224: IPropertyDefinition pDef = propElement
1225: .getPropertyDefinition();
1226: // build a new property element (refresh its data)
1227: IPropertyElement propEle = m_PropEleMgr
1228: .buildElement(pDisp, pDef,
1229: propElement);
1230: filterPropertyElement(propEle);
1231:
1232: // remove the old one
1233: m_Elements.removeElementAt(i);
1234: // add the new one
1235: m_Elements.add(propEle);
1236: // refresh the grid
1237: setPropertyElements(m_Elements);
1238: }
1239: }
1240: }
1241: }
1242: }
1243: } finally {
1244: PropertyEditorBlocker.unblock();
1245: }
1246: }
1247:
1248: /**
1249: * Registers or revokes event sinks.
1250: *
1251: * @param bConnect
1252: *
1253: * @return HRESULT
1254: *
1255: */
1256: public long connectSinks(boolean bConnect) {
1257: DispatchHelper helper = new DispatchHelper();
1258: if (bConnect && !m_bSinksConnected) {
1259: if (m_EventsSink == null) {
1260: m_EventsSink = new PropertyEditorEventsSink();
1261: m_EventsSink.setPropertyEditor(this );
1262: }
1263:
1264: if (m_EventsSink != null) {
1265: //Register for events
1266: helper.registerForWorkspaceEvents(m_EventsSink);
1267: helper.registerForLifeTimeEvents(m_EventsSink);
1268: helper.registerDrawingAreaSelectionEvents(m_EventsSink);
1269: helper.registerDrawingAreaEvents(m_EventsSink);
1270: helper
1271: .registerDrawingAreaCompartmentEvents(m_EventsSink);
1272: helper.registerProjectTreeEvents(m_EventsSink);
1273: helper.registerForTransformEvents(m_EventsSink);
1274: helper.registerForAttributeEvents(m_EventsSink);
1275: helper.registerForOperationEvents(m_EventsSink);
1276: helper.registerForElementModifiedEvents(m_EventsSink);
1277: helper.registerForWSProjectEvents(m_EventsSink);
1278: helper.registerForPreferenceManagerEvents(m_EventsSink);
1279: helper.registerForInitEvents(m_EventsSink);
1280:
1281: m_bSinksConnected = true;
1282:
1283: m_RespondToReload = true;
1284: }
1285: } else if (!bConnect && m_bSinksConnected) {
1286: try {
1287: helper.revokeDrawingAreaSelectionSink(m_EventsSink);
1288: helper.revokeDrawingAreaSink(m_EventsSink);
1289: helper.revokeDrawingAreaCompartmentSink(m_EventsSink);
1290: helper.revokeProjectTreeSink(m_EventsSink);
1291: helper.revokeLifeTimeSink(m_EventsSink);
1292: helper.revokeTransformSink(m_EventsSink);
1293: helper.revokeWorkspaceSink(m_EventsSink);
1294: helper.revokeAttributeSink(m_EventsSink);
1295: helper.revokeOperationSink(m_EventsSink);
1296: helper.revokeElementModifiedSink(m_EventsSink);
1297: helper.revokeWSProjectSink(m_EventsSink);
1298: helper.revokePreferenceManagerSink(m_EventsSink);
1299: helper.revokeInitSink(m_EventsSink);
1300: } catch (InvalidArguments e) {
1301: // TODO Auto-generated catch block
1302: e.printStackTrace();
1303: }
1304:
1305: m_bSinksConnected = false;
1306: }
1307: return 0;
1308: }
1309:
1310: /**
1311: * returns the TreeTable used in this property editor.
1312: */
1313: public Object getGrid() {
1314: return m_Tree;
1315: }
1316:
1317: /**
1318: * Load the passed in IElement into the property editor
1319: *
1320: * @param pElement[in] The element to put into the editor
1321: *
1322: * @return HRESULT
1323: */
1324: public long loadElement(IElement pElement) {
1325: if (PropertyEditorBlocker.inProcess() == false /*&& m_Model != null*/) {
1326: processLastCell(true);
1327: clear();
1328: //
1329: // the property editor is loaded by creating property definitions(which
1330: // represent the structure of the data) and property elements(which represent
1331: // the actual data)
1332: //
1333: String kind = ""; //$NON-NLS-1$
1334: if (pElement instanceof IDiagram) {
1335: kind = "Diagram"; //$NON-NLS-1$
1336: }
1337:
1338: Vector<IPropertyElement> propElems = new Vector<IPropertyElement>();
1339: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
1340: IPropertyElement pEle = processSelectedItem(kind, propDefs,
1341: pElement);
1342: if (pEle != null) {
1343: // since we are coming from the drawing area, we will also want the
1344: // capability of showing the presentation information, so store the
1345: // presentation element on the property element
1346: pEle.setElement(pElement);
1347: propElems.add(pEle);
1348: }
1349: setPropertyDefinitions(propDefs);
1350: setPropertyElements(propElems);
1351: m_CurLoadedObject = pElement;
1352: }
1353: // TODO Auto-generated method stub
1354: return 0;
1355: }
1356:
1357: /**
1358: * Load the passed in IElements into the property editor
1359: *
1360: * @param pElements[in] The elements to put into the editor
1361: *
1362: * @return HRESULT
1363: */
1364: public long loadElements(IElement[] pElements) {
1365: //might want to use m_Tree instead of m_PropertyGrid
1366: if (PropertyEditorBlocker.inProcess() == false
1367: && m_PropertyGrid != null) {
1368: processLastCell(true);
1369: clear();
1370: //
1371: // the property editor is loaded by creating property definitions(which
1372: // represent the structure of the data) and property elements(which represent
1373: // the actual data)
1374: //
1375: int count = pElements.length;
1376:
1377: // get how many should be displayed from preferences
1378: IPreferenceAccessor pref = PreferenceAccessor.instance();
1379: int max = pref.getDefaultEditorSelect();
1380: if (count < max) {
1381: max = count;
1382: }
1383:
1384: Vector<IPropertyElement> propElems = new Vector<IPropertyElement>();
1385: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
1386: // loop through the items selected and build the corresponding definitions and elements
1387: for (int i = 0; i < max; i++) {
1388: // what we have selected from the project tree is a project tree item
1389: IElement pElement = pElements[i];
1390:
1391: // more processing to create the property element
1392: IPropertyElement pEle = processSelectedItem(
1393: "", propDefs, pElement); //$NON-NLS-1$
1394: if (pEle != null) {
1395: propElems.add(pEle);
1396: }
1397: }
1398: setPropertyDefinitions(propDefs);
1399: setPropertyElements(propElems);
1400: }
1401: // TODO Auto-generated method stub
1402: return 0;
1403: }
1404:
1405: /**
1406: * Create the property element that represents whatever is selected from the drawing area or the project tree
1407: *
1408: * @param[in] kind The element type
1409: * @param[in] pDefs The array of property definitions associated with the property editor
1410: * @param[in] pModelElement The model element that is selected
1411: * @param[out] pEle The property element that has been built based on a property definition
1412: *
1413: * @return HRESULT
1414: *
1415: */
1416: public IPropertyElement processSelectedItem(String kind,
1417: Vector<IPropertyDefinition> propDefs, Object pElement) {
1418: IPropertyElement retEle = null;
1419: if (m_Factory != null) {
1420: // get the property definition that represents this kind of model element
1421: // this will create it from the xml file if it hasn't already been created
1422: IPropertyDefinition propDef = m_Factory
1423: .getPropertyDefinitionForElement(kind, pElement);
1424:
1425: if (propDef != null) {
1426: IElement modelElement = null;
1427: if (pElement instanceof IElement) {
1428: modelElement = (IElement) pElement;
1429: }
1430: // if((propDef.getID() != null) && (propDef.getID().length() > 0))
1431: // {
1432: // try {
1433: // Class clazz = Class.forName(propDef.getID());
1434: // Class[] params = null;//{com.embarcadero.com.Dispatch.class};
1435: // Constructor constructor = clazz.getConstructor(params);
1436: //
1437: // Object[] paramInstances = {pElement};
1438: // modelElement = (IElement)constructor.newInstance(paramInstances);
1439: // } catch (Exception e) {}
1440: // }
1441:
1442: // add this to the property editor's property definitions
1443: propDefs.add(propDef);
1444: if (m_PropEleMgr != null) {
1445: // build the property element
1446: m_PropEleMgr.setModelElement(pElement);
1447: m_PropEleMgr.setCreateSubs(true);
1448: IPropertyElement propEle = m_PropEleMgr
1449: .buildTopPropertyElement(propDef);
1450: if (propEle != null) {
1451: propEle.setElement(pElement);
1452: // now that we have built the property element structure
1453: // check the definition filter to see if any of the elements need to
1454: // change
1455: filterPropertyElement(propEle);
1456: retEle = propEle;
1457: m_CurLoadedObject = modelElement;
1458: }
1459: }
1460: }
1461: }
1462: return retEle;
1463: }
1464:
1465: /**
1466: * Filter the property element based on an xml file that has been predefined
1467: * by the user
1468: *
1469: *
1470: * @param pEle[in] The property element to filter
1471: *
1472: * @return HRESULT
1473: *
1474: */
1475: private void filterPropertyElement(IPropertyElement pEle) {
1476: // check the preference to see if we should filter or not
1477: //kris richards - "LanguageFilter" pref expunged. Set to true. Condition removed.
1478:
1479: // this guy does the filtering
1480: IPropertyDefinitionFilter pFilter = new PropertyDefinitionFilter();
1481: // get the element from the property element
1482: Object pDisp = pEle.getElement();
1483: if (pDisp instanceof IElement) {
1484: IElement pModEle = (IElement) pDisp;
1485: // from the element we should be able to tell what language it is
1486: ILanguage lang = getActiveLanguage(pModEle);
1487: if (lang != null) {
1488: pFilter.filterPropertyElement(pEle);
1489: } else {
1490: // if the element is new, it may not have a language just yet, so
1491: // get the top most property element's model element and use that
1492: // as the guy to figure out the language filter
1493: Object pTop = getTopModelElement(pEle);
1494: if (pTop instanceof IElement) {
1495: IElement parentEle = (IElement) pTop;
1496: pFilter.filterPropertyElementBasedOnModelElement(
1497: pEle, parentEle);
1498: }
1499: }
1500: } else {
1501: // there is not a model element on the property element, so
1502: // get the top most property element's model element and use that
1503: // as the guy to figure out the language filter
1504: Object pTop = getTopModelElement(pEle);
1505: if (pTop instanceof IElement) {
1506: IElement parentEle = (IElement) pTop;
1507: pFilter.filterPropertyElementBasedOnModelElement(pEle,
1508: parentEle);
1509: }
1510: }
1511:
1512: }
1513:
1514: /**
1515: * Retrieves a model elements associated language. If the model element
1516: * is associated to more than one language then the first language is the
1517: * active language.
1518: *
1519: * @param pElement [in] The element being processed.
1520: * @param pVal [out] The active language for the element.
1521: */
1522: private ILanguage getActiveLanguage(IElement pElement) {
1523: ILanguage retLang = null;
1524: // Find the first language that is supported by the element. If the
1525: // is not supporting any languages (Should never happen) get the
1526: // default langauge.
1527: ETList<ILanguage> langs = pElement.getLanguages();
1528: // if (langs != null && langs.length > 0)
1529: if (langs != null && langs.size() > 0) {
1530: retLang = langs.get(0);
1531: }
1532: return retLang;
1533: }
1534:
1535: /**
1536: * Method to navigate up the property element chain to retrieve the top model element in the chain
1537: *
1538: * @param[in] pEle The property element in which to get the model element
1539: * @param[out] pModEle The model element
1540: *
1541: * @return HRESULT
1542: *
1543: */
1544: private Object getTopModelElement(IPropertyElement pEle) {
1545: Object retObj = null;
1546: if (pEle != null) {
1547: // get the model element
1548: Object pDisp = pEle.getElement();
1549: // get the parent of this property element
1550: IPropertyElement parentEle = pEle.getParent();
1551: if (parentEle != null) {
1552: retObj = getTopModelElement(parentEle);
1553: } else {
1554: retObj = pDisp;
1555: }
1556: }
1557: return retObj;
1558: }
1559:
1560: /**
1561: * Because we have changed the way that we do a save - save now on leaving a field
1562: * or if in a new property (attribute/operation), save when we leave that particular
1563: * property, we need to determine whether or not to save the last cell that we were on
1564: *
1565: * I think it needs to be called only when a new element is selected and I need to save
1566: * the record.
1567: *
1568: * @return HRESULT
1569: *
1570: */
1571: public void processLastCell(boolean elementChanged) {
1572: processLastCell(elementChanged, m_LastRow);
1573: }
1574:
1575: public void processLastCell(boolean elementChanged, int row) {
1576: if (m_Model != null && row != 0) {
1577: int lastRow = row;
1578:
1579: // get the element at the previous row
1580: IColorProperty pColorProperty = getColorPropertyAtGridRow(lastRow);
1581: IFontProperty pFontProperty = getFontPropertyAtGridRow(lastRow);
1582: JDefaultMutableTreeNode node = getNodeAtGridRow(lastRow);
1583: IPropertyElement nodeEle = getElementAtGridRow(lastRow);
1584:
1585: if (node != null) {
1586: if (node != null) {
1587: //
1588: // Update the information in the elements, grid, and xml
1589: // This may cause both a create and a set, or just a set
1590: //
1591: boolean mod = nodeEle.getModified();
1592: if (mod) {
1593: // get the model element at the previous row
1594: Object pLastDisp = nodeEle.getElement();
1595:
1596: // get the definition of the element on the last row
1597: IPropertyDefinition pDef = nodeEle
1598: .getPropertyDefinition();
1599:
1600: // Block events from coming in.
1601: PropertyEditorBlocker.block();
1602: try {
1603: setRowData(lastRow, pDef, nodeEle);
1604:
1605: // update the grid nodes
1606: if (node != null) {
1607: updateNodeAndParentNodes(node, nodeEle);
1608: }
1609: nodeEle.setModified(false);
1610: } finally {
1611: PropertyEditorBlocker.unblock();
1612: }
1613: }
1614: }
1615:
1616: //
1617: // Now we need to determine if we need to do an insert of the information that
1618: // was just created or set
1619: //
1620: if (node != null) {
1621: JDefaultMutableTreeNode lastRecNode = getGridNodeMarkedAsRecord(node);
1622:
1623: //I want the current node to pass to the insertNecessary
1624: node = getNodeAtGridRow(m_CurRow);
1625:
1626: while (lastRecNode != null) {
1627: //if the element selection has changed or
1628: if (elementChanged
1629: || insertNecessary(node, lastRecNode)) {
1630: insert(lastRecNode);
1631: }
1632: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) lastRecNode
1633: .getParent();
1634: lastRecNode = getGridNodeMarkedAsRecord(parentNode);
1635: }
1636:
1637: if (m_Reordered) {
1638: reorderFeatures();
1639: m_Reordered = false;
1640: }
1641:
1642: if (row > 0) {
1643: // Block events from coming in.
1644: PropertyEditorBlocker.block();
1645: try {
1646: // Now we need to see if we need to pop the operation signature context
1647: IPropertyElement pCurPropEle = getElementAtGridRow(row);
1648: if (pCurPropEle != null) {
1649: if (m_SigChange != null) {
1650: IOperation pOldOp = m_SigChange
1651: .getOperation();
1652: IOperation pNewOp = getOperationFromPropertyElement(pCurPropEle);
1653: if (pOldOp != null
1654: && pNewOp != null) {
1655: boolean isSame = pOldOp
1656: .isSame(pNewOp);
1657: if (!isSame) {
1658: endSignatureChange();
1659: }
1660: } else {
1661: endSignatureChange();
1662: }
1663: }
1664: } else {
1665: endSignatureChange();
1666: }
1667: } finally {
1668: PropertyEditorBlocker.unblock();
1669: }
1670: }
1671: }
1672: m_processingRecord = false;
1673: } else if (pColorProperty != null) {
1674: // boolean modified = pColorProperty.isModified();
1675: // if (modified)
1676: // {
1677: // pColorProperty.save();
1678: // }
1679: // }
1680: // else if (pFontProperty != null)
1681: // {
1682: // boolean modified = pFontProperty.isModified();
1683: // if (modified)
1684: // {
1685: // pFontProperty.save();
1686: // }
1687: }
1688: }
1689: }
1690:
1691: public void saveCellValueAt(int row, String newVal) {
1692: if (m_Model != null && row != 0) {
1693: // get the element at the previous row
1694: IPropertyElement lastPropEle = getElementAtGridRow(row);
1695:
1696: if (lastPropEle != null) {
1697: //
1698: // Update the information in the elements, grid, and xml
1699: // This may cause both a create and a set, or just a set
1700: //
1701: boolean mod = lastPropEle.getModified();
1702: if (mod) {
1703: // get the model element at the previous row
1704: Object pLastDisp = lastPropEle.getElement();
1705:
1706: // update the property element
1707: updatePropertyElementValue(row, lastPropEle, newVal);
1708:
1709: // get the definition of the element on the last row
1710: IPropertyDefinition pDef = lastPropEle
1711: .getPropertyDefinition();
1712:
1713: // Block events from coming in.
1714: //PropertyEditorBlocker.block();
1715:
1716: setRowData(row, pDef, lastPropEle);
1717:
1718: // update the grid nodes
1719: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
1720: if (node != null) {
1721: updateNodeAndParentNodes(node, lastPropEle);
1722: }
1723: lastPropEle.setModified(false);
1724: }
1725:
1726: }
1727: }
1728: }
1729:
1730: /**
1731: * Update the value on the property element
1732: *
1733: * @param[in] Row The row that was just edited
1734: * @param[in] pEle The property element to update
1735: *
1736: * @return HRESULT
1737: *
1738: */
1739: private void updatePropertyElementValue(int row,
1740: IPropertyElement pEle) {
1741: // get the corresponding definition
1742: if (m_Tree != null) {
1743: IPropertyDefinition pDef = pEle.getPropertyDefinition();
1744: if (pDef != null) {
1745: String value = (String) m_Tree.getValueAt(row, 2);
1746:
1747: //
1748: // if the user has chosen something from a list box or a combo box, get its index
1749: // because most things in the listbox are represented by an enumeration, we need to
1750: // determine what that enumeration is, so that we can set the property element value
1751: // to the proper thing
1752: //
1753: String values = pDef.getValidValues();
1754: if (values != null && values.length() > 0) {
1755: // there could be an enumeration, so further check
1756: int pos = values.indexOf("//"); //$NON-NLS-1$
1757: if (pos >= 0) {
1758: // xpath string
1759: pEle.setValue(value);
1760: } else {
1761: pos = values.indexOf("#DataTypeList"); //$NON-NLS-1$
1762: if (pos >= 0) {
1763: // we now have to be smart and if the user has set this preference
1764: // to use fully qualified names in the picklist, we actually want
1765: // to be setting the type to the qualified name, not just int, pack1::pack1a::int
1766: // so this needs to get the information from the listbox
1767: boolean useQName = getDataTypePreference();
1768: if (useQName) {
1769: // use fully qualified name, so get the index of the selected item in the
1770: // combo box
1771:
1772: //This is complicated, need to understand and implement
1773: }
1774: } else {
1775: // enumeration, so store the index in the property element
1776: IEnumTranslator enumTranslator = new EnumTranslator();
1777: String enumValues = pDef
1778: .getFromAttrMap("enumValues"); //$NON-NLS-1$
1779: int num = enumTranslator.translateToEnum(
1780: value, values, enumValues);
1781: if (num != -999) {
1782: pEle.setValue(Integer.toString(num));
1783: } else {
1784: pEle.setValue(value);
1785: }
1786: }
1787: }
1788: } else {
1789: pEle.setValue(value);
1790: }
1791: }
1792: pEle.setModified(true);
1793: }
1794: }
1795:
1796: private void updatePropertyElementValue(int row,
1797: IPropertyElement pEle, String newVal) {
1798: if (newVal == null) {
1799: updatePropertyElementValue(row, pEle);
1800: }
1801: // get the corresponding definition
1802: IPropertyDefinition pDef = pEle.getPropertyDefinition();
1803: if (pDef != null) {
1804: String value = newVal;
1805:
1806: //
1807: // if the user has chosen something from a list box or a combo box, get its index
1808: // because most things in the listbox are represented by an enumeration, we need to
1809: // determine what that enumeration is, so that we can set the property element value
1810: // to the proper thing
1811: //
1812: String values = pDef.getValidValues();
1813: if (values != null && values.length() > 0) {
1814: // there could be an enumeration, so further check
1815: int pos = values.indexOf("//"); //$NON-NLS-1$
1816: if (pos >= 0) {
1817: // xpath string
1818: pEle.setValue(value);
1819: } else {
1820: pos = values.indexOf("#DataTypeList"); //$NON-NLS-1$
1821: if (pos >= 0) {
1822: // we now have to be smart and if the user has set this preference
1823: // to use fully qualified names in the picklist, we actually want
1824: // to be setting the type to the qualified name, not just int, pack1::pack1a::int
1825: // so this needs to get the information from the listbox
1826: boolean useQName = getDataTypePreference();
1827: if (useQName) {
1828: // use fully qualified name, so get the index of the selected item in the
1829: // combo box
1830:
1831: //This is complicated, need to understand and implement
1832: }
1833: } else {
1834: // enumeration, so store the index in the property element
1835: IEnumTranslator enumTranslator = new EnumTranslator();
1836: String enumValues = pDef
1837: .getFromAttrMap("enumValues"); //$NON-NLS-1$
1838: int num = enumTranslator.translateToEnum(value,
1839: values, enumValues);
1840: if (num != -999) {
1841: pEle.setValue(Integer.toString(num));
1842: } else {
1843: pEle.setValue(value);
1844: }
1845: }
1846: }
1847: } else {
1848: pEle.setValue(value);
1849: }
1850: }
1851: pEle.setModified(true);
1852: }
1853:
1854: /**
1855: * Retrieves the datatype preference from the preference manager
1856: *
1857: *
1858: * @param pref[out] Whether or not to display the fully qualified name in the datatype picklist
1859: *
1860: * @return HRESULT
1861: *
1862: */
1863: private boolean getDataTypePreference() {
1864: //kris richards - "DisplayTypeFSN" pref removed. Set to true
1865: return true;
1866: }
1867:
1868: /**
1869: * Special processing to reorder parameters
1870: * @return HRESULT
1871: *
1872: */
1873: private void reorderFeatures() {
1874: // only doing this for parameters at this time
1875: // we are not set up to do it generically for "features"
1876: ETList<IParameter> pFeatures = new ETArrayList<IParameter>();
1877:
1878: // get the grid node that is at the last row we just processed
1879: JDefaultMutableTreeNode pNode = getNodeAtGridRow(m_LastRow);
1880: if (pNode != null) {
1881: // get the collection grid node for the last row we just processed
1882: JDefaultMutableTreeNode colNode = getCollectionGridNode(
1883: pNode, 0);
1884: if (colNode != null) {
1885: // get the property element at the row of the collection node
1886: IPropertyElement colEle = (IPropertyElement) colNode
1887: .getUserObject();
1888: if (colEle != null) {
1889: // loop through the grid nodes under the collection
1890: DefaultMutableTreeNode child = (DefaultMutableTreeNode) colNode
1891: .getFirstChild();
1892: while (child != null) {
1893: IPropertyElement pEle = (IPropertyElement) child
1894: .getUserObject();
1895: if (pEle != null) {
1896: // if the property element contains a parameter, add it to
1897: // our temporary list
1898: Object pDisp = pEle.getElement();
1899: if (pDisp instanceof IParameter) {
1900: IParameter pFeat = (IParameter) pDisp;
1901: String temp = pFeat.getName();
1902: pFeatures.add(pFeat);
1903: }
1904: child = child.getNextSibling();
1905: } else {
1906: child = null;
1907: }
1908: }
1909: //
1910: // now we should have a new array of parameters in the correct order
1911: // according to the user
1912: //
1913: Object pDisp2 = colEle.getElement();
1914: if (pDisp2 instanceof IOperation) {
1915: IOperation pOp = (IOperation) pDisp2;
1916: // so set it on the operation
1917: pOp.setFormalParameters(pFeatures);
1918: }
1919: }
1920: }
1921: }
1922: }
1923:
1924: /**
1925: * Method to navigate up the grid node chain to retrieve the grid node that represents
1926: * the record that the passed in grid node is in.
1927: *
1928: * @param[in] pNode The grid node in which to get the record grid node that it belongs to
1929: * @param[out] pCollectionNode The grid node that is the record node
1930: *
1931: * @return HRESULT
1932: *
1933: */
1934: private JDefaultMutableTreeNode getGridNodeMarkedAsRecord(
1935: JDefaultMutableTreeNode node) {
1936: JDefaultMutableTreeNode retNode = null;
1937: if (node != null) {
1938: String key = node.getKey();
1939: if (key != null && key.equals("RecordNew")) //$NON-NLS-1$
1940: {
1941: retNode = node;
1942: } else {
1943: JDefaultMutableTreeNode parent = (JDefaultMutableTreeNode) node
1944: .getParent();
1945: if (parent != null) {
1946: retNode = getGridNodeMarkedAsRecord(parent);
1947: }
1948: }
1949: }
1950:
1951: return retNode;
1952: }
1953:
1954: /**
1955: * Calls the insert method of the property element
1956: *
1957: *
1958: * @param row[in] The grid row that we are dealing with
1959: *
1960: * @return HRESULT
1961: */
1962: private void insert(JDefaultMutableTreeNode lastRecNode) {
1963: if (m_Model != null) {
1964: int lastRow = m_LastRow;//m_Tree.getRowCount();
1965: IPropertyElement lastPropEle = getElementAtGridRow(lastRow);
1966: JDefaultMutableTreeNode lastNode = getNodeAtGridRow(lastRow);
1967: if (lastPropEle != null && lastRecNode != null) {
1968: IPropertyElement pEle = (IPropertyElement) lastRecNode
1969: .getUserObject();
1970: if (pEle != null) {
1971: IPropertyElement colEle = getCollectionElement(pEle);
1972: if (colEle != null) {
1973: IPropertyDefinition pDef = pEle
1974: .getPropertyDefinition();
1975: Object pDisp2 = colEle.getElement();
1976: if (pDisp2 != null) {
1977: // continue with the add
1978: PropertyEditorBlocker.block();
1979: try {
1980: m_PropEleMgr.insertData(pDisp2, pDef,
1981: pEle);
1982:
1983: // we are having problems in RT when dealing with the sets of an operation
1984: // the change events cannot handle single changes to the signature
1985: // a context was created to handle this and was being used by everything
1986: // but the property editor, so now we are special casing an operation
1987: // and have a context set up, so now before we "Add" the operation
1988: // we need to pop the context
1989: Object pDisp3 = pEle.getElement();
1990: if (lastNode != null) {
1991: updateNodeAndParentNodes(lastNode,
1992: lastPropEle);
1993: JDefaultMutableTreeNode pLastRecNode = getGridNodeMarkedAsRecord(lastNode);
1994: if (pLastRecNode != null) {
1995: pLastRecNode.setKey("Record"); //$NON-NLS-1$
1996: pLastRecNode.setExpanded(false);
1997: }
1998: }
1999: pEle.setModified(false);
2000: } finally {
2001: PropertyEditorBlocker.unblock();
2002: }
2003: } else {
2004: Object pDisp = getModelElement(colEle);
2005: PropertyEditorBlocker.block();
2006: try {
2007: m_PropEleMgr.insertData(pDisp, pDef,
2008: pEle);
2009:
2010: if (lastNode != null) {
2011: updateNodeAndParentNodes(lastNode,
2012: lastPropEle);
2013: //JDefaultMutableTreeNode pLastRecNode = getGridNodeMarkedAsRecord(lastNode);
2014: if (lastRecNode != null) {
2015: lastRecNode.setKey("Record"); //$NON-NLS-1$
2016: lastRecNode.setExpanded(false);
2017: }
2018: }
2019: pEle.setModified(false);
2020: } finally {
2021: PropertyEditorBlocker.unblock();
2022: }
2023: }
2024: }
2025: }
2026: }
2027: }
2028: }
2029:
2030: /**
2031: * Determines whether or not we need to call the insert function for a particular element
2032: *
2033: *
2034: * @param pCurrNode[in] The current grid node
2035: * @param pLastRecNode[in] The last grid node that we were in
2036: *
2037: * @return bool
2038: */
2039: private boolean insertNecessary(JDefaultMutableTreeNode node,
2040: JDefaultMutableTreeNode lastRecNode) {
2041: boolean retVal = false;
2042: if (node != null && lastRecNode != null) {
2043: JDefaultMutableTreeNode curRecNode = getGridNodeMarkedAsRecord(node);
2044: if (curRecNode == null) {
2045: retVal = true;
2046: } else {
2047: int curLevel = curRecNode.getLevel();
2048: int lastLevel = lastRecNode.getLevel();
2049: if (curLevel > lastLevel) {
2050: } else if (curLevel == lastLevel) {
2051: int curRow = m_CurRow;//curRecNode.getRow();
2052: int lastRow = m_LastRow;//lastRecNode.getRow();
2053: if (curRow != lastRow) {
2054: //in our case since we do not know where the user clicked next, we cannot say
2055: //that we need to insert. I will decide that when I know where the user clicked
2056: //next in TreeTableCellEditor
2057: //retVal = true;
2058: }
2059: } else {
2060: retVal = true;
2061: }
2062: }
2063: }
2064: return retVal;
2065: }
2066:
2067: /* (non-Javadoc)
2068: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#resetGridSettings()
2069: */
2070: public long resetGridSettings() {
2071: // TODO Auto-generated method stub
2072: return 0;
2073: }
2074:
2075: /* (non-Javadoc)
2076: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#resetGridFilter()
2077: */
2078: public long resetGridFilter() {
2079: // TODO Auto-generated method stub
2080: return 0;
2081: }
2082:
2083: /* (non-Javadoc)
2084: * @see org.netbeans.modules.uml.ui.swing.propertyeditor.IPropertyEditor#getWindowHandle()
2085: */
2086: public int getWindowHandle() {
2087: // TODO Auto-generated method stub
2088: return 0;
2089: }
2090:
2091: /**
2092: * Ask the user what to do about a name collision
2093: *
2094: * @param pElement [in] The element being renamed
2095: * @param sProposedName [in] The new name
2096: * @param pFirstCollidingElement [in] The first colliding element
2097: * @param pCell [in] The result cell. Used to cancel the rename.
2098: */
2099: public long questionUserAboutNameCollision(INamedElement pElement,
2100: String sProposedName, INamedElement pFirstCollidingElement,
2101: IResultCell pCell) {
2102: if (pFirstCollidingElement != null && pElement != null
2103: && pCell != null) {
2104: // Ask the user if he wants to reconnect the presentation element to a different model element
2105: IQuestionDialog pDiag = new SwingQuestionDialogImpl();
2106: if (pDiag != null) {
2107: String title = PropertyEditorResources
2108: .getString("PropertyEditor.NameCollisionTitle");
2109: String msg = PropertyEditorResources
2110: .getString("PropertyEditor.NameCollision");
2111: QuestionResponse result = pDiag
2112: .displaySimpleQuestionDialog(
2113: SimpleQuestionDialogKind.SQDK_YESNO,
2114: MessageIconKindEnum.EDIK_ICONWARNING,
2115: msg, 0, null, title);
2116: if (result.getResult() == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
2117: // User wants to allow the name collision.
2118: } else if (result.getResult() == SimpleQuestionDialogResultKind.SQDRK_RESULT_NO) {
2119: // Cancel the editing to abort the name collision
2120: pCell.setContinue(false);
2121: }
2122: }
2123: }
2124: return 0;
2125: }
2126:
2127: /**
2128: * Tells the listener we've got as a member that it was us that began editing
2129: */
2130: public long beginEditContext() {
2131: if (m_NameCollisionListener != null) {
2132: m_NameCollisionListener.setEnabled(true);
2133: }
2134: return 0;
2135: }
2136:
2137: /**
2138: * Tells the listener we've got as a member that we're done editing
2139: */
2140: public void endEditContext() {
2141: if (m_NameCollisionListener != null) {
2142: m_NameCollisionListener.setEnabled(false);
2143: }
2144: }
2145:
2146: /**
2147: * Whether or not the property editor should respond to an event and reload its information.
2148: * We were running into performance issues from within some of the processes (ie. ERStudioIntegration
2149: * and DesignPattern Apply) where the property editor is receiving events, but we really don't want it
2150: * to try and figure out if it should reload, so this flag will be checked and short circuit the check.
2151: *
2152: * @param[out] pVal The flag for whether or not a diagram should be created
2153: *
2154: * @return HRESULT
2155: */
2156: public boolean getRespondToReload() {
2157: return m_RespondToReload;
2158: }
2159:
2160: public void setRespondToReload(boolean value) {
2161: m_RespondToReload = value;
2162: }
2163:
2164: /**
2165: * Figure out how we should present the property element to the user as far as whether the grid
2166: * node is read-only or not
2167: *
2168: * @param[in] pDef The property definition associated with the property element
2169: * @param[in] pEle The property element to be used
2170: *
2171: * @return BOOL If it is read only or not
2172: *
2173: */
2174: private boolean isReadOnlyStatus(IPropertyDefinition pDef,
2175: IPropertyElement pEle) {
2176: boolean isReadOnly = false;
2177: String controlType = pDef.getControlType();
2178: long mult = pDef.getMultiplicity();
2179: if (mult > 1) {
2180: // collections are read only
2181: if (controlType != null && controlType.equals("read-only")) //$NON-NLS-1$
2182: {
2183: isReadOnly = true;
2184: }
2185: } else {
2186: // property definitions that have not told us what their type is or that they are read only
2187: // should be marked as read only
2188: if (controlType == null || controlType.length() == 0
2189: || controlType.equals("read-only")) //$NON-NLS-1$
2190: {
2191: isReadOnly = true;
2192: } else {
2193: boolean bEdit = isElementEditable(pEle, pDef);
2194: if (!bEdit) {
2195: isReadOnly = true;
2196: }
2197: }
2198: }
2199: return isReadOnly;
2200: }
2201:
2202: /**
2203: * Figure out how we should present the property element to the user as far as whether the grid
2204: * node is bold or not
2205: *
2206: * @param[in] pDef The property definition associated with the property element
2207: * @param[in] pEle The property element to be used
2208: *
2209: * @return BOOL If it is bold or not
2210: *
2211: */
2212: private boolean isBold(IPropertyDefinition pDef,
2213: IPropertyElement pEle) {
2214: boolean bold = false;
2215: long mult = pDef.getMultiplicity();
2216: if (mult > 1) {
2217: // collections are bold
2218: bold = true;
2219: } else {
2220: String values = pDef.getValidValues();
2221: if (values != null && values.length() > 0) {
2222: int pos = values.indexOf("FormatString"); //$NON-NLS-1$
2223: if (pos >= 0) {
2224: bold = true;
2225: }
2226: }
2227: }
2228: return bold;
2229: }
2230:
2231: /**
2232: * Determines whether or not this property element should be editable. There are some cases
2233: * that we know going in that it is not editable (ie. versioned file name). There are other
2234: * cases that we want it to not be editable if it is a certain value. In these cases, we
2235: * need to mark the definition, so that we know who to ask.
2236: *
2237: *
2238: * @param pEle[in] The property element in question
2239: * @param pDef[in] The property definition of the property element in question
2240: * @param bEdit[out] Whether or not this property element is editable
2241: *
2242: * @return HRESULT
2243: *
2244: */
2245: private boolean isElementEditable(IPropertyElement pEle,
2246: IPropertyDefinition pDef) {
2247: boolean bEdit = true;
2248: String value = pEle.getValue();
2249: if (value != null && value.length() > 0) {
2250: String cType = pDef.getControlType();
2251: if (cType != null && cType.equals("read-only")) //$NON-NLS-1$
2252: {
2253: String pdName = pDef.getName();
2254: String parentName = ""; //$NON-NLS-1$
2255: IPropertyDefinition parentDef = pDef.getParent();
2256: if (parentDef != null) {
2257: parentName = parentDef.getName();
2258: }
2259: if (pdName.equals("ReferredElement") || pdName.equals("ReferencingElement")) //$NON-NLS-1$ //$NON-NLS-2$
2260: {
2261: } else if (parentName.equals("AssociatedDiagrams") || parentName.equals("AssociatedElements")) //$NON-NLS-1$ //$NON-NLS-2$
2262: {
2263: } else {
2264: bEdit = false;
2265: }
2266: } else {
2267: // get the validate information from the definition
2268: String validM = pDef.getFromAttrMap("validate"); //$NON-NLS-1$
2269: if (validM != null && validM.length() > 0) {
2270: // if the string in the validate is not a progID (Foundation.Project)
2271: // then check to see if it is a GUID ({123-456})
2272: // there are two ways to invoke the validate, if it is a progID
2273: // then we cocreate it, cast it to a ICustomValidator, and call Validate
2274: // if it is a GUID, we cast the IDispatch that we have on the property element
2275: // to a ICustomValidator, and call Validate
2276: try {
2277: Class progIDClass = Class.forName(validM);
2278: Object progIDObj = progIDClass.newInstance();
2279: if (progIDObj instanceof ICustomValidator) {
2280: ICustomValidator pValidator = (ICustomValidator) progIDObj;
2281: String name = pDef.getName();
2282: bEdit = pValidator.validate(pEle, name,
2283: value);
2284: }
2285: } catch (ClassNotFoundException cExp) {
2286: Object obj = pEle.getElement();
2287: if (obj != null) {
2288: if (obj instanceof ICustomValidator) {
2289: ICustomValidator pValidator = (ICustomValidator) obj;
2290: String name = pDef.getName();
2291: bEdit = pValidator.validate(pEle, name,
2292: value);
2293: }
2294: }
2295: } catch (Exception e) {
2296: }
2297: }
2298: }
2299: }
2300: return bEdit;
2301: }
2302:
2303: /**
2304: * Display the proper menu in the grid based on where the user has clicked
2305: *
2306: * @param[in] pDef The property definition used to help determine what menu to display
2307: * @param[in] pEle The property element used to help determine what menu to display
2308: *
2309: * @return HRESULT
2310: *
2311: */
2312: public String[] showMenuBasedOnDefinition(IPropertyDefinition pDef,
2313: IPropertyElement pEle) {
2314: String[] retMenuItems = null;
2315: int menuNum = 0;
2316: //To Do
2317: if (pDef != null) {
2318: long mult = pDef.getMultiplicity();
2319: String type = pDef.getControlType();
2320: String pdName = pDef.getName();
2321: String parentName = ""; //$NON-NLS-1$
2322: IPropertyDefinition parentDef = pDef.getParent();
2323: if (parentDef != null) {
2324: parentName = parentDef.getName();
2325: }
2326: if (pdName.equals("ReferredElement") || //$NON-NLS-1$
2327: pdName.equals("ReferencingElement")) //$NON-NLS-1$
2328: {
2329: // totally special processing for referred/referencing elements
2330: // couldn't get it to work the generic way because we only wanted to show the opposite
2331: // element of the reference, and we wanted its value to be placed on the top level (read-only)
2332: // and values string in propDef, but we wanted to only have a right-click delete, no create
2333: if (parentDef != null) {
2334: String delMeth = parentDef.getDeleteMethod();
2335: if (delMeth != null && delMeth.length() > 0) {
2336: menuNum = 7;
2337: }
2338: }
2339: } else if (pdName.equals("SourceFileArtifact")) //$NON-NLS-1$
2340: {
2341: menuNum = 3;
2342: } else if (parentName.equals("AssociatedDiagrams") || //$NON-NLS-1$
2343: parentName.equals("AssociatedElements")) //$NON-NLS-1$
2344: {
2345: menuNum = 7;
2346: } else {
2347: // if it isn't marked as read only
2348: if (type == null || !type.equals("read-only")) //$NON-NLS-1$
2349: {
2350: // if the node that we are on is a collection, may want to display the create menu
2351: if (mult > 1) {
2352: String putM = pDef.getSetMethod();
2353: Vector<IPropertyElement> subEles = pEle
2354: .getSubElements();
2355: long count = subEles.size();
2356: if ((putM == null)
2357: || (putM.length() == 0)
2358: || ((putM.length() > 0) && (count == 0))) {
2359: menuNum = 1;
2360: }
2361: } else {
2362: // if it isn't a multiple definition(cannot have records), the user may have clicked in one of the
2363: // subs, which we still want them to be able to create from within there
2364: IPropertyElement collectionEle = getCollectionElement(pEle);
2365: if (collectionEle != null) {
2366: // show the create/delete menu
2367: // only show delete if it is editable
2368: boolean bEdit = isElementEditable(pEle,
2369: pDef);
2370: if (bEdit) {
2371: // now if we are on a attribute/operation/parameter
2372: // then show the insert menu button as well
2373: String insertBefore = pDef
2374: .getFromAttrMap("insertBefore"); //$NON-NLS-1$
2375: if (insertBefore != null
2376: && insertBefore.length() > 0) {
2377: menuNum = 6;
2378: } else {
2379: menuNum = 2;
2380: }
2381: } else {
2382: menuNum = 5;
2383: }
2384: } else {
2385: // not a collection, and not a member of a collection
2386: // so may want to show the fill down menu (if in that mode)
2387: boolean show = showFilldownMenuItem();
2388: if (show) {
2389: menuNum = 0;
2390: }
2391: }
2392: }
2393: }
2394: }
2395: }
2396: IProxyUserInterface pUI = ProductHelper.getProxyUserInterface();
2397:
2398: //ETSystem.out.println("Going to show menu for " + menuNum);
2399: // have figured out what menu, so display it
2400: if (menuNum > -1) {
2401: if (pUI != null)
2402: pUI.setDisableContextMenu(true);
2403:
2404: if (m_MenuItems != null && m_MenuItems.length > menuNum) {
2405: String[] menuItems = m_MenuItems[menuNum];
2406: if (menuItems != null) {
2407: retMenuItems = menuItems;
2408: }
2409: }
2410:
2411: if (pUI != null)
2412: pUI.setDisableContextMenu(false);
2413: } else {
2414: if (pUI != null)
2415: pUI.setDisableContextMenu(true);
2416: }
2417: return retMenuItems;
2418: }
2419:
2420: /**
2421: * Method to navigate up the property element chain to retrieve the element that represents
2422: * the collection that the passed in property element is in.
2423: *
2424: * @param[in] pEle The property element in which to get the collection element that it belongs to
2425: * @param[out] pInsertEle The property element that is the collection element
2426: *
2427: * @return HRESULT
2428: *
2429: */
2430: private IPropertyElement getCollectionElement(IPropertyElement pEle) {
2431: IPropertyElement retEle = null;
2432: IPropertyDefinition pDef = pEle.getPropertyDefinition();
2433: if (pDef != null) {
2434: // if the element has a property definition that is multiple, then we have found it
2435: long mult = pDef.getMultiplicity();
2436: String controlType = pDef.getControlType();
2437: if (mult > 1) {
2438: if (controlType == null
2439: || !controlType.equals("read-only")) //$NON-NLS-1$
2440: {
2441: retEle = pEle;
2442: }
2443: } else {
2444: IPropertyElement parentEle = pEle.getParent();
2445: if (parentEle != null) {
2446: retEle = getCollectionElement(parentEle);
2447: }
2448: }
2449: }
2450: return retEle;
2451: }
2452:
2453: /**
2454: * Determines whether or not the Fill menu should be displayed
2455: *
2456: */
2457: private boolean showFilldownMenuItem() {
2458: boolean show = false;
2459: if (m_Mode == EDITOR_SEL) {
2460: show = true;
2461: }
2462: return show;
2463: }
2464:
2465: public void actionPerformed(ActionEvent e) {
2466: Object source = e.getSource();
2467: if (source instanceof JComboBox) {
2468: JComboBox box = (JComboBox) source;
2469: onSelChangeFilterCombo();
2470: Object selItem = box.getSelectedItem();
2471: }
2472:
2473: }
2474:
2475: /**
2476: * Called when the user changes the selection in the listbox
2477: *
2478: * @param[in] wNotifyCode
2479: * @param[in] wID
2480: * @param[in] hWndCtrl
2481: * @param[out] bHandled
2482: *
2483: * @return LRESULT
2484: */
2485: public void onSelChangeFilterCombo() {
2486: if (m_FilterCombo != null && m_Tree != null) {
2487: // set up the mode that the property editor is in
2488: String str = m_FilterCombo.getSelectedItem().toString();
2489: setModeBasedOnCombo();
2490: if (str.equals("...")) //$NON-NLS-1$
2491: {
2492: m_Filter.showFilterDialog();
2493: String str1 = m_Filter.getCurrentSelection();
2494: if (str1 != null && !str1.equals("")) //$NON-NLS-1$
2495: {
2496: //need to make sure that duplicate items are not added
2497: boolean bFound = false;
2498: int size = m_FilterCombo.getItemCount();
2499: for (int j = 0; j < size; j++) {
2500: String tempStr = m_FilterCombo.getItemAt(j)
2501: .toString();
2502: if (str1.equals(tempStr)) {
2503: bFound = true;
2504: break;
2505: }
2506: }
2507: if (!bFound) {
2508: m_FilterCombo.addItem(str1);
2509: }
2510: m_FilterCombo.setSelectedItem(str1);
2511: }
2512: } else {
2513: m_Filter.setCurrentSelection(str);
2514: }
2515: setModeBasedOnCombo();
2516: Object obj = m_Tree.getTree().getModel().getRoot();
2517: if (obj != null && obj instanceof JDefaultMutableTreeNode) {
2518: //We want to get all the child nodes of this root node and
2519: //refresh them.
2520: JDefaultMutableTreeNode rootNode = (JDefaultMutableTreeNode) obj;
2521: int count = rootNode.getChildCount();
2522: for (int i = 0; i < count; i++) {
2523: JDefaultMutableTreeNode node = (JDefaultMutableTreeNode) rootNode
2524: .getChildAt(i);
2525: Object obj1 = node.getUserObject();
2526: if (obj1 != null
2527: && obj1 instanceof IPropertyElement) {
2528: IPropertyElement ele = (IPropertyElement) obj1;
2529: refreshRootNode(ele, node);
2530: }
2531: }
2532: }
2533: }
2534: }
2535:
2536: private void setModeBasedOnCombo() {
2537: if (m_FilterCombo != null) {
2538: // set up the mode that the property editor is in
2539: String str = m_FilterCombo.getSelectedItem().toString();
2540: ConfigStringTranslator trans = new ConfigStringTranslator();
2541: String all = trans.translate(null, "PSK_ALL"); //$NON-NLS-1$
2542: String pres = trans.translate(null, "PSK_PRESENTATION"); //$NON-NLS-1$
2543: String data = trans.translate(null, "PSK_DATA"); //$NON-NLS-1$
2544: if (str.equals(all)) {
2545: m_Mode = EDITOR_ALL;
2546: } else if (str.equals(pres)) {
2547: m_Mode = EDITOR_PRES;
2548: } else if (str.equals(data)) {
2549: m_Mode = EDITOR_DATA;
2550: } else {
2551: m_Mode = EDITOR_SEL;
2552: }
2553: }
2554: }
2555:
2556: public Vector<Icon> loadImages(JDefaultMutableTreeNode root) {
2557: Vector<Icon> retImages = new Vector();
2558: m_LoadedImages.removeAllElements();
2559: if (root != null) {
2560: Object obj = root.getUserObject();
2561: if (obj != null && obj instanceof IPropertyElement) {
2562: IPropertyElement rootEle = (IPropertyElement) obj;
2563: IPropertyDefinition rootDef = rootEle
2564: .getPropertyDefinition();
2565: Icon icon0 = getImage(rootEle);
2566: retImages.add(icon0);
2567: m_LoadedImages.add(rootEle);
2568: Vector<IPropertyElement> elems = rootEle
2569: .getSubElements();
2570: if (elems != null) {
2571: int count = elems.size();
2572: for (int i = 0; i < count; i++) {
2573: IPropertyElement pEle = elems.elementAt(i);
2574: IPropertyDefinition pDef = pEle
2575: .getPropertyDefinition();
2576: String name = pDef.getName();
2577:
2578: // determine if the element is a collection from its definition
2579: long mult = pDef.getMultiplicity();
2580: if (mult > 1) {
2581: String cType = pDef.getControlType();
2582: Vector<IPropertyElement> subEles = pEle
2583: .getSubElements();
2584: int count2 = subEles.size();
2585: if ((cType != null
2586: && cType.equals("read-only") && (count2 == 0)) || //$NON-NLS-1$
2587: name.equals("ReturnType")) //$NON-NLS-1$
2588: {
2589: } else if ((m_Mode == EDITOR_DATA)
2590: && (name.equals("Presentation"))) //$NON-NLS-1$
2591: {
2592: } else if (name.equals("FontProperties") || //$NON-NLS-1$
2593: name.equals("ColorProperties") || //$NON-NLS-1$
2594: name.equals("FontProperty") || //$NON-NLS-1$
2595: name.equals("ColorProperty") || //$NON-NLS-1$
2596: name.equals("PropertyContainer") || //$NON-NLS-1$
2597: name.equals("ChildProperties") //$NON-NLS-1$
2598: ) {
2599: } else {
2600: Icon icon = getImage(pEle);
2601: if (icon != null) {
2602: retImages.add(icon);
2603: m_LoadedImages.add(pEle);
2604: }
2605: }
2606: }
2607: }
2608: }
2609: }
2610: }
2611: return retImages;
2612: }
2613:
2614: /**
2615: * Set the icon of the grid cell
2616: *
2617: *
2618: * @param pDef[in] The current property definition
2619: * @param pEle[in] The current property element
2620: * @param row[in] The current row
2621: *
2622: * @return HRESULT
2623: *
2624: */
2625: public Icon getImage(IPropertyElement pEle) {
2626: Icon icon = null;
2627: if (pEle != null) {
2628: IPropertyDefinition pDef = pEle.getPropertyDefinition();
2629: if (pDef != null) {
2630: String name = pDef.getName();
2631: if (m_ResourceMgr != null) {
2632: if (name != null && name.equals("ProxyDiagram")) //$NON-NLS-1$
2633: {
2634: Object pDisp = pEle.getElement();
2635: if (pDisp != null
2636: && pDisp instanceof IProxyDiagram) {
2637: IProxyDiagram pDiag = (IProxyDiagram) pDisp;
2638: String kind = pDiag.getDiagramKindName();
2639: if (kind != null) {
2640: name = kind.trim();
2641: }
2642: }
2643: } else if (name.equals("Diagram")) //$NON-NLS-1$
2644: {
2645: Object pDisp = pEle.getElement();
2646: if (pDisp != null && pDisp instanceof IDiagram) {
2647: IDiagram pDiag = (IDiagram) pDisp;
2648: String kind = pDiag.getDiagramKind2();
2649: if (kind != null) {
2650: name = kind.trim();
2651: }
2652: }
2653: } else if (name.equals("State") //$NON-NLS-1$
2654: || name.equals("PseudoState") //$NON-NLS-1$
2655: || name.equals("FinalState")) //$NON-NLS-1$
2656: {
2657: String temp = calculateTopElementName(pEle);
2658: if (temp != null) {
2659: name = temp.trim();
2660: }
2661: }
2662: icon = m_ResourceMgr.getIconForElementType(name);
2663: }
2664: }
2665: }
2666: return icon;
2667: }
2668:
2669: /**
2670: * Determines the name to display in the property editor based on the IElement
2671: * type. Couldn't just use the element type because some of the elements were
2672: * the same element type, but had qualities that were different, so we wanted a
2673: * different name (psuedostate, for example)
2674: *
2675: *
2676: * @param pEle[in] The current property element
2677: * @param sName[out] The display name of the property element
2678: *
2679: * @return HRESULT
2680: *
2681: */
2682: public String calculateTopElementName(IPropertyElement pEle) {
2683: String topName = ""; //$NON-NLS-1$
2684: IPropertyDefinition pDef = pEle.getPropertyDefinition();
2685: if (pDef != null) {
2686: Object pDisp = pEle.getElement();
2687: if (pDisp != null) {
2688: IElement pElement = null;
2689: if (pDisp instanceof IPresentationElement) {
2690: IPresentationElement pPres = (IPresentationElement) pDisp;
2691: pElement = pPres.getFirstSubject();
2692: } else if (pDisp instanceof IElement) {
2693: pElement = (IElement) pDisp;
2694: }
2695:
2696: if (pElement != null) {
2697: IConfigStringTranslator trans = ConfigStringHelper
2698: .instance().getTranslator();
2699: if (trans != null) {
2700: String expandedEleType = pElement
2701: .getExpandedElementType();
2702:
2703: if (expandedEleType.equals("AbortedFinalState")) //$NON-NLS-1$
2704: {
2705: topName = trans.translate(null,
2706: "PSK_ABORTEDFINALSTATE"); //$NON-NLS-1$
2707: } else if (expandedEleType.equals("FinalState")) //$NON-NLS-1$
2708: {
2709: topName = trans.translate(null,
2710: "PSK_FINALSTATE"); //$NON-NLS-1$
2711: } else if (expandedEleType
2712: .equals("ChoicePseudoState")) //$NON-NLS-1$
2713: {
2714: topName = trans.translate(null,
2715: "PSK_CHOICEPSUEDOSTATE"); //$NON-NLS-1$
2716: } else if (expandedEleType
2717: .equals("DeepHistoryState")) //$NON-NLS-1$
2718: {
2719: topName = trans.translate(null,
2720: "PSK_DEEPHISTORY"); //$NON-NLS-1$
2721: } else if (expandedEleType.equals("ForkState")) //$NON-NLS-1$
2722: {
2723: topName = trans.translate(null,
2724: "PSKPSUEDOSTATE"); //$NON-NLS-1$
2725: } else if (expandedEleType
2726: .equals("InitialState")) //$NON-NLS-1$
2727: {
2728: topName = trans.translate(null,
2729: "PSK_INITIALSTATE"); //$NON-NLS-1$
2730: } else if (expandedEleType
2731: .equals(PropertyEditorResources
2732: .getString("PropertyEditor.JoinState_91"))) //$NON-NLS-1$
2733: {
2734: topName = trans.translate(null,
2735: "PSK_JOINSTATE"); //$NON-NLS-1$
2736: } else if (expandedEleType
2737: .equals("JunctionState")) //$NON-NLS-1$
2738: {
2739: topName = trans.translate(null,
2740: "PSK_JUNCTION"); //$NON-NLS-1$
2741: } else if (expandedEleType
2742: .equals("ShallowHistoryState")) //$NON-NLS-1$
2743: {
2744: topName = trans.translate(null,
2745: "PSK_SHALLOWHISTORY"); //$NON-NLS-1$
2746: } else if (expandedEleType
2747: .equals("EntryPointState")) //$NON-NLS-1$
2748: {
2749: topName = trans.translate(null,
2750: "PSK_ENTRYPOINT"); //$NON-NLS-1$
2751: } else if (expandedEleType.equals("StopState")) //$NON-NLS-1$
2752: {
2753: topName = trans.translate(null,
2754: "PSK_STOPSTATE"); //$NON-NLS-1$
2755: } else if (expandedEleType
2756: .equals("CompositeState")) //$NON-NLS-1$
2757: {
2758: topName = trans.translate(null,
2759: "PSK_COMPOSITESTATE"); //$NON-NLS-1$
2760: } else if (expandedEleType
2761: .equals("SubmachineState")) //$NON-NLS-1$
2762: {
2763: topName = trans.translate(null,
2764: "PSK_SUBMACHINESTATE"); //$NON-NLS-1$
2765: } else if (expandedEleType
2766: .equals("DesignPattern")) //$NON-NLS-1$
2767: {
2768: topName = trans.translate(null,
2769: "PSK_DESIGNPATTERN"); //$NON-NLS-1$
2770: } else {
2771: topName = pDef.getDisplayName();
2772: }
2773: }
2774: } else {
2775: topName = pDef.getDisplayName();
2776: }
2777: }
2778: }
2779: return topName;
2780: }
2781:
2782: /**
2783: * Called when a compartment on the drawing area is selected
2784: *
2785: * @param[in] selectedItems The compartments that are selected in the drawing area
2786: *
2787: * @return HRESULT
2788: *
2789: */
2790: public void onCompartmentSelect(final ICompartment selectedItem) {
2791: //we want the focusLost to do the work, but we need to set the lastCell
2792: //to be the m_CurRow
2793: m_LastRow = m_CurRow;
2794:
2795: try {
2796: if (PropertyEditorBlocker.inProcess() == false) {
2797: //When the last cell was being edited and user clicked on some other component which
2798: //makes property editor to refresh, we need to process last row.
2799: handleSave(false, null);
2800: clear();
2801:
2802: //
2803: // the property editor is loaded by creating property definitions(which
2804: // represent the structure of the data) and property elements(which represent
2805: // the actual data)
2806: //
2807: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
2808: Vector<IPropertyElement> propEles = new Vector<IPropertyElement>();
2809:
2810: if (selectedItem != null) {
2811: // what we have selected from the drawing area is a compartment
2812: // so ask it for its model element
2813: IElement pModelElement = selectedItem
2814: .getModelElement();
2815: if (pModelElement != null) {
2816: // more processing to create the property element
2817: IPropertyElement pEle = processSelectedItem(
2818: "", propDefs, pModelElement); //$NON-NLS-1$
2819: if (pEle != null) {
2820: // since we are coming from the drawing area, we will also want the
2821: // capability of showing the presentation information, so store the
2822: // presentation element on the property element
2823: //_VH(pEle->put_Element(pPresentationElement));
2824: // we also want to present the presentation section
2825: processSelectedPresentationItem(pEle,
2826: selectedItem);
2827: propEles.add(pEle);
2828: }
2829: }
2830: }
2831: setPropertyDefinitions(propDefs);
2832: setPropertyElements(propEles);
2833: }
2834: } catch (Exception e) {
2835: e.printStackTrace();
2836: }
2837: }
2838:
2839: /**
2840: * Called when something is selected on the drawing area
2841: *
2842: * @param[in] selectedItems The items that are currently selected in the drawing area
2843: *
2844: * @return HRESULT
2845: *
2846: */
2847: public void onDrawingAreaSelect(final IDiagram pParentDiagram,
2848: final ETList<IPresentationElement> selectedItems) {
2849: //we want the focusLost to do the work, but we need to set the lastCell
2850: //to be the m_CurRow
2851: m_LastRow = m_CurRow;
2852:
2853: try {
2854: int count = 0;
2855: if (selectedItems != null) {
2856: count = selectedItems.size();
2857: }
2858:
2859: if (count == 0) {
2860: if (PropertyEditorBlocker.inProcess() == false) {
2861: //When the last cell was being edited and user clicked on some other component which
2862: //makes property editor to refresh, we need to process last row.
2863: handleSave(false, null);
2864: clear();
2865:
2866: // if there is nothing selected and a diagram is open, we want to show the information
2867: // about the diagram
2868:
2869: onDrawingAreaSelectSpecial(pParentDiagram);
2870:
2871: }
2872: } else {
2873: // The blocker was put in because we were getting multiple "selects" when a
2874: // user was selecting a compartment. The compartment would issue a select, which would
2875: // then get processed by the property editor, but since the drawing area was also selected
2876: // it would also fire, nullifying what we did in the compartment select
2877: if (PropertyEditorBlocker.inProcess() == false) {
2878: //When the last cell was being edited and user clicked on some other component which
2879: //makes property editor to refresh, we need to process last row.
2880: handleSave(false, null);
2881: clear();
2882:
2883: //
2884: // the property editor is loaded by creating property definitions(which
2885: // represent the structure of the data) and property elements(which represent
2886: // the actual data)
2887: //
2888: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
2889: Vector<IPropertyElement> propEles = new Vector<IPropertyElement>();
2890:
2891: // get how many should be displayed from preferences
2892: IPreferenceAccessor pref = PreferenceAccessor
2893: .instance();
2894: int max = pref.getDefaultEditorSelect();
2895:
2896: if (count < max) {
2897: max = count;
2898: }
2899:
2900: // loop through the items selected and build the corresponding definitions and elements
2901: for (int i = 0; i < max; i++) {
2902: // what we have selected from the drawing area is a presentation element
2903: IPresentationElement presEle = selectedItems
2904: .get(i);
2905: if (presEle != null) {
2906: // we need the IElement from the presentation element
2907: IElement modelEle = presEle
2908: .getFirstSubject();
2909: if (modelEle != null) {
2910: // more processing to create the property element
2911: IPropertyElement pEle = processSelectedItem(
2912: "", propDefs, modelEle); //$NON-NLS-1$
2913: if (pEle != null) {
2914: // since we are coming from the drawing area, we will also want the
2915: // capability of showing the presentation information, so store the
2916: // presentation element on the property element
2917: pEle.setElement(presEle);
2918:
2919: // we also want to present the presentation section
2920: processSelectedPresentationItem(
2921: pEle, presEle);
2922: propEles.add(pEle);
2923: }
2924: }
2925: }
2926: }
2927: setPropertyDefinitions(propDefs);
2928: setPropertyElements(propEles);
2929: }
2930: }
2931: } catch (Exception e) {
2932: e.printStackTrace();
2933: }
2934: }
2935:
2936: /**
2937: * Called when something is selected on the project tree
2938: *
2939: * @param[in] selectedItems The items that are selected in the project tree
2940: *
2941: * @return HRESULT
2942: *
2943: */
2944: public void onTreeSelect(final IProjectTreeItem[] selectedItems) {
2945: //we want the focusLost to do the work, but we need to set the lastCell
2946: //to be the m_CurRow
2947: m_LastRow = m_CurRow;
2948:
2949: try {
2950: if (PropertyEditorBlocker.inProcess() == false) {
2951: //When the last cell was being edited and user clicked on some other component which
2952: //makes property editor to refresh, we need to process last row.
2953: handleSave(false, null);
2954: clear();
2955:
2956: //
2957: // the property editor is loaded by creating property definitions(which
2958: // represent the structure of the data) and property elements(which represent
2959: // the actual data)
2960: //
2961: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
2962: Vector<IPropertyElement> propEles = new Vector<IPropertyElement>();
2963:
2964: int count = selectedItems.length;
2965: IPreferenceAccessor pref = PreferenceAccessor
2966: .instance();
2967: int max = pref.getDefaultEditorSelect();
2968: if (count < max) {
2969: max = count;
2970: }
2971:
2972: // loop through the items selected and build the corresponding definitions and elements
2973: for (int i = 0; i < max; i++) {
2974: // what we have selected from the project tree is a project tree item
2975: IProjectTreeItem item = selectedItems[i];
2976:
2977: //if the support item for this ProjectTreeItem is a IFolderItem, we do not show its properties.
2978: ITreeItem suppItem = item
2979: .getProjectTreeSupportTreeItem();
2980: if (suppItem instanceof ITreeFolder) {
2981: //do nothing
2982: } else {
2983: // and then ask it for its model element
2984: IElement modelEle = item.getModelElement();
2985: if (modelEle != null) {
2986: //modelEle = new IElementProxy(modelEle);
2987: IPropertyElement pEle = processSelectedItem(
2988: "", propDefs, modelEle); //$NON-NLS-1$
2989: if (pEle != null) {
2990: propEles.add(pEle);
2991: }
2992: } else {
2993: // there are items in the project tree that do not have model elements behind them
2994: // ie. Workspace, Project, Diagram
2995: // this is the additional processing if one of those items are selected
2996: IPropertyElement pEle = onTreeSelectSpecial(
2997: item, propDefs);
2998: if (pEle != null) {
2999: propEles.add(pEle);
3000: }
3001: }
3002: }
3003: }
3004: setPropertyDefinitions(propDefs);
3005: setPropertyElements(propEles);
3006: //populateGrid();
3007: }
3008: } catch (Exception e) {
3009: e.printStackTrace();
3010: }
3011: }
3012:
3013: /**
3014: * Called when something is selected on the project tree and we cannot get a model element for it
3015: * ie. a workspace, a unopened project, a diagram
3016: *
3017: * @param[in] selectedItem The item that is selected in the project tree
3018: * @param[in] pDefs The array of property definitions for this property editor
3019: * @param[out] pEle The property element that has been created
3020: *
3021: * @return HRESULT
3022: *
3023: */
3024: public void onDrawingAreaSelectSpecial(IDiagram pDiagram) {
3025: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
3026: Vector<IPropertyElement> propEles = new Vector<IPropertyElement>();
3027:
3028: IPropertyElement pEle = processSelectedItem(
3029: "Diagram", propDefs, pDiagram); //$NON-NLS-1$
3030: if (pEle != null) {
3031: propEles.add(pEle);
3032: }
3033: setPropertyDefinitions(propDefs);
3034: setPropertyElements(propEles);
3035: }
3036:
3037: /**
3038: * Build the presentation section of the property element
3039: *
3040: *
3041: * @param pEle[in] The top level property element which will house the presentation section
3042: * @param pDisp[in] The IDispatch from which we will obtain its presentation information
3043: *
3044: * @return HRESULT
3045: */
3046: private void processSelectedPresentationItem(IPropertyElement pEle,
3047: Object pDisp) {
3048: // if (m_Factory != null)
3049: // {
3050: // // if the dispatch passed in can have a presentation section, it must be a DrawingPropertyProvider
3051: // if (pDisp instanceof IDrawingPropertyProvider)
3052: // {
3053: // IDrawingPropertyProvider provider = (IDrawingPropertyProvider)pDisp;
3054: //
3055: // // the information is actually stored in the container of the drawing property provider
3056: // IPropertyContainer container = provider.getPropertyContainer();
3057: // if (container != null)
3058: // {
3059: // // get the property definition that represents this kind of model element
3060: // // this will create it from the xml file if it hasn't already been created
3061: // IPropertyDefinition pDef = m_Factory.getPropertyDefinitionByName("Presentation");
3062: // if (pDef != null)
3063: // {
3064: // if (m_PropEleMgr != null)
3065: // {
3066: // // build the property element
3067: // IPropertyElement newEle = m_PropEleMgr.buildElement(container, pDef, pEle);
3068: // if (newEle != null)
3069: // {
3070: // filterPropertyElement(newEle);
3071: // // determine if there is presentation information present
3072: // Vector<IPropertyElement> subEles = newEle.getSubElements();
3073: // if (subEles != null)
3074: // {
3075: // int fontCount = 0;
3076: // int colorCount = 0;
3077: // int childCount = 0;
3078: // int count = subEles.size();
3079: // for (int i=0; i<count; i++)
3080: // {
3081: // IPropertyElement elem = subEles.get(i);
3082: // if (elem.getName().equals("FontProperties"))
3083: // {
3084: // Vector<IPropertyElement> subFonts = elem.getSubElements();
3085: // if (subFonts != null)
3086: // {
3087: // fontCount = subFonts.size();
3088: // }
3089: // }
3090: // if (elem.getName().equals("ColorProperties"))
3091: // {
3092: // Vector<IPropertyElement> subCols = elem.getSubElements();
3093: // if (subCols != null)
3094: // {
3095: // fontCount = subCols.size();
3096: // }
3097: // }
3098: // if (elem.getName().equals("ChildProperties"))
3099: // {
3100: // Vector<IPropertyElement> subChilds = elem.getSubElements();
3101: // if (subChilds != null)
3102: // {
3103: // fontCount = subChilds.size();
3104: // }
3105: // }
3106: // }
3107: //
3108: // if ( (fontCount > 0) || (colorCount > 0) || (childCount > 0) )
3109: // {
3110: // newEle.setElement(pDisp);
3111: // pEle.addSubElement(newEle);
3112: // }
3113: // }
3114: // }
3115: // }
3116: // }
3117: // }
3118: // }
3119: // }
3120: }
3121:
3122: /**
3123: * Called when something is selected on the project tree and we cannot get a model element for it
3124: * ie. a workspace, a unopened project, a diagram
3125: *
3126: * @param[in] selectedItem The item that is selected in the project tree
3127: * @param[in] pDefs The array of property definitions for this property editor
3128: * @param[out] pEle The property element that has been created
3129: *
3130: * @return HRESULT
3131: *
3132: */
3133: private IPropertyElement onTreeSelectSpecial(
3134: IProjectTreeItem selectedItem,
3135: Vector<IPropertyDefinition> pDefs) {
3136: IPropertyElement retEle = null;
3137: boolean isWork = selectedItem.isWorkspace();
3138: boolean isProj = selectedItem.isProject();
3139: if (isWork) {
3140: // get the workspace that is selected
3141: IWorkspace space = ProductHelper.getWorkspace();
3142: retEle = processSelectedItem("Workspace", pDefs, space); //$NON-NLS-1$
3143: } else if (isProj) {
3144: // have a closed project selected
3145: // if the project is open, we will have a model element and will not be
3146: // in this processing
3147: String projName = selectedItem.getItemText();
3148: if (projName.length() > 0) {
3149: IWorkspace space = ProductHelper.getWorkspace();
3150: if (space != null) {
3151: IWSProject wsproj = space
3152: .getWSProjectByName(projName);
3153: if (wsproj != null) {
3154: retEle = processSelectedItem(
3155: "WSProject", pDefs, wsproj); //$NON-NLS-1$
3156: }
3157: }
3158: }
3159: } else {
3160: // might have a diagram selected
3161: String description = selectedItem.getDescription();
3162: if (description.length() > 0) {
3163: if (description.endsWith(".etld")) //$NON-NLS-1$
3164: {
3165: IProxyDiagramManager diaMgr = ProxyDiagramManager
3166: .instance();
3167: IProxyDiagram proxyDiag = diaMgr
3168: .getDiagram(description);
3169: if (proxyDiag != null) {
3170: IDiagram diag = proxyDiag.getDiagram();
3171: if (diag != null) {
3172: retEle = processSelectedItem(
3173: "Diagram", pDefs, diag); //$NON-NLS-1$
3174: } else {
3175: retEle = processSelectedItem(
3176: "ProxyDiagram", pDefs, proxyDiag); //$NON-NLS-1$
3177: }
3178: }
3179: }
3180: }
3181: }
3182: return retEle;
3183: }
3184:
3185: public Vector<Object> buildSubElementsThatNeedToDisplay(
3186: IPropertyElement pEle, JDefaultMutableTreeNode node) {
3187: Vector<Object> retObj = new Vector<Object>();
3188:
3189: if (pEle != null) {
3190: IPropertyDefinition pDef = pEle.getPropertyDefinition();
3191: Vector<IPropertyElement> elems = pEle.getSubElements();
3192:
3193: if (elems != null) {
3194: int count = elems.size();
3195: for (int i = 0; i < count; i++) {
3196: JDefaultMutableTreeNode mNode = null;
3197: IPropertyElement subEle = elems.elementAt(i);
3198: IPropertyDefinition subDef = subEle
3199: .getPropertyDefinition();
3200: if (subDef != null) {
3201: // we may not want to build the property elements just yet
3202: // we got into a performance hit by building all of the property elements up front
3203: boolean onDem = subDef.isOnDemand();
3204: if (onDem && i < 1) {
3205: // the property definition says that this is an on demand one, therefore the
3206: // property element hasn't been built yet
3207: Object pDisp = subEle.getElement();
3208:
3209: // get the property definition for the element
3210: IPropertyDefinition pd2 = getPropertyDefinition(subEle);
3211: if (pd2 != null) {
3212: pd2.setParent(pDef);
3213: boolean onDem2 = pd2.isOnDemand();
3214:
3215: // everything is ready to be built now, so build it
3216: if (m_Mode == EDITOR_SEL) {
3217: String value = (String) m_FilterCombo
3218: .getSelectedItem();
3219:
3220: // set the value on the property element
3221: IConfigStringTranslator trans = ConfigStringHelper
3222: .instance().getTranslator();
3223: if (trans != null) {
3224: String transValue = trans
3225: .translateIntoPSK(null,
3226: value);
3227: String displayValue = subDef
3228: .getFromAttrMap("displayName"); //$NON-NLS-1$
3229: if (displayValue
3230: .equals(transValue)) {
3231: mNode = addSubElementToTable(
3232: node, pd2, subEle,
3233: onDem2);
3234: }
3235: }
3236: } else {
3237: mNode = addSubElementToTable(node,
3238: pd2, subEle, onDem2);
3239: }
3240: }
3241: } else {
3242: if (m_Mode == EDITOR_SEL) {
3243: String value = (String) m_FilterCombo
3244: .getSelectedItem();
3245:
3246: // set the value on the property element
3247: IConfigStringTranslator trans = ConfigStringHelper
3248: .instance().getTranslator();
3249: if (trans != null) {
3250: String transValue = trans
3251: .translateIntoPSK(null,
3252: value);
3253: String displayValue = subDef
3254: .getName();//subDef.getFromAttrMap("displayName");
3255: if (displayValue != null
3256: && displayValue
3257: .equals(value)) {
3258: mNode = addSubElementToTable(
3259: node, subDef, subEle,
3260: false);
3261: }
3262: }
3263: } else {
3264: mNode = addSubElementToTable(node,
3265: subDef, subEle, false);
3266: }
3267: }
3268: }
3269: if (mNode != null) {
3270: retObj.add(mNode);
3271: }
3272: }
3273: }
3274: }
3275: return retObj;
3276: }
3277:
3278: /**
3279: * Add the sub element of the passed in property element to the grid
3280: *
3281: * @param[in] pNode The grid node to add element to
3282: * @param[in] pDef The property definition associated with the property element
3283: * @param[in] pEle The property element to be added at this time
3284: * @param[in] onDemand Whether or not the property element should be built now or later
3285: *
3286: * @return HRESULT
3287: *
3288: */
3289: private JDefaultMutableTreeNode addSubElementToTable(
3290: JDefaultMutableTreeNode pNode, IPropertyDefinition pDef,
3291: IPropertyElement pEle, boolean onDemand) {
3292: JDefaultMutableTreeNode retNode = null;
3293: // need the parent of the definition so that we can do special processing for fonts/colors
3294: IPropertyDefinition parentDef = pDef.getParent();
3295: String parentName = ""; //$NON-NLS-1$
3296: if (parentDef != null) {
3297: parentName = parentDef.getName();
3298: }
3299:
3300: String name = pDef.getName();
3301:
3302: // get the name to be displayed in the name field of the property editor
3303: String displayName = pDef.getDisplayName();
3304:
3305: // get the value
3306: m_PropEleMgr.interpretElementValue(pEle);
3307: String value = pEle.getValue();
3308:
3309: // now determine if there are subelements by getting the sub element count
3310: // we will also need to do a check on these sub elements to see if the sub element
3311: // is on demand, if it is, it is a placeholder and may not cause us to add this
3312: Vector<IPropertyElement> subEles = pEle.getSubElements();
3313:
3314: // get the control type of the definition
3315: String cType = pDef.getControlType();
3316:
3317: // get the multiplicity of the definition
3318: long mult = pDef.getMultiplicity();
3319:
3320: int count = 0;
3321: if (subEles != null) {
3322: count = subEles.size();
3323: }
3324:
3325: // Now we have the information that we need, so should we add this node
3326: // But first, we will want to do several rule checks to see if it should be added
3327: //
3328: if ((cType != null && cType.equals("read-only")) && (mult > 1) //$NON-NLS-1$
3329: && (count == 0) && (!onDemand)) {
3330: //ETSystem.out.println("Ignoring in first loop " + name + cType + mult + count + onDemand);
3331: // Can't remember why this is here but it is needed
3332: // I think it is to not show the collections that are for display purposes (can't be
3333: // added to through the property editor - relationships). We didn't want to display
3334: // the node if it was empty - Associations, Generalizations if there weren't any
3335: } else if ((cType == null || cType.equals("read-only")) && //$NON-NLS-1$
3336: (mult == 1) && (count == 0) && (!onDemand)
3337: && (value == null || value.length() == 0)
3338: && (!parentName.equals("ChildProperties")) //$NON-NLS-1$
3339: ) {
3340: //ETSystem.out.println("Ignoring in second loop " + name);
3341: // VersionedFileName : We don't want to display a read only single field that has no value
3342: } else if ((m_Mode == EDITOR_DATA)
3343: && (name.equals("Presentation") //$NON-NLS-1$
3344: || name.equals("FontProperty") //$NON-NLS-1$
3345: || name.equals("ColorProperty"))) //$NON-NLS-1$
3346: {
3347: //ETSystem.out.println("Ignoring in third loop " + name);
3348: // if we are in the mode where the user only wants to see data information, the property element
3349: // could have property elements representing the presentation section, so filter these out
3350: } else if ((m_Mode == EDITOR_PRES)
3351: && (!name.equals("Presentation")) && //$NON-NLS-1$
3352: (!name.equals("PropertyContainer")) && //$NON-NLS-1$
3353: (!name.equals("FontProperties")) && //$NON-NLS-1$
3354: (!name.equals("ColorProperties")) && //$NON-NLS-1$
3355: (!name.equals("FontProperty")) && //$NON-NLS-1$
3356: (!name.equals("ColorProperty")) && //$NON-NLS-1$
3357: (!name.equals("ChildProperties")) //$NON-NLS-1$
3358: ) {
3359: //ETSystem.out.println("Ignoring in fourth loop " + name);
3360: // if we are in the mode where the user only wants to see only presentation information,
3361: // the property element could actually have both data and presentation sections. So we
3362: // filter out the data stuff
3363: } else if (parentName.equals("FontProperty")) //$NON-NLS-1$
3364: {
3365: //ETSystem.out.println("Ignoring in fifth loop " + name);
3366: // we don't want to add sub elements of a font property because fonts appear as one line, so the
3367: // sub elements have been taken care of in special processing
3368: } else if (parentName.equals(PropertyEditorResources
3369: .getString("PropertyEditor.ColorProperty_132"))) //$NON-NLS-1$
3370: {
3371: //ETSystem.out.println("Ignoring in sixth loop " + name);
3372: // we don't want to add sub elements of a color property because colors appear as one line, so the
3373: // sub elements have been taken care of in special processing
3374: } else {
3375: //ETSystem.out.println("Finally adding " + name);
3376: // add the node to the grid
3377: retNode = new JDefaultMutableTreeNode(pEle, true);
3378: pNode.add(retNode);
3379: // if (m_Tree != null)
3380: // {
3381: // m_Tree.updateUI();
3382: // }
3383:
3384: // special processing to mark this grid node as a record in case we need to process
3385: // it as a whole. This is due to the changing of the way we save to do it by record
3386: // rather than by cell
3387: String recd = pDef.getFromAttrMap("pseudoRecord"); //$NON-NLS-1$
3388: if ((count > 0 && mult == 1)
3389: || name.equals("Multiplicity") || //$NON-NLS-1$
3390: (recd != null && recd.equals("true"))) //$NON-NLS-1$
3391: {
3392: retNode.setKey("Record"); //$NON-NLS-1$
3393: }
3394: int newRow = retNode.getRow();
3395:
3396: // do not expand the node
3397: retNode.setExpanded(false);
3398:
3399: // Now check the name for fonts/colors so that we can do special processing
3400: if (name.equals("FontProperty")) //$NON-NLS-1$
3401: {
3402: specialFontProcessing(newRow, pDef, pEle);
3403: } else if (name.equals("ColorProperty")) //$NON-NLS-1$
3404: {
3405: specialColorProcessing(newRow, pDef, pEle);
3406: } else if (name.equals("PropertyContainer")) //$NON-NLS-1$
3407: {
3408: specialPropertyProcessing(newRow, pDef, pEle);
3409: } else {
3410: // set the value
3411:
3412: }
3413:
3414: if (!name.equals("ColorProperty")) //$NON-NLS-1$
3415: {
3416: // set the color of the grid cell
3417: int color = m_EditableColor;
3418: boolean readOnly = isReadOnlyStatus(pDef, pEle);
3419: if (readOnly) {
3420: color = m_ReadOnlyColor;
3421: }
3422:
3423: boolean boldness = isBold(pDef, pEle);
3424:
3425: //set the color of the row and set the boldness of the row.
3426: }
3427:
3428: if (!onDemand) {
3429: // process further sub elements if necessary
3430: buildSubElementsThatNeedToDisplay(pEle, retNode);
3431: }
3432: }
3433: return retNode;
3434: }
3435:
3436: /**
3437: * Font property elements are displayed differently than other preference elements. The font
3438: * definition looks like:
3439: *
3440: * <PropertyDefinition id="{6C77C083-7008-4CE0-893E-D4C198D5E8C2}" name="FontProperty" controlType="multiedit">
3441: * <aDefinition name="FontDisplayName" get="DisplayNameID"/>
3442: * <aDefinition name="FontColor" get="Color" set="Color"/>
3443: * </PropertyDefinition>
3444: *
3445: * but we only want to display one line in the grid and have that one line represent all of the font values
3446: * (ie. Have the name "Arial" displayed, but have it bolded and the right size
3447: *
3448: * We will use the FontDisplayName for the left hand side of the property editor
3449: * and for the other properties, we will ask the FontProperty for its information
3450: *
3451: * @param pDef[in] The property definition associated with the preference element
3452: * @param pEle[in] The property element representing the font
3453: *
3454: * @return HRESULT
3455: */
3456: private void specialFontProcessing(int row,
3457: IPropertyDefinition pDef, IPropertyElement pEle) {
3458: Object pDisp = pEle.getElement();
3459: if (pDisp != null && pDisp instanceof IFontProperty) {
3460: IFontProperty fontProp = (IFontProperty) pDisp;
3461: specialFontProcessing2(row, fontProp, pEle);
3462: }
3463: }
3464:
3465: /**
3466: * Font property elements are displayed differently than other preference elements. The font
3467: * definition looks like:
3468: *
3469: * <PropertyDefinition id="{6C77C083-7008-4CE0-893E-D4C198D5E8C2}" name="FontProperty" controlType="multiedit">
3470: * <aDefinition name="FontDisplayName" get="DisplayNameID"/>
3471: * <aDefinition name="FontColor" get="Color" set="Color"/>
3472: * </PropertyDefinition>
3473: *
3474: * but we only want to display one line in the grid and have that one line represent all of the font values
3475: * (ie. Have the name "Arial" displayed, but have it bolded and the right size
3476: *
3477: * We will use the FontDisplayName for the left hand side of the property editor
3478: * and for the other properties, we will ask the FontProperty for its information
3479: *
3480: * @param row[in] The current row
3481: * @param pFontProperty[in] The font property to load into the grid
3482: * @param pEle[in] The property element representing the font
3483: *
3484: * @return HRESULT
3485: */
3486: private void specialFontProcessing2(int row,
3487: IFontProperty fontProp, IPropertyElement pEle) {
3488: // This method builds the left hand side of the font in the grid
3489: Vector<IPropertyElement> subEles = pEle.getSubElements();
3490: if (subEles != null) {
3491: String name, displayName = null;
3492: for (int i = 0; i < subEles.size(); i++) {
3493: IPropertyElement subEle = subEles.elementAt(i);
3494: if (subEle.getName().equals("FontDisplayName")) //$NON-NLS-1$
3495: {
3496: name = subEle.getValue();
3497: IConfigStringTranslator translator = ConfigStringHelper
3498: .instance().getTranslator();
3499: if (translator != null) {
3500: displayName = translator.translate(null, name);
3501: }
3502: }
3503: }
3504:
3505: if (displayName != null && displayName.length() > 0) {
3506: //set the display name for this element
3507: //_VH(m_PropertyGrid->put_Cell(flexcpText, CComVariant(row), CComVariant(m_HeadingCol), vtMissing, vtMissing, CComVariant(dispName)));
3508: specialFontProcessing3(row, fontProp);
3509:
3510: // set the behind the scenes data to the property element
3511: //_VH(m_PropertyGrid->put_Cell(flexcpData, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(pEle)));
3512:
3513: }
3514: }
3515: }
3516:
3517: /**
3518: * Font property elements are displayed differently than other preference elements. The font
3519: * definition looks like:
3520: *
3521: * <PropertyDefinition id="{6C77C083-7008-4CE0-893E-D4C198D5E8C2}" name="FontProperty" controlType="multiedit">
3522: * <aDefinition name="FontDisplayName" get="DisplayNameID"/>
3523: * <aDefinition name="FontColor" get="Color" set="Color"/>
3524: * </PropertyDefinition>
3525: *
3526: * but we only want to display one line in the grid and have that one line represent all of the font values
3527: * (ie. Have the name "Arial" displayed, but have it bolded and the right size
3528: *
3529: * We will use the FontDisplayName for the left hand side of the property editor
3530: * and for the other properties, we will ask the FontProperty for its information
3531: *
3532: * @param row[in] The current row
3533: * @param pFontProperty[in] The font property to load into the grid
3534: *
3535: * @return HRESULT
3536: */
3537: private void specialFontProcessing3(int row,
3538: IFontProperty pFontProperty) {
3539:
3540: }
3541:
3542: /**
3543: * Color property elements are displayed differently than other preference elements. The color
3544: * definition looks like:
3545: *
3546: * <PropertyDefinition id="{6C77C083-7008-4CE0-893E-D4C198D5E8C2}" name="ColorProperty" controlType="multiedit">
3547: * <aDefinition name="ColorName" get="DisplayNameID"/>
3548: * <aDefinition name="Color" get="Color" set="Color"/>
3549: * </PropertyDefinition>
3550: *
3551: * but we only want to display one line in the grid and have that one line represent all of the color values
3552: * (ie. Have the color stored in the property editor
3553: *
3554: * We will use the ColorName for the left hand side of the property editor
3555: * and for the other properties, we will ask the ColorProperty for its information
3556: *
3557: * @param row[in] The current row
3558: * @param pProperty[in] The color property to load into the grid
3559: * @param pEle[in] The property element representing the color
3560: *
3561: * @return HRESULT
3562: */
3563: private void specialColorProcessing(int row,
3564: IPropertyDefinition pDef, IPropertyElement pEle) {
3565: Object pDisp = pEle.getElement();
3566: if (pDisp != null && pDisp instanceof IColorProperty) {
3567: IColorProperty colorProp = (IColorProperty) pDisp;
3568: specialColorProcessing2(row, colorProp, pEle);
3569: }
3570: }
3571:
3572: /**
3573: * Color property elements are displayed differently than other preference elements. The color
3574: * definition looks like:
3575: *
3576: * <PropertyDefinition id="{6C77C083-7008-4CE0-893E-D4C198D5E8C2}" name="ColorProperty" controlType="multiedit">
3577: * <aDefinition name="ColorName" get="DisplayNameID"/>
3578: * <aDefinition name="Color" get="Color" set="Color"/>
3579: * </PropertyDefinition>
3580: *
3581: * but we only want to display one line in the grid and have that one line represent all of the color values
3582: * (ie. Have the color stored in the property editor
3583: *
3584: * We will use the ColorName for the left hand side of the property editor
3585: * and for the other properties, we will ask the ColorProperty for its information
3586: *
3587: * @param row[in] The current row
3588: * @param pProperty[in] The color property to load into the grid
3589: * @param pEle[in] The property element representing the color
3590: *
3591: * @return HRESULT
3592: */
3593: private void specialColorProcessing2(int row,
3594: IColorProperty colorProp, IPropertyElement pEle) {
3595: // get the display name of the color property
3596: String name, displayName;
3597: int color = 0;
3598:
3599: Vector<IPropertyElement> subEles = pEle.getSubElements();
3600: if (subEles != null) {
3601: for (int i = 0; i < subEles.size(); i++) {
3602: IPropertyElement subEle = subEles.elementAt(i);
3603: if (subEle.getName().equals("ColorName")) //$NON-NLS-1$
3604: {
3605: name = subEle.getValue();
3606: IConfigStringTranslator translator = ConfigStringHelper
3607: .instance().getTranslator();
3608: if (translator != null) {
3609: displayName = translator.translate(null, name);
3610: }
3611: }
3612: }
3613: }
3614:
3615: // if there is no value for this, keep the color at white
3616: // if there is a value, and it is black ("0"), need to set the grid color to one, per flex grid
3617: /*
3618: Remarks
3619: Setting this property to zero (black) causes the control to paint the cell using the standard
3620: colors (set by the BackColor and BackColorAlternate properties).
3621: Therefore, to set this property to black, use RGB(1,1,1) instead of RGB(0,0,0).
3622: */
3623: int cref = colorProp.getColor();
3624: // BYTE rvalue = GetRValue(cref);
3625: // BYTE gvalue = GetGValue(cref);
3626: // BYTE bvalue = GetBValue(cref);
3627: // if (rvalue == 0 && gvalue == 0 && bvalue == 0)
3628: // {
3629: // color = 1;
3630: // }
3631: // else
3632: // {
3633: // color = cref;
3634: // }
3635:
3636: if (m_Model != null) {
3637: // now set the information in the grid
3638: //_VH(m_PropertyGrid->put_Cell(flexcpText, CComVariant(row), CComVariant(m_HeadingCol), vtMissing, vtMissing, CComVariant(dispName)));
3639: //_VH(m_PropertyGrid->put_Cell(flexcpBackColor, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(color)));
3640: // set the behind the scenes data to the property element
3641: //_VH(m_PropertyGrid->put_Cell(flexcpData, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(pEle)));
3642: //_VH(m_PropertyGrid->put_Cell(flexcpRefresh, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(TRUE)));
3643: }
3644: }
3645:
3646: /**
3647: * Child property elements are displayed differently than other preference elements.
3648: *
3649: * @param row[in] The current row
3650: * @param pProperty[in] The child property to load into the grid
3651: * @param pEle[in] The property element representing the color
3652: *
3653: * @return HRESULT
3654: */
3655: private void specialPropertyProcessing(int row,
3656: IPropertyDefinition pDef, IPropertyElement pEle) {
3657: Object pDisp = pEle.getElement();
3658: if (pDisp != null && m_Model != null
3659: && pDisp instanceof IPropertyContainer) {
3660: IPropertyContainer pContainer = (IPropertyContainer) pDisp;
3661: String displayName = pContainer.getDisplayName();
3662:
3663: int color = m_EditableColor;
3664: boolean readOnly = isReadOnlyStatus(pDef, pEle);
3665: if (readOnly) {
3666: color = m_ReadOnlyColor;
3667: }
3668: boolean boldness = isBold(pDef, pEle);
3669:
3670: // _VH(m_PropertyGrid->put_Cell(flexcpText, CComVariant(row), CComVariant(m_HeadingCol), vtMissing, vtMissing, CComVariant(displayName)));
3671: // _VH(m_PropertyGrid->put_Cell(flexcpText, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(value)));
3672: // // set the behind the scenes data to the property element
3673: // _VH(m_PropertyGrid->put_Cell(flexcpData, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(pEle)));
3674: //
3675: // _VH(m_PropertyGrid->put_Cell(flexcpBackColor, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(color)));
3676: // // set the boldness of the font of the grid cell
3677: // _VH(m_PropertyGrid->put_Cell(flexcpFontBold, CComVariant(row), CComVariant(m_HeadingCol), vtMissing, vtMissing, CComVariant(boldness)));
3678: // _VH(m_PropertyGrid->put_Cell(flexcpFontBold, CComVariant(row), CComVariant(m_DataCol), vtMissing, vtMissing, CComVariant(boldness)));
3679:
3680: }
3681: }
3682:
3683: /**
3684: * Retrieve the property definition from the definition factory
3685: *
3686: *
3687: * @param pEle[in] The current property element
3688: * @param pDef[out] The current property definition
3689: *
3690: * @return HRESULT
3691: *
3692: */
3693: private IPropertyDefinition getPropertyDefinition(
3694: IPropertyElement pEle) {
3695: IPropertyDefinition retDef = null;
3696:
3697: // get the property definition for the element on the property element
3698: Object pDisp = pEle.getElement();
3699: IPropertyDefinition pDef = null;
3700: if (pDisp != null) {
3701: if (pDisp instanceof IElement) {
3702: // can reuse a method if it is an IElement
3703: pDef = m_Factory.getPropertyDefinitionForElement(
3704: "", pDisp); //$NON-NLS-1$
3705: } else if (pDisp instanceof IFontProperty) {
3706: // need to specifically retrieve this element, because can't get its "type"
3707: pDef = m_Factory
3708: .getPropertyDefinitionByName("FontProperty"); //$NON-NLS-1$
3709: } else if (pDisp instanceof IColorProperty) {
3710: // need to specifically retrieve this element, because can't get its "type"
3711: pDef = m_Factory
3712: .getPropertyDefinitionByName("ColorProperty"); //$NON-NLS-1$
3713: } else if (pDisp instanceof IPropertyContainer) {
3714: // need to specifically retrieve this element, because can't get its "type"
3715: pDef = m_Factory
3716: .getPropertyDefinitionByName("PropertyContainer"); //$NON-NLS-1$
3717: }
3718: } else {
3719: String name = pEle.getName();
3720: // need to specifically retrieve this element, because can't get its "type"
3721: pDef = m_Factory.getPropertyDefinitionByName(name);
3722: if (pDef != null) {
3723: String value = pDef.getFromAttrMap("pseudoRecord"); //$NON-NLS-1$
3724: if (value != null && !value.equals("true")) //$NON-NLS-1$
3725: {
3726: pDef = null;
3727: }
3728: }
3729: }
3730: if (pDef != null) {
3731: retDef = pDef;
3732: }
3733: return retDef;
3734: }
3735:
3736: /**
3737: * Called when the create popup menu is clicked upon
3738: *
3739: * @param[in] wNotifyCode
3740: * @param[in] wID
3741: * @param[in] hWndCtrl
3742: * @param[out] bHandled
3743: *
3744: * @return LRESULT
3745: *
3746: */
3747: public void onPopupCreate(int row, IPropertyElement element) {
3748: if (m_Tree != null && m_Model != null) {
3749: onNodeExpanding(row);
3750: IPropertyElement pEle = createEmptyPropertyElement(row,
3751: true);
3752: JDefaultMutableTreeNode node = null;
3753: if (pEle != null) {
3754: // now expand and set up the node that will be added
3755: node = addNodeToGrid(row, pEle);
3756:
3757: //Now go through the sub elements of pEle and add those to the tree
3758: //buildSubElementsThatNeedToDisplay(pEle, node);
3759: }
3760: //refreshElementInGrid(m_CurRow, pEle);
3761: m_Tree.getTree().updateUI();
3762: m_Model.expand(row, true);
3763: if (node != null) {
3764: node.setExpanded(true);
3765: JDefaultMutableTreeNode pNode = getNodeAtGridRow(row);
3766: int iRow = pNode.getIndex(node);
3767:
3768: //expand the node that is just created.
3769: m_Model.expand(row + iRow + 1, true);
3770: //m_Tree.expandNode(node, true);
3771:
3772: //I need to start editing the first node in this newly created node.
3773: final int editRow = row + iRow + 2;
3774: SwingUtilities.invokeLater(new Runnable() {
3775:
3776: public void run() {
3777: startEditingRowAt(editRow);
3778: }
3779: });
3780:
3781: }
3782: }
3783: }
3784:
3785: /**
3786: * Called when the user clicks on the delete popup menu
3787: *
3788: * @param[in] wNotifyCode
3789: * @param[in] wID
3790: * @param[in] hWndCtrl
3791: * @param[out] bHandled
3792: *
3793: * @return LRESULT
3794: */
3795: public void onPopupDelete() {
3796: if (m_Model != null && m_Tree != null) {
3797: // we will try to delete any rows that are selected
3798: // I had a terrible time with the grid and processing the rows that are selected
3799: // I finally had to break it up into sections, and this seems to work, so I didn't
3800: // want to mess with it anymore
3801: //
3802: // First get the rows that are selected that are marked as records
3803: // this just stores the row number in an array
3804: int count = m_Tree.getSelectedRowCount();
3805: int[] rows = m_Tree.getSelectedRows();
3806: Vector tempRows = new Vector();
3807: for (int i = 0; i < count; i++) {
3808: int rowNum = rows[i];
3809: if (count == 1) {
3810: //only one row is selected, user may not have selected
3811: //this row and right clicked, if that is the case, use the
3812: //saved row value
3813: if (rowNum != m_RightClickRow) {
3814: rowNum = m_RightClickRow;
3815: }
3816: }
3817: JDefaultMutableTreeNode node = getNodeAtGridRow(rowNum);
3818: if (node != null) {
3819: String key = node.getKey();
3820: if (key != null
3821: && (key.equals("Record") || key.equals("RecordNew"))) //$NON-NLS-1$ //$NON-NLS-2$
3822: {
3823: tempRows.addElement(node);
3824: }
3825: }
3826: }
3827:
3828: // now loop through that array of selected "record" rows and store the property elements
3829: // in a temporary array to be removed in the next step. I couldn't remove them as I went
3830: // because then the grid data got all messed up and I couldn't do any further processing
3831: // if more than one row was selected
3832: int rowCount = tempRows.size();
3833: for (int i = rowCount - 1; i >= 0; i--) {
3834: JDefaultMutableTreeNode node = (JDefaultMutableTreeNode) tempRows
3835: .elementAt(i);
3836: IPropertyElement pEle = (IPropertyElement) node
3837: .getUserObject();
3838: if (pEle != null) {
3839: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) node
3840: .getParent();
3841: IPropertyDefinition pDef = pEle
3842: .getPropertyDefinition();
3843: boolean bEdit = isElementEditable(pEle, pDef);
3844: if (bEdit) {
3845: //DefaultMutableTreeNode parentNode = node.getParent();
3846: node.removeFromParent();
3847:
3848: //now remove it from the xml file
3849: pEle.setModified(true);
3850: IPropertyElement delEle = getDeleteElement(pEle);
3851: if (delEle != null) {
3852: String delName = delEle.getName();
3853: if (delName.equals("DiagramName")
3854: || delName.equals("ElementName")) {
3855: deleteDiagram(delEle);
3856: } else if (delName
3857: .equals("ReferencingReferences")
3858: || delName
3859: .equals("ReferencedReferences")) {
3860: deleteReference(delEle, pEle);
3861: } else {
3862: // delete, make sure to create a blocker to block other events!
3863: // only want to call delete if there is an element to delete
3864: PropertyEditorBlocker.block();
3865: try {
3866: // Because of Issue 7295 (where there is a new attribute
3867: // and we try and delete it, the class gets deleted)
3868: // we need to check to see if there is an element to delete
3869: // this introduces a problem with the ability to delete a reference
3870: // library (because there is not an element on it)
3871: // so we are special casing the reference library
3872: String parentName = ""; //$NON-NLS-1$
3873: IPropertyElement parentEle = pEle
3874: .getParent();
3875: if (parentEle != null) {
3876: parentName = parentEle
3877: .getName();
3878: }
3879: Object pDisp = delEle.getElement();
3880: if (pDisp != null
3881: || parentName
3882: .equals("ReferencedLibraries")) //$NON-NLS-1$
3883: {
3884: m_PropEleMgr.deleteData(delEle,
3885: pEle);
3886: }
3887: } finally {
3888: PropertyEditorBlocker.unblock();
3889: }
3890: }
3891: }
3892: updateNodeAndParentNodes(node, pEle);
3893:
3894: //since the node is now removed, I want to refresh the parent
3895: if (parentNode != null) {
3896: boolean expanded = parentNode.isExpanded();
3897: if (expanded) {
3898: parentNode.setExpanded(false);
3899: parentNode.setExpanded(true);
3900: }
3901: }
3902: }
3903: }
3904: }
3905:
3906: // now that both the grid and the xml have been updated, process the parent nodes to see if their
3907: // format strings need to be updated
3908: refresh();
3909: }
3910: }
3911:
3912: /**
3913: * @param node
3914: * @param pEle
3915: */
3916: private void updateNodeAndParentNodes(JDefaultMutableTreeNode node,
3917: IPropertyElement pEle) {
3918: if (m_Model != null) {
3919: String name = pEle.getName();
3920: String value = pEle.getValue();
3921:
3922: IPropertyDefinition pDef = pEle.getPropertyDefinition();
3923: if (pDef != null) {
3924: String validVals = pDef.getValidValues();
3925: if (validVals != null
3926: && validVals.equals("FormatString")) //$NON-NLS-1$
3927: {
3928: m_PropEleMgr.interpretElementValue(pEle);
3929: String val2 = pEle.getValue();
3930: if (val2 == null || val2.length() == 0) {
3931: val2 = value;
3932: }
3933: //update this value in the data grid.
3934: } else if (name.equals("Name")) //$NON-NLS-1$
3935: {
3936: // if the element that we are editing/updating is the name value
3937: // then we also want to update the alias field because there were
3938: // some bugs entered where they were not in synch
3939: //
3940: // so, get the element at the next row (should be the alias)
3941: int aliasRow = m_LastRow + 1;
3942: IPropertyElement aliasEle = getElementAtGridRow(aliasRow);
3943: if (aliasEle != null) {
3944: String tempName = aliasEle.getName();
3945: if (tempName != null
3946: && tempName.equals("Alias")) //$NON-NLS-1$
3947: {
3948: // now rebuild the value because by setting the name
3949: // the alias could have changed
3950: IPropertyDefinition tempDef = aliasEle
3951: .getPropertyDefinition();
3952: Object tempMod = aliasEle.getElement();
3953: IPropertyElement tempEle = m_PropEleMgr
3954: .buildElement(tempMod, tempDef,
3955: null);
3956: String val2 = tempEle.getValue();
3957: refresh();
3958: }
3959: }
3960: }
3961: }
3962: updateNecessaryParents(node, pEle);
3963: }
3964: }
3965:
3966: /**
3967: * Some of the updates that occur in the grid may also warrant a change to a node above it
3968: *
3969: *
3970: * @param pNode[in] The current grid node
3971: * @param pEle[in] The current property element
3972: *
3973: * @return HRESULT
3974: *
3975: */
3976: private void updateNecessaryParents(JDefaultMutableTreeNode node,
3977: IPropertyElement pEle) {
3978: if (m_Model != null) {
3979: IPropertyDefinition pDef = pEle.getPropertyDefinition();
3980: if (pDef != null) {
3981: IPropertyElement parentEle = pEle.getParent();
3982: if (parentEle != null) {
3983: IPropertyDefinition parentDef = parentEle
3984: .getPropertyDefinition();
3985: if (parentDef != null) {
3986: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) node
3987: .getParent();
3988: if (parentNode != null) {
3989: String validVals = parentDef
3990: .getValidValues();
3991: boolean alreadyProcessed = false;
3992: if (validVals != null
3993: && validVals.equals("FormatString")) //$NON-NLS-1$
3994: {
3995: Object obj = parentNode.getUserObject();
3996: if (obj != null
3997: && obj instanceof IPropertyElement) {
3998: IPropertyElement propEle = (IPropertyElement) obj;
3999: m_PropEleMgr
4000: .interpretElementValue(parentEle);
4001: alreadyProcessed = true;
4002: }
4003: }
4004: updateNecessaryParents(parentNode,
4005: parentEle);
4006: }
4007: }
4008: }
4009: }
4010: }
4011: }
4012:
4013: /**
4014: * Special processing for associated diagrams on diagram and element
4015: *
4016: *
4017: * @param pEle[in] The property element that houses the diagram info that is being deleted
4018: *
4019: * @return HRESULT
4020: *
4021: */
4022: private void deleteDiagram(IPropertyElement pEle) {
4023: if (pEle != null) {
4024: // first ask the user about deleting this association
4025: boolean answer = false;
4026: IQuestionDialog pQuestionDiag = new SwingQuestionDialogImpl();
4027: if (pQuestionDiag != null) {
4028: String text = PropertyEditorResources
4029: .getString("PropertyEditor.DeleteQuestion");
4030: QuestionResponse result = pQuestionDiag
4031: .displaySimpleQuestionDialog(
4032: SimpleQuestionDialogKind.SQDK_YESNO,
4033: MessageIconKindEnum.EDIK_ICONQUESTION,
4034: text, 0, null, "");
4035: if (result.getResult() == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
4036: Object pTopDisp = getTopModelElement(pEle);
4037: if (pTopDisp instanceof IElement) {
4038: IElement pTopElement = (IElement) pTopDisp;
4039: // the top guy is an element or an open diagram
4040: if (pTopElement instanceof IDiagram) {
4041: IDiagram pDiagram = (IDiagram) pTopElement;
4042: // the top guy is an open diagram
4043: // get the element that we are deleting
4044: Object pDisp = pEle.getElement();
4045: // figure out if it is a closed diagram or an element (maybe an open diagram)
4046: if (pDisp instanceof IProxyDiagram) {
4047: IProxyDiagram pDiag = (IProxyDiagram) pDisp;
4048: // deleting a closed diagram from an open diagram's properties
4049: String xmiID = pDiag.getXMIID();
4050: String xmiID2 = pDiagram.getXMIID();
4051: pDiagram.removeAssociatedDiagram(xmiID);
4052: pDiag.removeAssociatedDiagram(xmiID2);
4053: } else if (pDisp instanceof IElement) {
4054: IElement pElement = (IElement) pDisp;
4055: if (pElement instanceof IDiagram) {
4056: IDiagram pDiagram2 = (IDiagram) pElement;
4057: // deleting an open diagram from an open diagram's properties
4058: String xmiID = pDiagram2.getXMIID();
4059: String xmiID2 = pDiagram.getXMIID();
4060: pDiagram
4061: .removeAssociatedDiagram(xmiID);
4062: pDiagram2
4063: .removeAssociatedDiagram(xmiID2);
4064: } else {
4065: // deleting an element from an open diagram's properties
4066: pDiagram
4067: .removeAssociatedElement2(pElement);
4068: }
4069: }
4070: } else {
4071: // the top guy is an element
4072: // get the element that we are deleting
4073: Object pDisp = pEle.getElement();
4074: // figure out if it is a closed diagram or an element (maybe an open diagram)
4075: if (pDisp instanceof IProxyDiagram) {
4076: IProxyDiagram pDiag = (IProxyDiagram) pDisp;
4077: // deleting a closed diagram from an element's properties
4078: pDiag
4079: .removeAssociatedElement(pTopElement);
4080: } else if (pDisp instanceof IElement) {
4081: IElement pElement = (IElement) pDisp;
4082: if (pElement instanceof IDiagram) {
4083: IDiagram pDiagram2 = (IDiagram) pElement;
4084: // deleting an open diagram from an element's properties
4085: pDiagram2
4086: .removeAssociatedElement2(pTopElement);
4087: }
4088: }
4089: }
4090: } else if (pTopDisp instanceof IProxyDiagram) {
4091: IProxyDiagram pTopDiag = (IProxyDiagram) pTopDisp;
4092: // the top guy is a closed diagram
4093: // so get what we are deleting
4094: Object pDisp = pEle.getElement();
4095: if (pDisp instanceof IProxyDiagram) {
4096: IProxyDiagram pDiag2 = (IProxyDiagram) pDisp;
4097: // deleting a closed diagram from a closed diagram's properties
4098: pDiag2.removeDualAssociatedDiagrams(
4099: pTopDiag, pDiag2);
4100: }
4101: // could be deleting an element or an open diagram from a closed diagram's properties
4102: else if (pDisp instanceof IElement) {
4103: IElement pElement = (IElement) pDisp;
4104: if (pElement instanceof IDiagram) {
4105: IDiagram pDiagram2 = (IDiagram) pElement;
4106: String xmiID = pDiagram2.getXMIID();
4107: // deleting an open diagram from a closed diagram's properties
4108: pDiagram2
4109: .removeAssociatedDiagram2(pTopDiag);
4110: pTopDiag.removeAssociatedDiagram(xmiID);
4111: } else {
4112: // deleting an element from a closed diagram's properties
4113: pTopDiag
4114: .removeAssociatedElement(pElement);
4115: }
4116: }
4117: }
4118:
4119: }
4120: }
4121: }
4122: }
4123:
4124: /**
4125: * Special processing for associated diagrams on diagram and element
4126: *
4127: *
4128: * @param pEle[in] The property element that houses the diagram info that is being deleted
4129: *
4130: * @return HRESULT
4131: *
4132: */
4133: private void deleteReference(IPropertyElement delEle,
4134: IPropertyElement pEle) {
4135: if (pEle != null && delEle != null) {
4136: // first ask the user about deleting this reference
4137: boolean answer = false;
4138: IQuestionDialog pQuestionDiag = new SwingQuestionDialogImpl();
4139: if (pQuestionDiag != null) {
4140: String text = PropertyEditorResources
4141: .getString("PropertyEditor.DeleteQuestion");
4142: QuestionResponse result = pQuestionDiag
4143: .displaySimpleQuestionDialog(
4144: SimpleQuestionDialogKind.SQDK_YESNO,
4145: MessageIconKindEnum.EDIK_ICONQUESTION,
4146: text, 0, null, "");
4147: if (result.getResult() == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
4148: // delete, make sure to create a blocker to block other events!
4149: // only want to call delete if there is an element to delete
4150: PropertyEditorBlocker.block();
4151: try {
4152: Object pDisp = delEle.getElement();
4153: if (pDisp != null) {
4154: m_PropEleMgr.deleteData(delEle, pEle);
4155: }
4156: } finally {
4157: PropertyEditorBlocker.unblock();
4158: }
4159: }
4160: }
4161: }
4162: }
4163:
4164: /**
4165: * Refresh the grid node in the grid. This is only used to add a node to a collection. It adds
4166: * the proper property elements and then expands the proper node and places you in edit mode on the
4167: * added node
4168: *
4169: * @param[in] row The row to refresh
4170: * @param[in] pEle The property element associated with the row to refresh
4171: *
4172: * @return HRESULT
4173: *
4174: */
4175: private JDefaultMutableTreeNode addNodeToGrid(int row,
4176: IPropertyElement pEle) {
4177: JDefaultMutableTreeNode retObj = null;
4178: if (m_Tree != null) {
4179: // get the grid node at the passed in row
4180: JDefaultMutableTreeNode curNode = getNodeAtGridRow(row);
4181: if (curNode != null) {
4182: // get the grid node that is this node's collection node
4183: JDefaultMutableTreeNode colNode = getCollectionGridNode(
4184: curNode, row);
4185: if (colNode != null) {
4186: // refresh the property elements for this grid node
4187: pEle.setModified(true);
4188: IPropertyDefinition pDef = pEle
4189: .getPropertyDefinition();
4190: JDefaultMutableTreeNode addedNode = addSubElementToTable(
4191: colNode, pDef, pEle, false);
4192:
4193: // now deal with the grid node
4194: // we want to collapse any children and then expand the node that we just
4195: // created (this will be the last node of the collection)
4196: if (colNode.getChildCount() > 0) {
4197: DefaultMutableTreeNode child = (DefaultMutableTreeNode) colNode
4198: .getFirstChild();
4199: int i = 1;
4200: while (child != null) {
4201: if (child instanceof JDefaultMutableTreeNode) {
4202: ((JDefaultMutableTreeNode) child)
4203: .setExpanded(false);
4204: //m_Tree.expandNode((JDefaultMutableTreeNode)child, false);
4205: m_Tree.getTree().expandNode(row + i,
4206: false);
4207: m_Model.expand(row + i, false);
4208: }
4209: child = child.getNextSibling();
4210: i++;
4211: }
4212:
4213: //now expand the last node
4214: child = (DefaultMutableTreeNode) colNode
4215: .getLastChild();
4216: if (child instanceof JDefaultMutableTreeNode) {
4217: retObj = (JDefaultMutableTreeNode) child;
4218: ((JDefaultMutableTreeNode) child)
4219: .setExpanded(true);
4220: int childLevel = colNode.getIndex(child);
4221: //m_Tree.expandNode((JDefaultMutableTreeNode)child, true);
4222: m_Tree.getTree().expandNode(
4223: row + childLevel + 1, true);
4224: m_Model.expand(row + childLevel + 1, true);
4225: // this is ugly, but I cannot figure out another way to do this
4226: // in order for the create/set/insert problems to go away, nodes need to be marked
4227: // so that we know when to do a create, a set, or an insert
4228: //
4229: // when a node is first added to the grid, if it is a record, it is marked as "Record"
4230: // this code is invoked when something new is added to the grid
4231: // if there is no model element associated with it, we don't want to mark it as "Record",
4232: // but we do need to mark it so that we can get to it when doing a save
4233: Object pDisp2 = pEle.getElement();
4234: String temp = pEle.getName();
4235: if (pDisp2 == null
4236: || (temp != null && temp
4237: .equals("Multiplicity"))) //$NON-NLS-1$
4238: {
4239: addedNode.setKey("RecordNew"); //$NON-NLS-1$
4240: }
4241:
4242: // expand this last child
4243: addedNode.setExpanded(true);
4244:
4245: // get the first child of this last one
4246: JDefaultMutableTreeNode firstNode = (JDefaultMutableTreeNode) addedNode
4247: .getFirstChild();
4248:
4249: if (firstNode != null) {
4250: // set focus to this field
4251: int firstRow = firstNode.getRow();
4252:
4253: //set focus on this row, edit it.
4254: }
4255: }
4256: }
4257: }
4258: }
4259: }
4260: return retObj;
4261: }
4262:
4263: /**
4264: * Method to navigate up the grid node chain to retrieve the grid node that represents
4265: * the collection that the passed in grid node is in.
4266: *
4267: * @param[in] pNode The grid node in which to get the collection grid node that it belongs to
4268: * @param[out] pCollectionNode The grid node that is the collection node
4269: *
4270: * @return HRESULT
4271: *
4272: */
4273: private JDefaultMutableTreeNode getCollectionGridNode(
4274: JDefaultMutableTreeNode curNode, int curRow) {
4275: JDefaultMutableTreeNode retCol = null;
4276:
4277: // get the property element at the row where user clicked
4278: IPropertyElement pEle = getElementAtGridRow(curRow);
4279: if (pEle != null) {
4280: // get the corresponding definition
4281: IPropertyDefinition pDef = pEle.getPropertyDefinition();
4282: if (pDef != null) {
4283: // if the element has a property definition that is multiple, then we have found it
4284: long mult = pDef.getMultiplicity();
4285: if (mult == 1) {
4286: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) curNode
4287: .getParent();
4288: if (parentNode != null) {
4289: int loc = findNodeRowInTreeTable(parentNode);
4290: retCol = getCollectionGridNode(parentNode, loc);
4291: }
4292: } else {
4293: retCol = curNode;
4294: }
4295: }
4296: }
4297:
4298: return retCol;
4299: }
4300:
4301: /**
4302: * @param parentNode
4303: * @return
4304: */
4305: private int findNodeRowInTreeTable(JDefaultMutableTreeNode pNode) {
4306: // TODO Auto-generated method stub
4307: return 0;
4308: }
4309:
4310: /**
4311: * Called when the user has clicked on a row and is expanding the grid node
4312: *
4313: * @param[in] row The row that is being expanded
4314: *
4315: * @return HRESULT
4316: *
4317: */
4318: public void onNodeExpanding(int row) {
4319: // Block other events from coming in when we don't want them.
4320: PropertyEditorBlocker.block();
4321: try {
4322: // get the property element at the row where user clicked
4323: IPropertyElement pEle = getElementAtGridRow(row);
4324: if (pEle != null) {
4325: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
4326: int countChild = node.getChildCount();
4327: if (countChild == 0) {
4328: Vector<IPropertyElement> subElems = pEle
4329: .getSubElements();
4330: if (subElems != null && subElems.size() > 0) {
4331: //if this property element was build earlier, we want to rebuild it,
4332: //since we are rebuilding the default node.
4333: pEle
4334: .setSubElements(new Vector<IPropertyElement>());
4335: }
4336:
4337: buildAndExpandNode(row);
4338: }
4339:
4340: pEle = getElementAtGridRow(row);
4341: String name = pEle.getName();
4342: if (name.equals("dummy")) //$NON-NLS-1$
4343: {
4344: // get the corresponding definition
4345: IPropertyDefinition pd = pEle
4346: .getPropertyDefinition();
4347: if (pd != null) {
4348: // get the model element on the property element
4349: Object curModEle = pEle.getElement();
4350:
4351: // get the property definition representing this model element
4352: IPropertyDefinition pd2 = getPropertyDefinition(pEle);
4353:
4354: if (pd2 != null) {
4355: m_PropEleMgr.reloadElement(curModEle, pd2,
4356: pEle);
4357: filterPropertyElement(pEle);
4358: refreshElementInGrid(row, pEle);
4359: }
4360: }
4361: } else {
4362: boolean refresh = false;
4363:
4364: // get its sub elements
4365: Vector<IPropertyElement> subEles = pEle
4366: .getSubElements();
4367: if (subEles != null) {
4368: int count = subEles.size();
4369: for (int i = 0; i < count; i++) {
4370: IPropertyElement subEle = subEles
4371: .elementAt(i);
4372:
4373: // get the corresponding definition
4374: IPropertyDefinition subDef = subEle
4375: .getPropertyDefinition();
4376: if (subDef != null) {
4377: // has the definition been marked as on demand
4378: boolean onDem = subDef.isOnDemand();
4379: if (onDem) {
4380: Object modEle = subEle.getElement();
4381: IPropertyDefinition pd2 = getPropertyDefinition(subEle);
4382: if (pd2 != null) {
4383: m_PropEleMgr
4384: .reloadElementWithDummy(
4385: modEle, pd2,
4386: subEle);
4387: refresh = true;
4388: }
4389: }
4390: }
4391: }
4392: if (refresh) {
4393: refreshElementInGrid(row, pEle);
4394: }
4395: }
4396: }
4397: }
4398: } finally {
4399: PropertyEditorBlocker.unblock();
4400: }
4401: }
4402:
4403: private IPropertyElement createEmptyPropertyElement(int row,
4404: boolean filter) {
4405: IPropertyElement newEle = null;
4406:
4407: // get the property element at the row that we are on
4408: IPropertyElement pEle = getElementAtGridRow(row);
4409: if (pEle != null) {
4410: // get the element that represents the collection element
4411: // If the user has gotten this far, they have right clicked either on a collection or on a node
4412: // that is under the collection. We need to get the collection element.
4413: IPropertyElement colEle = getCollectionElement(pEle);
4414: if (colEle != null) {
4415: // get the property definition associated with the collection element
4416: IPropertyDefinition colDef = colEle
4417: .getPropertyDefinition();
4418: if (colDef != null) {
4419: // We are not actually concerned with the collection definition, we are concerned with the
4420: // sub definition because that will tell us what we need to build
4421: IPropertyDefinition indivDef = colDef
4422: .getSubDefinition(0);
4423: if (indivDef != null) {
4424: // have the definition that needs to be built, so get its name
4425: String indDefName = indivDef.getName();
4426:
4427: // get the current model element and save off for later use
4428: Object mainEle = m_PropEleMgr.getModelElement();
4429:
4430: // determine if the definition with this name has been built, if not build it
4431: // this will be the definition "Attribute" (whatever we are creating)
4432: IPropertyDefinition newDef = m_Factory
4433: .getPropertyDefinitionForElement(
4434: indDefName, mainEle);
4435: if (newDef != null) {
4436: // have the definition, so set up its parent, because it may have just been built
4437: newDef.setParent(colDef);
4438:
4439: // now that we have the definition, we need to build the corresponding empty property element
4440: IPropertyElement newPropEle = null;
4441: // but we were having problems building property elements for something that
4442: // did not have a model element with it
4443: // we were getting collections that we didn't want to show (references)
4444: // and then when we implemented the filter, we didn't know what filter to
4445: // use because there was no model element
4446: FactoryRetriever ret = FactoryRetriever
4447: .instance();
4448: // so we are going to create a fake model element to go on this property
4449: // element structure so that the build and the filter work right
4450: // but then we will remove it so that the save will also work ("create")
4451: // but first see if it is a valid metatype
4452: ICoreProduct cProd = CoreProductManager
4453: .instance().getCoreProduct();
4454: //IProduct prod = ProductHelper.getProduct();
4455: Object tempDisp = null;
4456: if (cProd != null) {
4457: //ICreationFactory fact = cProd.getCreationFactory();
4458: // ICreationFactory fact = new CreationFactory();//cProd.getCreationFactory();
4459: // ConfigManager conMan = new ConfigManager();
4460: // fact.setConfigManager(conMan);
4461: //if (fact != null)
4462: {
4463: try {
4464: //fact = new ICreationFactoryProxy((Dispatch)fact);
4465: //Object disp = fact.retrieveMetaType(indDefName, null);
4466: tempDisp = ret.createType(
4467: indDefName, null);
4468:
4469: //using the newDef, find the right class for this object and create it
4470: if (tempDisp instanceof INamedElement) {
4471: String id = newDef.getID();
4472: if (id != null
4473: && id.length() > 0) {
4474: try {
4475: Class clazz = Class
4476: .forName(id);
4477: //tempDisp = (clazz)tempDisp;
4478: } catch (Exception e1) {
4479: // TODO Auto-generated catch block
4480: e1
4481: .printStackTrace();
4482: }
4483: }
4484: }
4485: //tempDisp = disp;
4486: } catch (Exception e) {
4487: e.printStackTrace();
4488: }
4489: }
4490: }
4491:
4492: // blanking out the model element that the manager knows about will allow us to
4493: // create a dummy structure
4494: m_PropEleMgr.setModelElement(null);
4495: m_PropEleMgr.setCreateSubs(true);
4496: newPropEle = m_PropEleMgr
4497: .buildTopPropertyElement(newDef);
4498: if (newPropEle != null) {
4499: // now temporarily store the fake new model element on this new property
4500: // element so that the filter will work
4501: newPropEle.setElement(tempDisp);
4502: //newPropEle = m_PropEleMgr.buildElement(tempDisp, newDef, null);
4503: //newPropEle = m_PropEleMgr.buildElement(null, newDef, null);
4504:
4505: // have built the property element, so set it as modified and add it to the collection
4506: // of property elements
4507: newPropEle.setModified(true);
4508:
4509: if (filter) {
4510: // now add this new one to the collection
4511: colEle.addSubElement(newPropEle);
4512:
4513: // now that we have built the property element structure
4514: // check the definition filter to see if any of the elements need to
4515: // change
4516: filterPropertyElement(newPropEle);
4517: }
4518:
4519: // done with the filtering, so set its model element back to 0 so that
4520: // the saves, creates will work properly
4521: newPropEle.setElement(null);
4522: newEle = newPropEle;
4523: }
4524: }
4525: // reset the model element
4526: m_PropEleMgr.setModelElement(mainEle);
4527: }
4528: }
4529: }
4530: }
4531:
4532: return newEle;
4533: }
4534:
4535: /**
4536: * Shortcut method to retrieve the data from the grid cell which is in the form of a IPropertyElement
4537: *
4538: * @param[in] row The row to retrieve the property element from
4539: * @param[out] pEle The found property element
4540: *
4541: * @return HRESULT
4542: *
4543: */
4544: public IPropertyElement getElementAtGridRow(int row) {
4545: IPropertyElement retEle = null;
4546:
4547: if (row > 0 && m_Tree != null) {
4548: JTree tree = m_Tree.getTree();
4549: TreePath path = tree.getPathForRow(row);
4550: if (path != null) {
4551: Object obj = path.getLastPathComponent();
4552: if (obj instanceof JDefaultMutableTreeNode) {
4553: JDefaultMutableTreeNode node = (JDefaultMutableTreeNode) obj;
4554: retEle = (IPropertyElement) node.getUserObject();
4555: }
4556: }
4557: }
4558: return retEle;
4559: }
4560:
4561: public JDefaultMutableTreeNode getNodeAtGridRow(int row) {
4562: JDefaultMutableTreeNode retNode = null;
4563:
4564: if (row >= 0 && m_Tree != null) {
4565: JTree tree = m_Tree.getTree();
4566: TreePath path = tree.getPathForRow(row);
4567: if (path != null) {
4568: Object obj = path.getLastPathComponent();
4569: if (obj instanceof JDefaultMutableTreeNode) {
4570: retNode = (JDefaultMutableTreeNode) obj;
4571: }
4572: }
4573: }
4574: return retNode;
4575: }
4576:
4577: public void setCurrentRow(int row) {
4578: //save the last selected row as the last row and store the new value
4579: if (m_CurRow == 0) {
4580: m_LastRow = row;
4581: } else {
4582: m_LastRow = m_CurRow;
4583: }
4584:
4585: m_CurRow = row;
4586: }
4587:
4588: /**
4589: * Refresh the element in the grid. This will remove any unwanted nodes and then add any others.
4590: *
4591: * @param[in] row The row to refresh
4592: * @param[in] propEle The property element associated with the row to be refreshed
4593: *
4594: * @return HRESULT
4595: *
4596: */
4597: public void refreshElementInGrid(int row, IPropertyElement pEle) {
4598: if (m_Tree != null) {
4599: // get the grid node at the passed in row
4600: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
4601: if (node != null) {
4602: // get all of the children of this grid node and remove them from the bottom up
4603: node.removeAllChildren();
4604:
4605: // now process the property element
4606: // get the corresponding definition
4607: buildSubElementsThatNeedToDisplay(pEle, node);
4608: }
4609: }
4610: }
4611:
4612: public void onKeyDownGrid(KeyEvent e) {
4613: if (m_Tree != null) {
4614: int row = m_CurRow;
4615: int keyCode = e.getKeyCode();
4616: if (keyCode == KeyEvent.VK_ENTER
4617: || keyCode == KeyEvent.VK_ESCAPE) {
4618: m_Tree.editingCanceled(null);
4619: //keep the focus on this row.
4620: startEditingRowAt(row);
4621: } else if (keyCode == KeyEvent.VK_TAB) {
4622: try {
4623: if (e.isShiftDown()) {
4624: startEditingRowAt(row - 1);
4625: } else {
4626: startEditingRowAt(row + 1);
4627: }
4628: } catch (Exception exc) {
4629: }
4630: } else if (e.getKeyCode() == KeyEvent.VK_UP) {
4631: try {
4632: startEditingRowAt(row - 1);
4633: } catch (Exception exc) {
4634: }
4635: } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
4636: try {
4637: startEditingRowAt(row + 1);
4638: } catch (Exception exc) {
4639: }
4640: } else if (keyCode == KeyEvent.VK_LEFT) {
4641: IPropertyElement pEle = getElementAtGridRow(row);
4642: if (pEle != null) {
4643: IPropertyDefinition pDef = pEle
4644: .getPropertyDefinition();
4645: if (pDef != null) {
4646: String cType = pDef.getControlType();
4647: if (cType == null
4648: || (cType != null && cType
4649: .equals("read-only"))) {
4650: m_Tree.editingCanceled(null);
4651: //collapse the row
4652: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
4653: if (node != null) {
4654: node.setExpanded(false);
4655: m_Model.expand(row, false);
4656: }
4657: // tried this, but it made the property editor totally lose focus on the current cell
4658: // so editCellAt is not ideal, but is better than what we got (you lose the highlight
4659: // of the current cell, but if you arrow around, you get it back
4660: //e.consume();
4661: //startEditingRowAt(row);
4662: m_Tree.editCellAt(row, 2, e);
4663: }
4664: }
4665: }
4666: } else if (keyCode == KeyEvent.VK_RIGHT) {
4667: IPropertyElement pEle = getElementAtGridRow(row);
4668: if (pEle != null) {
4669: IPropertyDefinition pDef = pEle
4670: .getPropertyDefinition();
4671: if (pDef != null) {
4672: String cType = pDef.getControlType();
4673: if (cType == null
4674: || (cType != null && cType
4675: .equals("read-only"))) {
4676: m_Tree.editingCanceled(null);
4677:
4678: //expand the row
4679: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
4680: if (node != null) {
4681: onNodeExpanding(row);
4682: node.setExpanded(false);
4683: m_Model.expand(row, true);
4684: }
4685: // tried this, but it made the property editor totally lose focus on the current cell
4686: // so editCellAt is not ideal, but is better than what we got (you lose the highlight
4687: // of the current cell, but if you arrow around, you get it back
4688: //e.consume();
4689: //startEditingRowAt(row);
4690: m_Tree.editCellAt(row, 2, e);
4691: }
4692: }
4693: }
4694: } else if (keyCode == KeyEvent.VK_INSERT) {
4695: IPropertyElement pEle = getElementAtGridRow(row);
4696: onPopupCreate(row, pEle);
4697: } else if (keyCode == KeyEvent.VK_DELETE) {
4698: IPropertyElement pEle = getElementAtGridRow(row);
4699:
4700: //set the rightClick row to this row number
4701: m_RightClickRow = row;
4702: onPopupDelete();
4703: }
4704: }
4705: }
4706:
4707: public void editNextRow() {
4708: startEditingRowAt(m_CurRow + 1);
4709: }
4710:
4711: public void startEditingRowAt(int row) {
4712: try {
4713: if (m_Tree != null) {
4714: m_Tree.editingCanceled(null);
4715: m_Tree.editCellAt(row, 2);
4716: TableCellEditor editor = m_Tree.getCellEditor(row, 2);
4717: if (editor != null) {
4718: Object obj = getEditingComponent();
4719: if (obj != null && obj instanceof Component) {
4720: ((Component) obj).requestFocus();
4721: if (obj instanceof JTextField) {
4722: ((JTextField) obj).selectAll();
4723: } else if (obj instanceof JComboBox) {
4724: Component comp = ((JComboBox) obj)
4725: .getEditor().getEditorComponent();
4726: if (comp != null
4727: && comp instanceof JTextField) {
4728: ((JTextField) comp).requestFocus();
4729: ((JTextField) comp).selectAll();
4730: }
4731: }
4732: }
4733: }
4734: setCurrentRow(row);
4735: m_Tree.getSelectionModel().setSelectionInterval(row,
4736: row);
4737: }
4738: } catch (Exception exc) {
4739: }
4740: }
4741:
4742: private void refreshRootNode(IPropertyElement pEle,
4743: JDefaultMutableTreeNode root) {
4744: if (m_Tree != null) {
4745: if (root != null) {
4746: // get all of the children of this grid node and remove them from the bottom up
4747: root.removeAllChildren();
4748:
4749: // now process the property element
4750: // get the corresponding definition
4751: buildSubElementsThatNeedToDisplay(pEle, root);
4752: populateGrid();
4753: }
4754: }
4755: }
4756:
4757: private void refreshRootNodeAfterFilter(IPropertyElement pEle) {
4758: if (m_Tree != null) {
4759: if (m_root != null) {
4760: //We can reach here only if there is only one element being shown
4761: JDefaultMutableTreeNode rootNode = (JDefaultMutableTreeNode) m_root
4762: .getChildAt(0);
4763: // get all of the children of this grid node and remove them from the bottom up
4764: rootNode.removeAllChildren();
4765:
4766: Object obj = rootNode.getUserObject();
4767: if (obj != null && obj instanceof IPropertyElement) {
4768: IPropertyElement rootEle = (IPropertyElement) obj;
4769:
4770: //remove all existing subElements
4771: rootEle
4772: .setSubElements(new Vector<IPropertyElement>());
4773:
4774: Vector<IPropertyElement> propElems = new Vector<IPropertyElement>();
4775: Vector<IPropertyDefinition> propDefs = new Vector<IPropertyDefinition>();
4776:
4777: // now process the property element
4778: // get the corresponding definition
4779: //buildSubElementsThatNeedToDisplay(pEle, m_root);
4780:
4781: if (rootEle.equals(pEle)) {
4782: if (m_CurLoadedObject != null
4783: && m_CurLoadedObject instanceof IElement) {
4784: loadElement((IElement) m_CurLoadedObject);
4785: }
4786: } else {
4787: //we have just built a small collection node
4788: rootEle.addSubElement(pEle);
4789: propElems.add(rootEle);
4790: setPropertyElements(propElems);
4791: //populateGrid();
4792:
4793: //at this point I want to build the node and expand it.
4794: Vector subElems = pEle.getSubElements();
4795:
4796: //we want to expand the child node - this will build it if the
4797: //property element is not built already.
4798: onNodeExpanding(1);
4799:
4800: m_Model.expand(1, true);
4801: refresh();
4802: }
4803: }
4804: }
4805: }
4806: }
4807:
4808: /**
4809: *
4810: */
4811: public void refresh() {
4812: Graphics g = this .getGraphics();
4813: if (g != null) {
4814: this .paintAll(g);
4815: }
4816: }
4817:
4818: /**
4819: * Called when dialog is initialized
4820: *
4821: * @param[in] uMsg
4822: * @param[in] wParam
4823: * @param[in] lParam
4824: * @param[out] bHandled
4825: *
4826: * @return LRESULT
4827: *
4828: */
4829: public void onInitDialog() {
4830: if (m_Factory == null) {
4831: m_Factory = new PropertyDefinitionFactory();
4832: }
4833:
4834: if (m_Factory != null) {
4835: ICoreProduct prod = CoreProductManager.instance()
4836: .getCoreProduct();
4837: IConfigManager conMan = prod.getConfigManager();
4838: if (conMan != null) {
4839: String home = conMan.getDefaultConfigLocation();
4840: String file = home + "PropertyDefinitions.etc"; //$NON-NLS-1$
4841: m_Factory.setDefinitionFile(file);
4842: }
4843: }
4844: if (m_PropEleMgr == null) {
4845: m_PropEleMgr = getPropertyElementManager();
4846: }
4847:
4848: m_PropEleMgr.setPDFactory(m_Factory);
4849: m_ResourceMgr = CommonResourceManager.instance();
4850:
4851: // m_ReadOnlyColor = RGB(232, 228, 232);
4852: // m_ReadOnlyColor2 = RGB(192, 192, 192);
4853: // m_EditableColor = GetSysColor(COLOR_WINDOW);
4854:
4855: m_Filter = new PropertyEditorFilter();
4856: m_Filter.build();
4857:
4858: // help box
4859: initializeHelpBox();
4860:
4861: // buttons
4862: initializeButtons();
4863:
4864: // grid stuff
4865: initializeGrid();
4866: // combo box, must be after the grid, because we use the mode which is determined
4867: // in the grid stuff
4868: initializeComboBox();
4869: // fill in the grid
4870: populateGrid();
4871:
4872: // Initialize tooltips for grid
4873: m_ToolTip = createToolTip();
4874:
4875: }
4876:
4877: /**
4878: * Called when the navigate popup menu is clicked upon
4879: *
4880: * @param[in] wNotifyCode
4881: * @param[in] wID
4882: * @param[in] hWndCtrl
4883: * @param[out] bHandled
4884: *
4885: * @return LRESULT
4886: *
4887: */
4888: public void onPopupNavigate() {
4889: if (m_Model != null) {
4890: IPropertyElement pEle = getElementAtGridRow(m_CurRow);
4891: if (pEle != null) {
4892: Object pDisp = pEle.getElement();
4893: if (pDisp != null) {
4894: if (pDisp instanceof IReference) {
4895: IReference pReference = (IReference) pDisp;
4896: String name = pEle.getName();
4897: IElement pElement2 = null;
4898: if (name.equals("ReferredElement")) //$NON-NLS-1$
4899: {
4900: pElement2 = pReference.getReferredElement();
4901: } else if (name.equals("ReferencingElement")) //$NON-NLS-1$
4902: {
4903: pElement2 = pReference
4904: .getReferencingElement();
4905: }
4906:
4907: if (pElement2 != null) {
4908: IFindController controller = new FindController();
4909: controller.navigateToElement(pElement2);
4910: }
4911: } else if (pDisp instanceof IElement) {
4912: IElement pElement = (IElement) pDisp;
4913: IFindController controller = new FindController();
4914: controller.navigateToElement(pElement);
4915: } else if (pDisp instanceof IProxyDiagram) {
4916: IProxyDiagram pDiagram = (IProxyDiagram) pDisp;
4917: IProductDiagramManager pManager = ProductHelper
4918: .getProductDiagramManager();
4919: if (pManager != null) {
4920: IDiagram dia = pManager.openDiagram2(
4921: pDiagram, true, null);
4922: }
4923: }
4924: }
4925: }
4926: }
4927: }
4928:
4929: /**
4930: * Called when the fill down popup menu is clicked upon. This takes the value in the first
4931: * selected row and changes the information of all of the other rows that are selected to
4932: * the value in the first row.
4933: *
4934: * @param[in] wNotifyCode
4935: * @param[in] wID
4936: * @param[in] hWndCtrl
4937: * @param[out] bHandled
4938: *
4939: * @return LRESULT
4940: *
4941: */
4942: public void onPopupFill() {
4943: if (m_Model != null && m_Tree != null) {
4944: PropertyEditorBlocker.block();
4945: try {
4946: // need a temporary array of property elements
4947: Vector<IPropertyElement> temp = new Vector<IPropertyElement>();
4948:
4949: boolean haveValue = false;
4950: // having problems with the GetSelectedRows method, so we are just going
4951: // to loop through all of the rows in the grid and see if they are selected
4952: int countRows = m_Tree.getRowCount();
4953: String eleValue = null;
4954: String textValue = null;
4955:
4956: for (int i = 1; i < countRows; i++) {
4957: boolean selected = true;//m_Tree.isRowSelected(i);
4958: if (selected) {
4959: IPropertyElement pEle = getElementAtGridRow(i);
4960: if (pEle != null) {
4961: if (!haveValue) {
4962: // if we don't have a value yet, this must be the first one selected, so
4963: // we want to get its information to use for the value to set the rest of the
4964: // selected rows to
4965: // get the information from both the element and the grid
4966: // because they could be different (stored vs displayed values)
4967: eleValue = pEle.getValue();
4968: textValue = (String) m_Tree.getValueAt(
4969: i, 2);
4970: haveValue = true;
4971: } else {
4972: // if we already have a value, and the item is selected, then this is an
4973: // element that we want to "fill" or set its value
4974:
4975: // we don't want to process a top level node, if it is selected, so check
4976: IPropertyElement parEle = pEle
4977: .getParent();
4978: if (parEle != null) {
4979: // set that it is being modified, set its value, and set the grid text
4980: m_Tree.setValueAt(textValue, i, 2);
4981: updatePropertyElementValue(i, pEle,
4982: textValue);
4983: temp.add(pEle);
4984: }
4985: }
4986: }
4987: }
4988: }
4989: // we have set the information in the grid, now need to set it in the xml
4990: int count = temp.size();
4991: for (int j = 0; j < count; j++) {
4992: IPropertyElement ele = temp.get(j);
4993: IPropertyDefinition def = ele
4994: .getPropertyDefinition();
4995: if (def != null) {
4996: setRowData(j, def, ele);
4997: }
4998: }
4999: m_Tree.updateUI();
5000: } finally {
5001: PropertyEditorBlocker.unblock();
5002: }
5003: }
5004: }
5005:
5006: /**
5007: * Called before a grid cell is left - grid event
5008: *
5009: * @return VOID
5010: *
5011: */
5012: public void onLeaveCellGrid() {
5013: if (m_Model != null && m_Tree != null) {
5014: m_LastRow = m_Tree.getSelectedRow();
5015: }
5016: }
5017:
5018: /**
5019: * Called when the associate popup menu is clicked upon
5020: *
5021: * @param[in] wNotifyCode
5022: * @param[in] wID
5023: * @param[in] hWndCtrl
5024: * @param[out] bHandled
5025: *
5026: * @return LRESULT
5027: *
5028: */
5029: public void onPopupAssociate() {
5030: Vector<IElement> tempElements = new Vector<IElement>();
5031: IPropertyElement pEle = getElementAtGridRow(m_CurRow);
5032: if (pEle != null) {
5033: Object pDisp = pEle.getElement();
5034: if (pDisp != null && pDisp instanceof IElement) {
5035: IElement pElement = (IElement) pDisp;
5036: tempElements.add(pElement);
5037:
5038: //AssociateDialog dialog = new AssociateDialog();
5039: //dialog.setElements(tempElements);
5040: //dialog.doModal();
5041: }
5042: }
5043: }
5044:
5045: /**
5046: * Some of the picklists used by the property editor are common and are built
5047: * from xpath queries. This routine executes the xpath query and then gets the
5048: * name from each element and stores it in a list buffer.
5049: *
5050: *
5051: * @param pEle[in] The current property element
5052: *
5053: * @return HRESULT
5054: */
5055: public String buildDataTypeList(IPropertyElement pEle) {
5056: if (m_ListBuffer == null || m_ListBuffer.length() == 0) {
5057: boolean useQName = getDataTypePreference();
5058:
5059: // need to block events here because we may be opening up projects in here
5060: // to populate the datatype lists
5061: PropertyEditorBlocker.block();
5062: try {
5063: IPropertyDefinition pDef = pEle.getPropertyDefinition();
5064: String str = null;
5065: if (pDef != null) {
5066: // get_validvalues3 uses the picklist manager
5067: IStrings strs = pDef.getValidValue(pEle);
5068: if (strs != null) {
5069: TreeMap<String, TreeMap<String, String>> theMap = new TreeMap<String, TreeMap<String, String>>();
5070: String empty = ""; //$NON-NLS-1$
5071: String full = null;
5072: int count = strs.getCount();
5073: for (int i = 0; i < count; i++) {
5074: String temp = strs.item(i);
5075: if (useQName && temp.length() > 0) {
5076: full = temp;
5077: int pos = full.lastIndexOf(':');
5078: if (pos >= 0) {
5079: temp = full.substring(pos + 1);
5080: empty = full.substring(0, pos - 1);
5081: } else {
5082: empty = ""; //$NON-NLS-1$
5083: }
5084: }
5085: String lower = temp.toLowerCase();
5086:
5087: TreeMap inner = theMap.get(lower);
5088: if (inner != null) {
5089: String found = (String) inner.get(full);
5090: if (found == null
5091: || found.length() == 0) {
5092: inner.put(full, temp);
5093: }
5094: } else {
5095: inner = new TreeMap<String, String>();
5096: inner.put(full, temp);
5097: theMap.put(lower, inner);
5098: }
5099: }
5100:
5101: Collection col = theMap.values();
5102: Object[] objs = col.toArray();
5103: int cnt = objs.length;
5104: for (int x = 0; x < cnt; x++) {
5105: Object obj = objs[x];
5106: if (obj instanceof TreeMap) {
5107: TreeMap hm = (TreeMap) obj;
5108: Collection col2 = hm.values();
5109: Object[] objs2 = col2.toArray();
5110: int cnt2 = objs2.length;
5111: for (int x2 = 0; x2 < cnt2; x2++) {
5112: Object obj2 = objs2[x2];
5113: if (obj2 instanceof String) {
5114: String temp = (String) obj2;
5115: if (str == null) {
5116: str = ""; //$NON-NLS-1$
5117: }
5118: if (str.length() > 0) {
5119: str += "|"; //$NON-NLS-1$
5120: }
5121: str += temp;
5122: if (useQName) {
5123: //I am commenting out right now,
5124: //need to uncomment later when I can handle
5125: //popup display with table format.
5126: //str += "\t";
5127: //str += temp;
5128: }
5129: }
5130: }
5131: }
5132: }
5133: }
5134: }
5135:
5136: if (str != null) {
5137: m_ListBuffer = "|"; //$NON-NLS-1$
5138: m_ListBuffer += str;
5139: }
5140: } finally {
5141: PropertyEditorBlocker.unblock();
5142: }
5143: }
5144: return m_ListBuffer;
5145: }
5146:
5147: /**
5148: * Called when the insert popup menu is clicked upon
5149: *
5150: * @param[in] wNotifyCode
5151: * @param[in] wID
5152: * @param[in] hWndCtrl
5153: * @param[out] bHandled
5154: *
5155: * @return LRESULT
5156: *
5157: */
5158: public void onPopupInsert() {
5159: JDefaultMutableTreeNode pBeforeNode = getNodeAtGridRow(m_CurRow);
5160: if (pBeforeNode != null) {
5161: // create an empty property element that is being inserted
5162: IPropertyElement pNewPropEle = createEmptyPropertyElement(
5163: m_CurRow, false);
5164: if (pNewPropEle != null) {
5165: pNewPropEle.setModified(true);
5166:
5167: // get the property element at the row that we are on, because we have right clicked
5168: // and said to insert before, we need the element that we are on to get the collection
5169: // element, so that we can rebuild the collection elements
5170: IPropertyElement pPropEle = (IPropertyElement) pBeforeNode
5171: .getUserObject();
5172: if (pPropEle != null) {
5173: // get the collection element
5174: IPropertyElement colEle = getCollectionElement(pPropEle);
5175: if (colEle != null) {
5176: //
5177: // reorder the elements in the collection element
5178: //
5179: Vector<IPropertyElement> temp = new Vector<IPropertyElement>();
5180: Vector<IPropertyElement> subEles = colEle
5181: .getSubElements();
5182: int count = subEles.size();
5183: for (int i = count - 1; i >= 0; i--) {
5184: IPropertyElement subEle = subEles
5185: .elementAt(i);
5186: // add it to our temp array
5187: temp.add(subEle);
5188: // remove it from the collection element
5189: subEles.removeElementAt(i);
5190: }
5191:
5192: // now loop through our temp array
5193: count = temp.size();
5194: for (int i = 0; i < count; i++) {
5195: // if the current sub element in our temp array is the same
5196: // as the new element we just created, then we need to insert
5197: // the new one before the current one
5198: // otherwise add the current one
5199: IPropertyElement subEle = temp.elementAt(i);
5200: if (subEle.equals(pPropEle)) {
5201: colEle.addSubElement(pNewPropEle);
5202: colEle.addSubElement(subEle);
5203: } else {
5204: colEle.addSubElement(subEle);
5205: }
5206: }
5207: }
5208: }
5209:
5210: //
5211: // Now we should have the sub elements in the right order
5212: //
5213: IPropertyDefinition pDef = pNewPropEle
5214: .getPropertyDefinition();
5215:
5216: // the following code is from AddSubElementToGrid
5217: // but that routine was doing more than we wanted, so it should
5218: // be refactored, but for proof of concept we duplicated it here
5219: // add the node to the grid
5220: String displayName = pDef.getDisplayName();
5221: m_PropEleMgr.interpretElementValue(pNewPropEle);
5222: String value = pNewPropEle.getValue();
5223:
5224: JDefaultMutableTreeNode newNode = new JDefaultMutableTreeNode();
5225: newNode.setKey("RecordNew"); //$NON-NLS-1$
5226: int row = newNode.getRow();
5227: pBeforeNode.add(newNode);
5228:
5229: //set the value
5230: m_Tree.setValueAt(displayName, row - 1, 2);
5231: m_Tree.setValueAt(value, row, 2);
5232:
5233: // set the behind the scenes data to the property element
5234: updatePropertyElementValue(row, pNewPropEle);
5235:
5236: // set the color of the grid cell
5237: boolean readOnlyStatus = isReadOnlyStatus(pDef,
5238: pNewPropEle);
5239:
5240: // set the boldness of the font of the grid cell
5241: boolean boldness = isBold(pDef, pNewPropEle);
5242:
5243: addSubElementToTable(newNode, pDef, pNewPropEle, false);
5244:
5245: // expand this last child
5246: JTreeTable.TreeTableCellRenderer tree = m_Tree
5247: .getTree();
5248: tree.expandNode(row, true);
5249: newNode.setExpanded(true);
5250:
5251: //set focus to the editable cell on the first node.
5252: }
5253: }
5254: }
5255:
5256: /**
5257: * Used to hide/show the property editor element's subElements.
5258: */
5259: public void sortPropertyEditorElements(int row) {
5260: //ETSystem.out.println("In sortPropertyElements for the row " + row);
5261: //We are builing root and not displaying it, so I need to user
5262: // the first child of the root.
5263: if (m_root == null) {
5264: return;
5265: }
5266:
5267: //We do not want to do anything if there are more than one items selected.
5268: int childCount = m_root.getChildCount();
5269: if (childCount != 1) {
5270: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
5271:
5272: //just make sure we have it expanded, if it was expanded
5273: if (node.isExpanded()) {
5274: m_Model.expand(row, true);
5275: }
5276: return;
5277: }
5278:
5279: JDefaultMutableTreeNode node = (JDefaultMutableTreeNode) m_root
5280: .getChildAt(0);
5281: Object obj = node.getUserObject();
5282: if (obj != null && obj instanceof IPropertyElement) {
5283: IPropertyElement ele = (IPropertyElement) obj;
5284: if (row == 0) {
5285: //we user has clicked onto the icon to toggle show all vs show selected
5286: //so check which mode we are in right now and then toggle to the other one
5287: if (m_IsShowingSelected) {
5288: m_IsShowingSelected = false;
5289:
5290: //show all elements
5291: refreshRootNodeAfterFilter(ele);
5292: } else {
5293: //do nothing as we are already showing all the elements.
5294: //just make sure we have it expanded, if it was expanded
5295: m_Model.expand(row, true);
5296: }
5297: } else {
5298: if (m_IsShowingSelected) {
5299: //do nothing
5300: } else {
5301:
5302: //show the selected element now. First need to find which
5303: Vector<Icon> icons = m_Model.getIcons();
5304: if (icons != null && icons.size() > 0) {
5305: int count = icons.size();
5306: if (count > row) {
5307: m_IsShowingSelected = true;
5308: IPropertyElement selEle = m_LoadedImages
5309: .elementAt(row);
5310: if (selEle != null) {
5311: //ETSystem.out.println("Going to sort for the element " + selEle.getName());
5312: refreshRootNodeAfterFilter(selEle);
5313: }
5314: }
5315: }
5316: }
5317: }
5318: }
5319: }
5320:
5321: public boolean isShowingFilteredOnIcons() {
5322: return m_IsShowingSelected;
5323: }
5324:
5325: public boolean isShowingComboFilteredList() {
5326: return m_Mode == EDITOR_SEL ? true : false;
5327: }
5328:
5329: /**
5330: * This method should save the value when it gets changed.
5331: * @param arg0
5332: */
5333: public void columnValueChanged(PropertyChangeEvent e) {
5334: try {
5335: Object obj = e.getSource();
5336: String str = e.getPropertyName();
5337: if (str.equals("ancestor")) //$NON-NLS-1$
5338: {
5339: if (!focusChange) {
5340: JDefaultMutableTreeNode node = getNodeAtGridRow(m_CurRow);
5341: IPropertyElement ele = getElementAtGridRow(m_CurRow);
5342:
5343: JDefaultMutableTreeNode recNode = getGridNodeMarkedAsRecord(node);
5344:
5345: String text = null;
5346: if (obj instanceof JTextField) {
5347: JTextField field = (JTextField) obj;
5348: text = field.getText();
5349: } else if (obj instanceof JComboBox) {
5350: JComboBox field = (JComboBox) obj;
5351: text = (String) field.getSelectedItem();
5352: }
5353: ETSystem.out.println("New value = " + text); //$NON-NLS-1$
5354: if (ele != null) {
5355: String value = ele.getValue();
5356: if (value == null
5357: && (text == null || text.length() == 0)) {
5358: //do nothing
5359: } else if ((value == null && text != null && text
5360: .length() > 0)
5361: || !value.equals(text)) {
5362: ele.setModified(true);
5363: if (obj instanceof JComboBox) {
5364: ConfigStringTranslator trans = new ConfigStringTranslator();
5365: IPropertyDefinition pDef = ele
5366: .getPropertyDefinition();
5367: text = trans.translateIntoPSK(pDef,
5368: text);
5369: }
5370: ele.setValue(text);
5371:
5372: if (recNode != null) {
5373: //just set this node as modified
5374: Object userObj = recNode
5375: .getUserObject();
5376: if (userObj != null
5377: && userObj instanceof IPropertyElement) {
5378: ((IPropertyElement) userObj)
5379: .setModified(true);
5380: }
5381: m_processingRecord = true;
5382: } else {
5383: if (m_processingRecord) {
5384: //need to save the old record
5385: insert(recNode);
5386: m_processingRecord = false;
5387: } else {
5388: saveCellValueAt(m_CurRow, text);
5389: }
5390: }
5391: }
5392: }
5393: } else {
5394: focusChange = false;
5395: }
5396: } else if (str.equals("nextFocus")) //$NON-NLS-1$
5397: {
5398: focusChange = true;
5399:
5400: //if we were working on a new record till now, need to save it.
5401: if (m_processingRecord) {
5402: JDefaultMutableTreeNode lastNode = getNodeAtGridRow(m_LastRow);
5403: JDefaultMutableTreeNode curNode = getNodeAtGridRow(m_CurRow);
5404:
5405: JDefaultMutableTreeNode recLastNode = getGridNodeMarkedAsRecord(lastNode);
5406: JDefaultMutableTreeNode recCurNode = getGridNodeMarkedAsRecord(curNode);
5407: if (recCurNode != null
5408: && recLastNode.equals(recCurNode)) {
5409: //we are still working on this node.
5410: } else {
5411: insert(recLastNode);
5412: m_processingRecord = false;
5413: }
5414: }
5415: }
5416:
5417: } catch (Exception ep) {
5418: ep.printStackTrace();
5419: }
5420: }
5421:
5422: public void handleSave(boolean stopCellEditing, Object obj) {
5423: try {
5424: if (obj == null) {
5425: if (m_Model != null) {
5426: obj = m_Model.getEditingComponent();
5427: }
5428: if (obj == null)
5429: return;
5430: }
5431: //I need to figure out if I have lost focus to a
5432: //different component, in which case I need to use the
5433: //m_CurRow and not m_LastRow, I can do this using the
5434: //other component on focus event
5435: int rowToUse = m_CurRow;
5436: if (!stopCellEditing) {
5437: //we lost focus to some other component.
5438: rowToUse = m_LastRow;
5439: }
5440:
5441: JDefaultMutableTreeNode node = getNodeAtGridRow(rowToUse);
5442: IPropertyElement ele = getElementAtGridRow(rowToUse);
5443:
5444: JDefaultMutableTreeNode recNode = getGridNodeMarkedAsRecord(node);
5445:
5446: String text = null;
5447: if (obj instanceof JTextField) {
5448: JTextField field = (JTextField) obj;
5449: text = field.getText();
5450: } else if (obj instanceof JComboBox) {
5451: JComboBox field = (JComboBox) obj;
5452: boolean editable = field.isEditable();
5453: if (editable) {
5454: text = (String) field.getEditor().getItem();
5455: } else {
5456: text = (String) field.getSelectedItem();
5457: }
5458: }
5459:
5460: if (ele != null) {
5461: String value = ele.getValue();
5462: //Samaresh: fix for #5078895.
5463: //Somehow I feel that the if condition 8 lines below
5464: //if (value == null && (text == null || text.length() == 0) )
5465: //should instead be
5466: //if (value != null && (text == null || text.length() == 0) )
5467: if ((value != null)
5468: && (text == null || text.length() == 0)) {
5469: return;
5470: }
5471:
5472: if (value == null
5473: && (text == null || text.length() == 0)) {
5474: //do nothing
5475: // we have a bug 2023 where if you enter an operation name and arrow down to alias
5476: // and then switch elements in the project tree, the operation was not getting saved
5477: // because we were going into this if statement
5478: // so now we are going to check if we are in a record node (just like down below)
5479: // this is pretty touchy code, so we just copied it rather than add to the if stmt
5480: // so as not to break other stuff
5481: if (recNode != null) {
5482: //the property element at last row was not modified
5483: //but if we were in a record new mode, we should process last node.
5484: node = getNodeAtGridRow(m_CurRow);
5485: while (recNode != null) {
5486: //if the element selection has changed or some other element is being loaded.
5487: if (insertNecessary(node, recNode)
5488: || stopCellEditing == false) {
5489: insert(recNode);
5490: }
5491: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) recNode
5492: .getParent();
5493: recNode = getGridNodeMarkedAsRecord(parentNode);
5494: }
5495: }
5496:
5497: } else if ((value == null && text != null && text
5498: .length() > 0)
5499: || (value != null && text != null && !value
5500: .equals(text))) {
5501: ele.setModified(true);
5502: if (obj instanceof JComboBox) {
5503: if (!((JComboBox) obj).isEditable()) {
5504: ConfigStringTranslator trans = new ConfigStringTranslator();
5505: IPropertyDefinition pDef = ele
5506: .getPropertyDefinition();
5507: text = trans.translateIntoPSK(pDef, text);
5508: }
5509: }
5510: ele.setValue(text);
5511:
5512: if (recNode != null) {
5513: //just set this node as modified
5514: Object userObj = recNode.getUserObject();
5515: if (userObj != null
5516: && userObj instanceof IPropertyElement) {
5517: ((IPropertyElement) userObj)
5518: .setModified(true);
5519: }
5520: m_processingRecord = true;
5521: m_RecordNode = recNode;
5522: }
5523:
5524: //we want to save the cell value at this last row - it will create
5525: //an element if the record element is not yet created.
5526: //saveCellValueAt(m_LastRow, text);
5527: if (stopCellEditing) {
5528: processLastCell(false, rowToUse);
5529: } else {
5530: //the focus has been lost to some other component so need to insert.
5531: processLastCell(true, rowToUse);
5532: }
5533: } else if (recNode != null) {
5534: //the property element at last row was not modified
5535: //but if we were in a record new mode, we should process last node.
5536: node = getNodeAtGridRow(m_CurRow);
5537: while (recNode != null) {
5538: //if the element selection has changed or some other element is being loaded.
5539: if (insertNecessary(node, recNode)
5540: || stopCellEditing == false) {
5541: insert(recNode);
5542: }
5543: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) recNode
5544: .getParent();
5545: recNode = getGridNodeMarkedAsRecord(parentNode);
5546: }
5547: }
5548: }
5549:
5550: } catch (Exception ep) {
5551: ep.printStackTrace();
5552: }
5553: }
5554:
5555: public void handleFocusLostOnCellEvent(FocusEvent e) {
5556: try {
5557: Object obj = e.getSource();
5558:
5559: //I need to figure out if I have lost focus to a
5560: //different component, in which case I need to use the
5561: //m_CurRow and not m_LastRow, I can do this using the
5562: //other component on focus event
5563: Component oComp = e.getOppositeComponent();
5564: int rowToUse = m_LastRow;
5565: if (oComp instanceof JPropertyTreeTable) {
5566: //we are still in the property editor, so no probs.
5567: } else {
5568: rowToUse = m_CurRow;
5569: }
5570:
5571: JDefaultMutableTreeNode node = getNodeAtGridRow(rowToUse);
5572: IPropertyElement ele = getElementAtGridRow(rowToUse);
5573:
5574: JDefaultMutableTreeNode recNode = getGridNodeMarkedAsRecord(node);
5575:
5576: String text = null;
5577: if (obj instanceof JTextField) {
5578: JTextField field = (JTextField) obj;
5579: text = field.getText();
5580: } else if (obj instanceof JComboBox) {
5581: JComboBox field = (JComboBox) obj;
5582: text = (String) field.getSelectedItem();
5583: }
5584: if (ele != null) {
5585: String value = ele.getValue();
5586: if (value == null
5587: && (text == null || text.length() == 0)) {
5588: //do nothing
5589: } else if ((value == null && text != null && text
5590: .length() > 0)
5591: || (value != null && text != null && !value
5592: .equals(text))) {
5593: ele.setModified(true);
5594: if (obj instanceof JDescribeComboBox) {
5595: //I do not want to translate this value
5596: } else if (obj instanceof JComboBox) {
5597: ConfigStringTranslator trans = new ConfigStringTranslator();
5598: IPropertyDefinition pDef = ele
5599: .getPropertyDefinition();
5600: text = trans.translateIntoPSK(pDef, text);
5601: }
5602: ele.setValue(text);
5603:
5604: if (recNode != null) {
5605: //just set this node as modified
5606: Object userObj = recNode.getUserObject();
5607: if (userObj != null
5608: && userObj instanceof IPropertyElement) {
5609: ((IPropertyElement) userObj)
5610: .setModified(true);
5611: }
5612: m_processingRecord = true;
5613: m_RecordNode = recNode;
5614: }
5615:
5616: //we want to save the cell value at this last row - it will create
5617: //an element if the record element is not yet created.
5618: //saveCellValueAt(m_LastRow, text);
5619: if (oComp instanceof JPropertyTreeTable) {
5620: processLastCell(false, rowToUse);
5621: } else {
5622: //the focus has been lost to some other component so need to insert.
5623: processLastCell(true, rowToUse);
5624: }
5625: } else if (recNode != null) {
5626: //the property element at last row was not modified
5627: //but if we were in a record new mode, we should process last node.
5628: node = getNodeAtGridRow(m_CurRow);
5629: while (recNode != null) {
5630: //if the element selection has changed or
5631: if (insertNecessary(node, recNode)) {
5632: insert(recNode);
5633: }
5634: JDefaultMutableTreeNode parentNode = (JDefaultMutableTreeNode) recNode
5635: .getParent();
5636: recNode = getGridNodeMarkedAsRecord(parentNode);
5637: }
5638:
5639: }
5640: }
5641:
5642: } catch (Exception ep) {
5643: ep.printStackTrace();
5644: }
5645: }
5646:
5647: public void handleFocusGainedOnCellEvent(FocusEvent e) {
5648: try {
5649: ETSystem.out
5650: .println("Focus Gained m_CurRow = " + m_CurRow + " m_LastRow = " + m_LastRow); //$NON-NLS-1$ //$NON-NLS-2$
5651: // Object obj = e.getSource();
5652: // JDefaultMutableTreeNode node = getNodeAtGridRow(m_CurRow);
5653: // IPropertyElement ele = getElementAtGridRow(m_CurRow);
5654: //
5655: // JDefaultMutableTreeNode recNode = getGridNodeMarkedAsRecord(node);
5656: //
5657: // if (ele != null)
5658: // {
5659: // if (recNode == null && m_processingRecord)
5660: // {
5661: // node = getNodeAtGridRow(m_LastRow);
5662: // recNode = getGridNodeMarkedAsRecord(node);
5663: // if (recNode != null)
5664: // {
5665: // IPropertyElement pEle = (IPropertyElement)recNode.getUserObject();
5666: // ETSystem.out.println("I need to save the record for " + pEle.getName());
5667: // //saveCellValueAt(m_LastRow, text);
5668: // processLastCell(false);
5669: // }
5670: // m_processingRecord = false;
5671: // }
5672: // }
5673: } catch (Exception ep) {
5674: ep.printStackTrace();
5675: }
5676: }
5677:
5678: /*
5679: * This method is called when a tree node in the property editor is
5680: * double clicked. It will expand the node or collapse it.
5681: * If the node's property element is not built yet and the multiplicity
5682: * is > 1, this method builds the property element and expands it.
5683: */
5684: public void handleDoubleClick() {
5685: if (m_Tree != null) {
5686: int row = m_Tree.getSelectedRow();
5687: handleDoubleClick(row, null);
5688: }
5689: }
5690:
5691: public void handleDoubleClick(int row, TreePath selPath) {
5692: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
5693: if (node == null)
5694: return;
5695:
5696: if (node.isExpanded())//|| m_Tree.getTree().isExpanded(selPath))
5697: {
5698: node.setExpanded(false);
5699: m_Model.expand(row, false);
5700: } else {
5701: int count = node.getChildCount();
5702:
5703: //if the child count is 0, we need to check if the element is
5704: // not built yet - like for attributes, operations etc.
5705: // if (count == 0)
5706: {
5707: onNodeExpanding(row);
5708: // IPropertyElement pEle = getElementAtGridRow(row);
5709: // if (pEle != null)
5710: // {
5711: // IPropertyDefinition pDef = pEle.getPropertyDefinition();
5712: // if (pDef != null)
5713: // {
5714: // long mult = pDef.getMultiplicity();
5715: // if (mult > 1)
5716: // {
5717: // IPropertyDefinition def = pDef.getSubDefinition(0);
5718: // //This element might not have built yet, so build it
5719: // String getMeth = pDef.getGetMethod();
5720: // Object pDisp = pEle.getElement();
5721: // //onNodeExpanding(row);
5722: // if (getMeth != null && getMeth.length() > 0)
5723: // {
5724: // Class clazz = pDisp.getClass();
5725: // if (Dispatch.isType(pDisp, IElement.GUID))
5726: // {
5727: // try
5728: // {
5729: // Class[] params = {com.embarcadero.com.Dispatch.class};
5730: // Constructor constructor = clazz.getConstructor(params);
5731: // Object[] paramInstances = {pDisp};
5732: // Object curE = (IElement)constructor.newInstance(paramInstances);
5733: // //curE = (IElement) new IElementProxy((Dispatch)pDisp);
5734: // clazz = curE.getClass();//Class.forName("com.embarcadero.describe.foundation.IElement");//curE.getClass();
5735: //
5736: // java.lang.reflect.Method method = clazz.getMethod(getMeth, null);
5737: // Object obj = method.invoke(curE, null);
5738: // if (obj != null)
5739: // {
5740: // //if this returned object has a getCount method, then this is a
5741: // //collection object and I want to build property element for each of
5742: // //these collection objects.
5743: //
5744: // //The obj I have got here is a Proxy, need to
5745: // //create a Dispatch object out of it.
5746: // Class[] dispParams = {com.embarcadero.com.Dispatch.class};
5747: // constructor = obj.getClass().getConstructor(dispParams);
5748: //
5749: // Object[] paramCollectionInstances = {obj};
5750: // obj = constructor.newInstance(paramCollectionInstances);
5751: //
5752: // Method countMethod = obj.getClass().getMethod("getCount", null);
5753: // if (countMethod != null)
5754: // {
5755: // Object countResult = countMethod.invoke(obj, null);
5756: // if (countResult != null && countResult instanceof Integer)
5757: // {
5758: // int counter = ((Integer)countResult).intValue();
5759: // if(counter > 0)
5760: // {
5761: // //Now I want to get the item method so that I can invoke
5762: // //it on the collections object.
5763: // Class[] parms = new Class[1];
5764: // parms[0] = int.class;
5765: // Method itemMethod = obj.getClass().getMethod("item", parms);
5766: // if (itemMethod != null)
5767: // {
5768: // for (int i=0; i<counter; i++)
5769: // {
5770: // Object[] itemCount = new Object[1];
5771: // itemCount[0] = new Integer(i);
5772: // Object itemResult = itemMethod.invoke(obj, itemCount);
5773: //
5774: // if (itemResult != null)
5775: // {
5776: // m_PropEleMgr.setCreateSubs(true);
5777: // IPropertyElement newPropEle = m_PropEleMgr.buildTopPropertyElement(def);
5778: // if (newPropEle != null)
5779: // {
5780: // //at this point the property definition may not be built yet, so build it.
5781: // IPropertyDefinition newDef = getPropertyDefinition(newPropEle);
5782: // if (newDef != null)
5783: // {
5784: // // now temporarily store the fake new model element on this new property
5785: // // element so that the filter will work
5786: // newPropEle.setElement(itemResult);
5787: // newPropEle = m_PropEleMgr.buildElement(itemResult, newDef, null);
5788: //
5789: // // now add this new one to the collection
5790: // pEle.addSubElement(newPropEle);
5791: //
5792: // // now that we have built the property element structure
5793: // // check the definition filter to see if any of the elements need to
5794: // // change
5795: // filterPropertyElement(newPropEle);
5796: // }
5797: // }
5798: //
5799: // if (newPropEle != null)
5800: // {
5801: // //JDefaultMutableTreeNode newNode = new JDefaultMutableTreeNode(newPropEle);
5802: // JDefaultMutableTreeNode newNode = null;
5803: //
5804: // // now expand and set up the node that will be added
5805: // newNode = addSubElementToTable(node, def, newPropEle, false);
5806: //
5807: // //Now go through the sub elements of pEle and add those to the tree
5808: // //buildSubElementsThatNeedToDisplay(newPropEle, newNode);
5809: // }
5810: // }
5811: // }
5812: // }
5813: // }
5814: // }
5815: // }
5816: // }
5817: // }
5818: // catch (Exception e)
5819: // {
5820: // // TODO Auto-generated catch block
5821: // e.printStackTrace();
5822: // }
5823: // }
5824: // }
5825: // }
5826: // }
5827: // }
5828: }
5829: m_Model.expand(row, true);
5830: node.setExpanded(true);
5831:
5832: //m_Tree.getTree().expandPath(selPath);
5833:
5834: //refresh();
5835: }
5836: }
5837:
5838: /*
5839: * Nodes with onDemand true or with multiplicity > 1 may not be built
5840: * at first load of an element. This method builds those.
5841: */
5842: private void buildAndExpandNode(int row) {
5843: IPropertyElement pEle = getElementAtGridRow(row);
5844: JDefaultMutableTreeNode node = getNodeAtGridRow(row);
5845: if (pEle != null) {
5846: IPropertyDefinition pDef = pEle.getPropertyDefinition();
5847: if (pDef != null) {
5848: long mult = pDef.getMultiplicity();
5849: boolean isOnDemand = pDef.isOnDemand();
5850: if (mult > 1) {
5851: buildForMutiplicityNode(pEle, node);
5852: } else {
5853: buildOnDemandNode(pEle, node);
5854: }
5855: }
5856: }
5857: }
5858:
5859: private void buildForMutiplicityNode(IPropertyElement pEle,
5860: JDefaultMutableTreeNode node) {
5861: if (pEle != null) {
5862: IPropertyDefinition pDef = pEle.getPropertyDefinition();
5863: if (pDef == null)
5864: return;
5865:
5866: IPropertyDefinition def = pDef.getSubDefinition(0);
5867: //This element might not have built yet, so build it
5868: String getMeth = pDef.getGetMethod();
5869: Object pDisp = pEle.getElement();
5870: //onNodeExpanding(row);
5871: if (getMeth != null && getMeth.length() > 0
5872: && pDisp != null) {
5873: Class clazz = pDisp.getClass();
5874: if (pDisp instanceof IElement) {
5875: try {
5876: java.lang.reflect.Method method = clazz
5877: .getMethod(getMeth, null);
5878: Object obj = method.invoke(pDisp, null);
5879: if (obj != null) {
5880: //if this returned object has a getCount method, then this is a
5881: //collection object and I want to build property element for each of
5882: //these collection objects.
5883:
5884: Method countMethod = obj.getClass()
5885: .getMethod("getCount", null); //$NON-NLS-1$
5886: if (countMethod != null) {
5887: Object countResult = countMethod
5888: .invoke(obj, null);
5889: if (countResult != null
5890: && countResult instanceof Integer) {
5891: int counter = ((Integer) countResult)
5892: .intValue();
5893: if (counter > 0) {
5894: //Now I want to get the item method so that I can invoke
5895: //it on the collections object.
5896: Class[] parms = new Class[1];
5897: parms[0] = int.class;
5898: Method itemMethod = obj
5899: .getClass().getMethod(
5900: "item", parms); //$NON-NLS-1$
5901: if (itemMethod != null) {
5902: boolean onDemand = def
5903: .isOnDemand();
5904: for (int i = 0; i < counter; i++) {
5905: Object[] itemCount = new Object[1];
5906: itemCount[0] = new Integer(
5907: i);
5908: Object itemResult = itemMethod
5909: .invoke(obj,
5910: itemCount);
5911:
5912: if (itemResult != null) {
5913: m_PropEleMgr
5914: .setCreateSubs(true);
5915: IPropertyElement newPropEle = m_PropEleMgr
5916: .buildTopPropertyElement(def);
5917: if (newPropEle != null) {
5918: newPropEle
5919: .setElement(itemResult);
5920: //newPropEle.setPropertyDefinition(newDef);
5921:
5922: //I want to build this property element only if its not on demand
5923: if (onDemand) {
5924: //here I just want to set its name as dummy.
5925: newPropEle
5926: .setName("dummy"); //$NON-NLS-1$
5927: } else {
5928: //newPropEle = m_PropEleMgr.buildElement(itemResult, newDef, null);
5929: }
5930:
5931: // now add this new one to the collection
5932: pEle
5933: .addSubElement(newPropEle);
5934:
5935: // now that we have built the property element structure
5936: // check the definition filter to see if any of the elements need to
5937: // change
5938: filterPropertyElement(newPropEle);
5939: }
5940:
5941: if (newPropEle != null) {
5942: //JDefaultMutableTreeNode newNode = new JDefaultMutableTreeNode(newPropEle);
5943: JDefaultMutableTreeNode newNode = null;
5944:
5945: // now expand and set up the node that will be added
5946: newNode = addSubElementToTable(
5947: node,
5948: def,
5949: newPropEle,
5950: false);
5951:
5952: //Now go through the sub elements of pEle and add those to the tree
5953: //buildSubElementsThatNeedToDisplay(newPropEle, newNode);
5954: }
5955: }
5956: }
5957: }
5958: }
5959: }
5960: }
5961: }
5962: } catch (Exception e) {
5963: // TODO Auto-generated catch block
5964: e.printStackTrace();
5965: }
5966: }
5967: }
5968: }
5969: }
5970:
5971: private void buildOnDemandNode(IPropertyElement pEle,
5972: JDefaultMutableTreeNode node) {
5973: Object pDisp = pEle.getElement();
5974: IPropertyDefinition pDef = pEle.getPropertyDefinition();
5975: if (pDef != null) {
5976: //set the name of the property element to proper name
5977: pEle.setName(pDef.getName());
5978: pEle = m_PropEleMgr.buildElement(pDisp, pDef, null);
5979: if (pEle != null) {
5980: // now that we have built the property element structure
5981: // check the definition filter to see if any of the elements need to
5982: // change
5983: filterPropertyElement(pEle);
5984: node.setUserObject(pEle);
5985: JDefaultMutableTreeNode newNode = null;
5986: // now expand and set up the node that will be added
5987: newNode = addSubElementToTable(node, pDef, pEle, false);
5988: }
5989: }
5990: }
5991:
5992: public void setRightClickRow(int newRow) {
5993: m_RightClickRow = newRow;
5994: }
5995:
5996: /**
5997: * In order to protect this object from a reentrancy issue, we make
5998: * sure that m_SigChange is set to NULL before it is destroyed
5999: *
6000: */
6001: private void endSignatureChange() {
6002: if (m_SigChange != null) {
6003: m_SigChange.endSignatureChange();
6004: m_SigChange = null;
6005: }
6006: }
6007:
6008: private IOperation getOperationFromPropertyElement(
6009: IPropertyElement pEle) {
6010: IOperation retOper = null;
6011: if (pEle != null) {
6012: // Get the PropertyElement's IElement
6013: Object pDisp = pEle.getElement();
6014: if (pDisp == null) {
6015: pDisp = getModelElement(pEle);
6016: }
6017:
6018: if (pDisp instanceof IOperation) {
6019: retOper = (IOperation) pDisp;
6020: } else if (pDisp instanceof IParameter) {
6021: IBehavioralFeature pFeature = ((IParameter) pDisp)
6022: .getBehavioralFeature();
6023: if (pFeature != null && pFeature instanceof IOperation) {
6024: retOper = (IOperation) pFeature;
6025: }
6026: } else {
6027: IPropertyElement parentEle = pEle.getParent();
6028: if (parentEle != null) {
6029: retOper = getOperationFromPropertyElement(parentEle);
6030: }
6031: }
6032: }
6033: return retOper;
6034: }
6035:
6036: public void setEditingComponent(Object obj) {
6037: if (m_Model != null) {
6038: m_Model.setEditingComponent(obj);
6039: }
6040: if (obj == null && m_Tree != null) {
6041: m_Tree.editingCanceled(null);
6042: }
6043: }
6044:
6045: public Object getEditingComponent() {
6046: Object retVal = null;
6047: if (m_Model != null) {
6048: retVal = m_Model.getEditingComponent();
6049: }
6050: return retVal;
6051: }
6052:
6053: public void onFocus() {
6054: if (m_Tree != null) {
6055: m_Tree.requestFocus();
6056: }
6057: }
6058: }
|