0001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012: // POSSIBILITY OF SUCH DAMAGE.
0013: //
0014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015: package com.metaboss.applications.designstudio.dependencyview;
0016:
0017: import java.awt.BorderLayout;
0018: import java.awt.Color;
0019: import java.awt.Paint;
0020: import java.awt.event.ActionEvent;
0021: import java.awt.event.ComponentAdapter;
0022: import java.awt.event.ComponentEvent;
0023: import java.awt.event.MouseEvent;
0024: import java.net.URL;
0025: import java.util.ArrayList;
0026: import java.util.Collection;
0027: import java.util.Collections;
0028: import java.util.Comparator;
0029: import java.util.HashMap;
0030: import java.util.HashSet;
0031: import java.util.Iterator;
0032: import java.util.List;
0033: import java.util.Set;
0034:
0035: import javax.jmi.model.AggregationKind;
0036: import javax.jmi.model.AggregationKindEnum;
0037: import javax.jmi.model.AssociationEnd;
0038: import javax.jmi.model.Feature;
0039: import javax.jmi.model.MofClass;
0040: import javax.jmi.model.Reference;
0041: import javax.jmi.reflect.RefClass;
0042: import javax.swing.AbstractAction;
0043: import javax.swing.Action;
0044: import javax.swing.ImageIcon;
0045: import javax.swing.JCheckBoxMenuItem;
0046: import javax.swing.JMenu;
0047: import javax.swing.JPopupMenu;
0048:
0049: import com.metaboss.applications.designstudio.Application;
0050: import com.metaboss.applications.designstudio.BaseAction;
0051: import com.metaboss.applications.designstudio.BaseChildPanel;
0052: import com.metaboss.applications.designstudio.components.SeparatorAction;
0053: import com.metaboss.applications.designstudio.icons.IconsHolder;
0054: import com.metaboss.applications.designstudio.userobjects.UserObjectFactory;
0055: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
0056: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
0057: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
0058: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
0059: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
0060: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.UsageSpecification;
0061: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibrary;
0062: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.VisualModelPackage;
0063:
0064: import edu.berkeley.guir.prefuse.AggregateItem;
0065: import edu.berkeley.guir.prefuse.Display;
0066: import edu.berkeley.guir.prefuse.EdgeItem;
0067: import edu.berkeley.guir.prefuse.FocusManager;
0068: import edu.berkeley.guir.prefuse.ItemRegistry;
0069: import edu.berkeley.guir.prefuse.NodeItem;
0070: import edu.berkeley.guir.prefuse.VisualItem;
0071: import edu.berkeley.guir.prefuse.action.RepaintAction;
0072: import edu.berkeley.guir.prefuse.action.animate.ColorAnimator;
0073: import edu.berkeley.guir.prefuse.action.animate.PolarLocationAnimator;
0074: import edu.berkeley.guir.prefuse.action.assignment.ColorFunction;
0075: import edu.berkeley.guir.prefuse.action.filter.TreeFilter;
0076: import edu.berkeley.guir.prefuse.activity.ActionList;
0077: import edu.berkeley.guir.prefuse.activity.SlowInSlowOutPacer;
0078: import edu.berkeley.guir.prefuse.event.ControlAdapter;
0079: import edu.berkeley.guir.prefuse.event.FocusEvent;
0080: import edu.berkeley.guir.prefuse.event.FocusListener;
0081: import edu.berkeley.guir.prefuse.focus.DefaultFocusSet;
0082: import edu.berkeley.guir.prefuse.graph.DefaultGraph;
0083: import edu.berkeley.guir.prefuse.graph.DefaultTreeNode;
0084: import edu.berkeley.guir.prefuse.render.DefaultRendererFactory;
0085: import edu.berkeley.guir.prefuse.render.Renderer;
0086: import edu.berkeley.guir.prefuse.render.TextImageItemRenderer;
0087: import edu.berkeley.guir.prefuse.util.ColorMap;
0088: import edu.berkeley.guir.prefuse.util.StringAbbreviator;
0089: import edu.berkeley.guir.prefusex.controls.DragControl;
0090: import edu.berkeley.guir.prefusex.controls.FocusControl;
0091: import edu.berkeley.guir.prefusex.controls.NeighborHighlightControl;
0092: import edu.berkeley.guir.prefusex.controls.PanControl;
0093: import edu.berkeley.guir.prefusex.controls.ZoomControl;
0094: import edu.berkeley.guir.prefusex.layout.RadialTreeLayout;
0095:
0096: /* Domain diagram panel class */
0097:
0098: public class DependencyViewPanel extends BaseChildPanel {
0099: private static Comparator sRefClassComparator = new Comparator() {
0100: public int compare(Object o1, Object o2) {
0101: // Compare names of types
0102: int lComparisonResult = 0;
0103: if (o1.equals(o2))
0104: return 0;
0105: RefClass lElement1 = (RefClass) o1;
0106: RefClass lElement2 = (RefClass) o2;
0107: String lElement1TypeName = (String) lElement1
0108: .refMetaObject().refGetValue("name");
0109: String lElement2TypeName = (String) lElement2
0110: .refMetaObject().refGetValue("name");
0111: return lElement1TypeName.compareTo(lElement2TypeName);
0112: }
0113: };
0114:
0115: private static Comparator sModelElementComparator = new Comparator() {
0116: public int compare(Object o1, Object o2) {
0117: // Order of comparison is equals(), name comparison, type comparison, ref comparison
0118: int lComparisonResult = 0;
0119: if (o1.equals(o2) == false) {
0120: ModelElement lElement1 = (ModelElement) o1;
0121: ModelElement lElement2 = (ModelElement) o2;
0122: String lElement1Name = lElement1.getName();
0123: String lElement2Name = lElement2.getName();
0124: if ((lComparisonResult = lElement1Name
0125: .compareTo(lElement2Name)) == 0) {
0126: String lElement1Type = (String) lElement1
0127: .refMetaObject().refGetValue("name");
0128: String lElement2Type = (String) lElement2
0129: .refMetaObject().refGetValue("name");
0130: if ((lComparisonResult = lElement1Type
0131: .compareTo(lElement2Type)) == 0)
0132: lComparisonResult = lElement1.getRef()
0133: .compareTo(lElement2.getRef());
0134: }
0135: }
0136: return lComparisonResult;
0137: }
0138: };
0139:
0140: // Set of packages which are always ignored - the model elements from these packages
0141: // are not shown and their dependencies are not studied any further.
0142: private static Set sIgnoredPackages = new HashSet();
0143: static {
0144: sIgnoredPackages.add(VisualModelPackage.class);
0145: }
0146:
0147: private MetaBossModelPackage mMetaBossModelPackage = null;
0148: private BorderLayout mPanelLayout = null;
0149: private Display mDisplay = null;
0150: private ActionList mLayout = null;
0151: private SpecialFocusListener mFocusListener = new SpecialFocusListener();
0152: private SpecialControlAdapter mControlAdapter = new SpecialControlAdapter();
0153: private HashMap mNodesByIdMap = new HashMap();
0154: private HashMap mEdgesByIdMap = new HashMap();
0155: private DefaultGraph mGraph = new DefaultGraph(false);
0156: //private JPopupMenu mPopupMenu = null;
0157: private ModelElement mCurrentModelElement;
0158: private Set mAdditionalExplodedModelElements = new HashSet(); // Model elements which have been explicitly included into the diagram
0159: private Set mRemovedModelElements = new HashSet(); // Collection of model elements which are excluded from the diagram - not shown as if they do not exist including their dependencies
0160: private Set mRemovedModelElementTypes = new HashSet(); // Collection of model element types which are excluded from the diagram - not shown as if they do not exist including their dependencies
0161: private Set mHiddenModelElements = new HashSet(); // Collection of model elements which are invisible - hidden within the parent
0162: private Set mHiddenModelElementTypes = new HashSet(); // Collection of model element types which are invisible - hidden within the parent
0163: private List mExcludedDependenciesModelElements = new ArrayList(); // Model elements for which dependencies are not included in the diagram
0164: private int mCurrentDepthLevel;
0165: private ModelElement mLastSelectedForPopupModelElement = null;
0166: private boolean mShowDownstream = true;
0167: private boolean mShowUpstream = true;
0168: private EditPropertiesAction mEditPropertiesAction = new EditPropertiesAction();
0169: private RebaseAction mRebaseAction = new RebaseAction();
0170: private ShowDependenciesAction mShowDependenciesAction = new ShowDependenciesAction();
0171: private JCheckBoxMenuItem mShowDependenciesActionMenuItem = new JCheckBoxMenuItem(
0172: mShowDependenciesAction);
0173: private RemoveDependenciesAction mRemoveDependenciesAction = new RemoveDependenciesAction();
0174: private JCheckBoxMenuItem mRemoveDependenciesActionMenuItem = new JCheckBoxMenuItem(
0175: mRemoveDependenciesAction);
0176:
0177: // Remove elements and types actions
0178: private RemoveElementAction mRemoveElementAction = new RemoveElementAction();
0179: private RemoveElementTypeAction mRemoveElementTypeAction = new RemoveElementTypeAction();
0180: private HideElementAction mHideElementAction = new HideElementAction();
0181: private HideElementTypeAction mHideElementTypeAction = new HideElementTypeAction();
0182:
0183: // Show elements and types actions
0184: private ShowRemovedElementAction mShowRemovedElementAction = new ShowRemovedElementAction();
0185: private ShowRemovedElementTypeAction mShowRemovedElementTypeAction = new ShowRemovedElementTypeAction();
0186: private ShowHiddenElementAction mShowHiddenElementAction = new ShowHiddenElementAction();
0187: private ShowHiddenElementTypeAction mShowHiddenElementTypeAction = new ShowHiddenElementTypeAction();
0188: // Popup menus for the show actions
0189: private JMenu mShowRemovedElementActionMenuItem = new JMenu(
0190: mShowRemovedElementAction);
0191: private JMenu mShowRemovedElementTypeActionMenuItem = new JMenu(
0192: mShowRemovedElementTypeAction);
0193: private JMenu mShowHiddenElementActionMenuItem = new JMenu(
0194: mShowHiddenElementAction);
0195: private JMenu mShowHiddenElementTypeActionMenuItem = new JMenu(
0196: mShowHiddenElementTypeAction);
0197:
0198: private MoreDetailsAction mMoreDetailsAction = new MoreDetailsAction();
0199: private LessDetailsAction mLessDetailsAction = new LessDetailsAction();
0200: private BistreamDiagramAction mBistreamDiagramAction = new BistreamDiagramAction();
0201: private DownstreamDiagramAction mDownstreamDiagramAction = new DownstreamDiagramAction();
0202: private UpstreamDiagramAction mUpstreamDiagramAction = new UpstreamDiagramAction();
0203:
0204: public DependencyViewPanel(ModelElement pModelElement,
0205: int pDepthLevel) {
0206: super (pModelElement);
0207: mMetaBossModelPackage = (MetaBossModelPackage) pModelElement
0208: .refOutermostPackage();
0209: setLayout(mPanelLayout = new BorderLayout());
0210: // Build list of types (RefClasses which are initially invisible)
0211: mHiddenModelElementTypes.add(mMetaBossModelPackage
0212: .getModelElementTag());
0213: mHiddenModelElementTypes.add(mMetaBossModelPackage
0214: .getDataDictionaryModel().getStructureField());
0215: mHiddenModelElementTypes.add(mMetaBossModelPackage
0216: .getDataDictionaryModel().getProperty());
0217: mHiddenModelElementTypes.add(mMetaBossModelPackage
0218: .getDataDictionaryModel().getPropertyDescriptor());
0219: mHiddenModelElementTypes.add(mMetaBossModelPackage
0220: .getEnterpriseModel().getMessageField());
0221: mHiddenModelElementTypes.add(mMetaBossModelPackage
0222: .getEnterpriseModel().getOperationInputField());
0223: mHiddenModelElementTypes.add(mMetaBossModelPackage
0224: .getEnterpriseModel().getOperationOutputField());
0225: mHiddenModelElementTypes.add(mMetaBossModelPackage
0226: .getEnterpriseModel().getOperationOutputMessage());
0227: mHiddenModelElementTypes.add(mMetaBossModelPackage
0228: .getEnterpriseModel().getSystemImplementationModel()
0229: .getAttribute());
0230: mHiddenModelElementTypes.add(mMetaBossModelPackage
0231: .getEnterpriseModel().getSystemImplementationModel()
0232: .getSelectorInputField());
0233:
0234: /*mPopupMenu = new JPopupMenu();
0235: mPopupMenu.add(mEditPropertiesAction);
0236: mPopupMenu.add(mShowDependenciesActionMenuItem);
0237: mPopupMenu.add(mHideDependenciesActionMenuItem);
0238: mPopupMenu.add(mHideElementAction);
0239: mPopupMenu.add(mShowElementActionMenuItem);
0240: mPopupMenu.add(mRebaseAction);
0241: mPopupMenu.addSeparator();
0242: m.add(mBistreamDiagramAction);
0243: m.add(mDownstreamDiagramAction);
0244: m.add(mUpstreamDiagramAction);
0245: m.addSeparator();
0246: m.add(mMoreDetailsAction);
0247: m.add(mLessDetailsAction);*/
0248: mCurrentDepthLevel = pDepthLevel;
0249: mCurrentModelElement = pModelElement;
0250: reinitialiseDiagram();
0251: }
0252:
0253: private void updateActions() {
0254: mBistreamDiagramAction
0255: .setEnabled(!(mShowDownstream == true && mShowUpstream == true));
0256: mDownstreamDiagramAction
0257: .setEnabled(!(mShowDownstream == true && mShowUpstream == false));
0258: mUpstreamDiagramAction
0259: .setEnabled(!(mShowDownstream == false && mShowUpstream == true));
0260: mMoreDetailsAction.setEnabled(true);
0261: mLessDetailsAction.setEnabled(mCurrentDepthLevel > 1);
0262: // Per element actions
0263: mRebaseAction
0264: .setEnabled(mLastSelectedForPopupModelElement != null
0265: && mLastSelectedForPopupModelElement
0266: .equals(mCurrentModelElement) == false);
0267: // Any element can be explored/collapsed except the one in the epicentre
0268: mShowDependenciesAction
0269: .setEnabled(mLastSelectedForPopupModelElement != null
0270: && mLastSelectedForPopupModelElement
0271: .equals(mCurrentModelElement) == false);
0272:
0273: // Work on Show dependencies menu item
0274: // Set state to selected when an element an epicenter element or is already explored
0275: mShowDependenciesActionMenuItem
0276: .setState(mLastSelectedForPopupModelElement != null
0277: && (mLastSelectedForPopupModelElement
0278: .equals(mCurrentModelElement) == true || mAdditionalExplodedModelElements
0279: .contains(mLastSelectedForPopupModelElement) == true));
0280: // Enabled when there is a selected element and it is not the one in the epicenter - the epicenter one is always on
0281: mShowDependenciesActionMenuItem
0282: .setEnabled(mLastSelectedForPopupModelElement != null
0283: && mLastSelectedForPopupModelElement
0284: .equals(mCurrentModelElement) == false);
0285:
0286: // Work on Exclude dependencies menu item
0287: // Set state to selected when an element is already in the list of the ones with hidden dependencies
0288: mRemoveDependenciesActionMenuItem
0289: .setState(mLastSelectedForPopupModelElement != null
0290: && mExcludedDependenciesModelElements
0291: .contains(mLastSelectedForPopupModelElement) == true);
0292: // Enabled when there is a selected element and it is not the one in the epicenter
0293: mRemoveDependenciesActionMenuItem
0294: .setEnabled(mLastSelectedForPopupModelElement != null
0295: && mLastSelectedForPopupModelElement
0296: .equals(mCurrentModelElement) == false);
0297:
0298: // Work on Remove element menu item
0299: // Enabled when there is a selected element and it is not the one in the epicenter
0300: mRemoveElementAction
0301: .setEnabled(mLastSelectedForPopupModelElement != null
0302: && mLastSelectedForPopupModelElement
0303: .equals(mCurrentModelElement) == false);
0304:
0305: // Work on Remove element type menu item
0306: // Enabled when there is a selected element and it is not the one in the epicenter
0307: mRemoveElementTypeAction
0308: .setEnabled(mLastSelectedForPopupModelElement != null
0309: && mLastSelectedForPopupModelElement
0310: .equals(mCurrentModelElement) == false);
0311:
0312: // Work on Hide element menu item
0313: // Enabled when there is a selected element and it is not the one in the epicenter
0314: mHideElementAction
0315: .setEnabled(mLastSelectedForPopupModelElement != null
0316: && mLastSelectedForPopupModelElement
0317: .equals(mCurrentModelElement) == false);
0318:
0319: // Work on Hide element type menu item
0320: // Enabled when there is a selected element and it is not the one in the epicenter
0321: mHideElementTypeAction
0322: .setEnabled(mLastSelectedForPopupModelElement != null
0323: && mLastSelectedForPopupModelElement
0324: .equals(mCurrentModelElement) == false);
0325:
0326: // Work on the show removed elements menu
0327: if (!mRemovedModelElements.isEmpty()) {
0328: mShowRemovedElementAction.setEnabled(true);
0329: mShowRemovedElementActionMenuItem.removeAll();
0330: mShowRemovedElementActionMenuItem
0331: .add(new ShowRemovedElementAction(null));
0332: List lExcludedModelElements = new ArrayList(
0333: mRemovedModelElements);
0334: Collections.sort(lExcludedModelElements,
0335: sModelElementComparator);
0336: for (Iterator lExcludedModelElementsIterator = lExcludedModelElements
0337: .iterator(); lExcludedModelElementsIterator
0338: .hasNext();)
0339: mShowRemovedElementActionMenuItem
0340: .add(new ShowRemovedElementAction(
0341: (ModelElement) lExcludedModelElementsIterator
0342: .next()));
0343: } else
0344: mShowRemovedElementAction.setEnabled(false);
0345:
0346: // Work on the show removed element types menu
0347: if (!mRemovedModelElementTypes.isEmpty()) {
0348: mShowRemovedElementTypeAction.setEnabled(true);
0349: mShowRemovedElementTypeActionMenuItem.removeAll();
0350: mShowRemovedElementTypeActionMenuItem
0351: .add(new ShowRemovedElementTypeAction(null));
0352: List lExcludedModelElementTypes = new ArrayList(
0353: mRemovedModelElementTypes);
0354: Collections.sort(lExcludedModelElementTypes,
0355: sRefClassComparator);
0356: for (Iterator lExcludedModelElementTypesIterator = lExcludedModelElementTypes
0357: .iterator(); lExcludedModelElementTypesIterator
0358: .hasNext();)
0359: mShowRemovedElementTypeActionMenuItem
0360: .add(new ShowRemovedElementTypeAction(
0361: (RefClass) lExcludedModelElementTypesIterator
0362: .next()));
0363: } else
0364: mShowRemovedElementTypeAction.setEnabled(false);
0365:
0366: // Work on the show hidden elements menu
0367: if (!mHiddenModelElements.isEmpty()) {
0368: mShowHiddenElementAction.setEnabled(true);
0369: mShowHiddenElementActionMenuItem.removeAll();
0370: mShowHiddenElementActionMenuItem
0371: .add(new ShowHiddenElementAction(null));
0372: List lExcludedModelElements = new ArrayList(
0373: mHiddenModelElements);
0374: Collections.sort(lExcludedModelElements,
0375: sModelElementComparator);
0376: for (Iterator lExcludedModelElementsIterator = lExcludedModelElements
0377: .iterator(); lExcludedModelElementsIterator
0378: .hasNext();)
0379: mShowHiddenElementActionMenuItem
0380: .add(new ShowHiddenElementAction(
0381: (ModelElement) lExcludedModelElementsIterator
0382: .next()));
0383: } else
0384: mShowHiddenElementAction.setEnabled(false);
0385:
0386: // Work on the show hidden element types menu
0387: if (!mHiddenModelElementTypes.isEmpty()) {
0388: mShowHiddenElementTypeAction.setEnabled(true);
0389: mShowHiddenElementTypeActionMenuItem.removeAll();
0390: mShowHiddenElementTypeActionMenuItem
0391: .add(new ShowHiddenElementTypeAction(null));
0392: List lExcludedModelElementTypes = new ArrayList(
0393: mHiddenModelElementTypes);
0394: Collections.sort(lExcludedModelElementTypes,
0395: sRefClassComparator);
0396: for (Iterator lExcludedModelElementTypesIterator = lExcludedModelElementTypes
0397: .iterator(); lExcludedModelElementTypesIterator
0398: .hasNext();)
0399: mShowHiddenElementTypeActionMenuItem
0400: .add(new ShowHiddenElementTypeAction(
0401: (RefClass) lExcludedModelElementTypesIterator
0402: .next()));
0403: } else
0404: mShowHiddenElementTypeAction.setEnabled(false);
0405: }
0406:
0407: // Reinitialises the diagram
0408: public void reinitialiseDiagram() {
0409: try {
0410: if (!isModelElementFromIgnoredPackage(mCurrentModelElement)) {
0411: mNodesByIdMap.clear();
0412: mEdgesByIdMap.clear();
0413: mGraph.reinit(false);
0414: // Display the graph for the epicenter element
0415: edu.berkeley.guir.prefuse.graph.Node lModelElementNode = getOrCreateModelElementNode(mCurrentModelElement);
0416: buildDependencyGraph(lModelElementNode,
0417: mCurrentModelElement, mCurrentDepthLevel);
0418: // Display the dependencies (one level only!) for the additional exploded elements
0419: for (Iterator lAdditionalExplodedModelElementsIterator = mAdditionalExplodedModelElements
0420: .iterator(); lAdditionalExplodedModelElementsIterator
0421: .hasNext();) {
0422: ModelElement lAdditionalExplodedModelElement = (ModelElement) lAdditionalExplodedModelElementsIterator
0423: .next();
0424: edu.berkeley.guir.prefuse.graph.Node lAdditionalExplodedModelElementNode = getOrCreateModelElementNode(lAdditionalExplodedModelElement);
0425: buildDependencyGraph(
0426: lAdditionalExplodedModelElementNode,
0427: lAdditionalExplodedModelElement, 1);
0428: }
0429: displayGraph();
0430: } else
0431: throw new IllegalArgumentException(
0432: "Displaying of the diagram is only supported for certain element types. Unable to display diagram for "
0433: + mCurrentModelElement.getRef());
0434: } catch (Throwable t) {
0435: t.printStackTrace();
0436: }
0437: }
0438:
0439: // Builds the graph of the datatype dependencies
0440: public void buildDependencyGraph(
0441: edu.berkeley.guir.prefuse.graph.Node pParentModelElementNode,
0442: ModelElement pParentModelElement, int pDepthLevel)
0443: throws Exception {
0444: // We are not building dependencies for the certain packages
0445: if (isModelElementFromIgnoredPackage(pParentModelElement))
0446: return; // Ignoring the package
0447: if (isRemovedModelElement(pParentModelElement))
0448: return; // Ignoring the excluded model element (as if the depth level was zero here)
0449: if (isModelElementFromExcludedDependenciesList(pParentModelElement))
0450: return; // Ignoring the excluded model element (as if the depth level was zero here)
0451: if (pDepthLevel == 0)
0452: return; // There is nothing to do if depth level is zero
0453:
0454: // Study references and add them in
0455: MofClass lMetaObject = (MofClass) pParentModelElement
0456: .refMetaObject();
0457: // Collect contents for the type and all supertypes
0458: List lAllContents = new ArrayList();
0459: lAllContents.addAll(lMetaObject.getContents());
0460: for (Iterator lSupertypesIterator = lMetaObject.allSupertypes()
0461: .iterator(); lSupertypesIterator.hasNext();)
0462: lAllContents.addAll(((MofClass) lSupertypesIterator.next())
0463: .getContents());
0464: for (Iterator lAllContentsIterator = lAllContents.iterator(); lAllContentsIterator
0465: .hasNext();) {
0466: Feature lFeature = (Feature) lAllContentsIterator.next();
0467: if (lFeature instanceof Reference) {
0468: Reference lReference = (Reference) lFeature;
0469: AssociationEnd lExposedEnd = lReference.getExposedEnd();
0470: AssociationEnd lReferencedEnd = lReference
0471: .getReferencedEnd();
0472: AggregationKind lExposedAggregationKind = lExposedEnd
0473: .getAggregation();
0474: AggregationKind lReferencedAggregationKind = lReferencedEnd
0475: .getAggregation();
0476: boolean lDependencyFromModelElement = (lExposedAggregationKind
0477: .equals(AggregationKindEnum.COMPOSITE) || lExposedAggregationKind
0478: .equals(AggregationKindEnum.SHARED));
0479: boolean lContainmentDependency = (lExposedAggregationKind
0480: .equals(AggregationKindEnum.COMPOSITE) || lReferencedAggregationKind
0481: .equals(AggregationKindEnum.COMPOSITE));
0482: // When showing downstream diagram association may need to be collapsed. This means that
0483: // all dependents of the referenced element are shown a s the dependents of the parent element and
0484: // the dependent element is not shown at all
0485: if ((mShowDownstream == true && lDependencyFromModelElement == true)
0486: || (mShowUpstream == true && lDependencyFromModelElement == false)) {
0487: List lAllReferencedValues = new ArrayList();
0488: Object lReferenceValue = pParentModelElement
0489: .refGetValue(lReference);
0490: if (lReferenceValue != null) {
0491: if (lReferenceValue instanceof ModelElement)
0492: lAllReferencedValues.add(lReferenceValue);
0493: else if (lReferenceValue instanceof Collection)
0494: lAllReferencedValues
0495: .addAll((Collection) lReferenceValue);
0496: else
0497: throw new Exception(
0498: "Unexpected reference value");
0499: for (Iterator lReferencedModelElementsIterator = lAllReferencedValues
0500: .iterator(); lReferencedModelElementsIterator
0501: .hasNext();) {
0502: // Single reference
0503: ModelElement lReferencedModelElement = (ModelElement) lReferencedModelElementsIterator
0504: .next();
0505: if (isModelElementFromIgnoredPackage(lReferencedModelElement) == false
0506: && isRemovedModelElement(lReferencedModelElement) == false) {
0507: if (isHiddenModelElement(lReferencedModelElement)) {
0508: // Find the closest visible ancestor to this element and as the byproduct
0509: // build the list of invisible elements which must be collapsed to the visible ancestor once it is found
0510: List lInvisibleElementsToProcess = new ArrayList();
0511: lInvisibleElementsToProcess
0512: .add(lReferencedModelElement);
0513: ModelElement lVisibleAncestorElement = (ModelElement) lReferencedModelElement
0514: .refImmediateComposite();
0515: while (isHiddenModelElement(lVisibleAncestorElement)) {
0516: lInvisibleElementsToProcess
0517: .add(lVisibleAncestorElement);
0518: lVisibleAncestorElement = (ModelElement) lVisibleAncestorElement
0519: .refImmediateComposite();
0520: }
0521:
0522: // If the element we are looking at is the visible ancestor of the invisible element
0523: // all we have to do is not to create edge and node, but simply draw all dependencies from the ignored element back to us
0524: if (lVisibleAncestorElement
0525: .equals(pParentModelElement)) {
0526: // Recursively call building of the graph, but do not decrement depth level because we have not drawn any new node
0527: for (Iterator lInvisibleElementsIterator = lInvisibleElementsToProcess
0528: .iterator(); lInvisibleElementsIterator
0529: .hasNext();) {
0530: ModelElement lInvisibleElementToProcess = (ModelElement) lInvisibleElementsIterator
0531: .next();
0532: buildDependencyGraph(
0533: pParentModelElementNode,
0534: lInvisibleElementToProcess,
0535: pDepthLevel);
0536: }
0537: } else {
0538: // Only draw it if this ancestor is not ignored
0539: if (isModelElementFromIgnoredPackage(lVisibleAncestorElement) == false
0540: && isRemovedModelElement(lVisibleAncestorElement) == false) {
0541: // Draw the node and the edge to the visible ancestor
0542: edu.berkeley.guir.prefuse.graph.Node lVisibleAncestorElementNode = getOrCreateModelElementNode(lVisibleAncestorElement);
0543: // Build the id of the edge. This is important because the edge should not be created many times even if
0544: // there are more than one dependencies between two edges
0545: // The name of the edge is <Referenced Node Id>IsReferencedBy<Referencing Node Id >
0546: if (lDependencyFromModelElement) {
0547: String lEdgeId = lVisibleAncestorElementNode
0548: .getAttribute("id")
0549: + "IsReferencedBy"
0550: + pParentModelElementNode
0551: .getAttribute("id");
0552: getOrCreateEdge(
0553: lEdgeId,
0554: lContainmentDependency,
0555: pParentModelElementNode,
0556: lVisibleAncestorElementNode);
0557: } else {
0558: String lEdgeId = pParentModelElementNode
0559: .getAttribute("id")
0560: + "IsReferencedBy"
0561: + lVisibleAncestorElementNode
0562: .getAttribute("id");
0563: getOrCreateEdge(
0564: lEdgeId,
0565: lContainmentDependency,
0566: lVisibleAncestorElementNode,
0567: pParentModelElementNode);
0568: }
0569: // Recursively call building of the graph
0570: buildDependencyGraph(
0571: lVisibleAncestorElementNode,
0572: lVisibleAncestorElement,
0573: pDepthLevel - 1);
0574: }
0575: }
0576: } else {
0577: edu.berkeley.guir.prefuse.graph.Node lReferencedModelElementNode = getOrCreateModelElementNode(lReferencedModelElement);
0578: // Build the id of the edge. This is important because the edge should not be created many times even if
0579: // there are more than one dependencies between two edges
0580: // The name of the edge is <Referenced Node Id>IsReferencedBy<Referencing Node Id >
0581: if (lDependencyFromModelElement) {
0582: String lEdgeId = lReferencedModelElementNode
0583: .getAttribute("id")
0584: + "IsReferencedBy"
0585: + pParentModelElementNode
0586: .getAttribute("id");
0587: getOrCreateEdge(
0588: lEdgeId,
0589: lContainmentDependency,
0590: pParentModelElementNode,
0591: lReferencedModelElementNode);
0592: } else {
0593: String lEdgeId = pParentModelElementNode
0594: .getAttribute("id")
0595: + "IsReferencedBy"
0596: + lReferencedModelElementNode
0597: .getAttribute("id");
0598: getOrCreateEdge(
0599: lEdgeId,
0600: lContainmentDependency,
0601: lReferencedModelElementNode,
0602: pParentModelElementNode);
0603: }
0604: // Recursively call building of the graph
0605: buildDependencyGraph(
0606: lReferencedModelElementNode,
0607: lReferencedModelElement,
0608: pDepthLevel - 1);
0609: }
0610: }
0611: }
0612: }
0613: }
0614: }
0615: }
0616: }
0617:
0618: // Returns existing or creates new node and than returns it
0619: private edu.berkeley.guir.prefuse.graph.Node getOrCreateModelElementNode(
0620: ModelElement pModelElement) {
0621: edu.berkeley.guir.prefuse.graph.Node lModelElementNode = (edu.berkeley.guir.prefuse.graph.Node) mNodesByIdMap
0622: .get(pModelElement.getRef());
0623: if (lModelElementNode != null)
0624: return lModelElementNode;
0625: String lTargetNodeId = pModelElement.getRef();
0626: String lTargetNodeLabel = getNodeLabel(pModelElement);
0627: DefaultTreeNode lTargetNode = new DefaultTreeNode();
0628: mNodesByIdMap.put(lTargetNodeId, lTargetNode);
0629: lTargetNode.setAttribute("id", lTargetNodeId);
0630: lTargetNode.setAttribute("label", lTargetNodeLabel);
0631: String lIconLocation = getNodeIconLocation(pModelElement);
0632: if (lIconLocation != null)
0633: lTargetNode.setAttribute("image", lIconLocation);
0634: // Add node to the graph
0635: mGraph.addNode(lTargetNode);
0636: return lTargetNode;
0637: }
0638:
0639: // Returns existing or creates new edge and than returns it
0640: private edu.berkeley.guir.prefuse.graph.Edge getOrCreateEdge(
0641: String lEdgeId, boolean pIsContainment,
0642: edu.berkeley.guir.prefuse.graph.Node pSourceNode,
0643: edu.berkeley.guir.prefuse.graph.Node pTargetNode) {
0644: edu.berkeley.guir.prefuse.graph.Edge lEdge = (edu.berkeley.guir.prefuse.graph.Edge) mEdgesByIdMap
0645: .get(lEdgeId);
0646: if (lEdge != null)
0647: return lEdge;
0648: SpecialEdge lTargetEdge = new SpecialEdge(pSourceNode,
0649: pTargetNode);
0650: mEdgesByIdMap.put(lEdgeId, lTargetEdge);
0651: lTargetEdge.setId(lEdgeId);
0652: lTargetEdge.setContainment(pIsContainment);
0653: // Add edge to the graph
0654: mGraph.addEdge(lTargetEdge);
0655: return lTargetEdge;
0656: }
0657:
0658: // Displays given dependencies document
0659: public void displayGraph() {
0660: try {
0661: if (mDisplay != null) {
0662: mDisplay.setVisible(false);
0663: remove(mDisplay);
0664: }
0665: mDisplay = new Display();
0666: ItemRegistry mRegistry = new ItemRegistry(mGraph);
0667:
0668: // initialize renderers
0669: // TextItemRenderer nodeRenderer = new TextItemRenderer();
0670: // nodeRenderer.setMaxTextWidth(75);
0671: // nodeRenderer.setAbbrevType(StringAbbreviator.NAME);
0672: // nodeRenderer.setRoundedCorner(8,8);
0673: TextImageItemRenderer nodeRenderer = new TextImageItemRenderer();
0674: nodeRenderer.setImageFactory(new SpecialImageFactory());
0675: nodeRenderer.setImageSpacing(2);
0676: nodeRenderer.setMaxImageDimensions(18, 18);
0677: nodeRenderer.setMaxTextWidth(75);
0678: nodeRenderer.setAbbrevType(StringAbbreviator.NAME);
0679: nodeRenderer.setRoundedCorner(8, 8);
0680:
0681: Renderer edgeRenderer = new SpecialEdgeRenderer();
0682:
0683: mRegistry.setRendererFactory(new DefaultRendererFactory(
0684: nodeRenderer, edgeRenderer));
0685:
0686: // initialize action pipelines
0687: mLayout = new ActionList(mRegistry);
0688: mLayout.add(new TreeFilter(true));
0689: mLayout.add(new RadialTreeLayout());
0690: mLayout.add(new DemoColorFunction(3));
0691:
0692: ActionList update = new ActionList(mRegistry);
0693: update.add(new DemoColorFunction(3));
0694: update.add(new RepaintAction());
0695:
0696: ActionList animate = new ActionList(mRegistry, 1500, 20);
0697: animate.setPacingFunction(new SlowInSlowOutPacer());
0698: animate.add(new PolarLocationAnimator());
0699: animate.add(new ColorAnimator());
0700: animate.add(new RepaintAction());
0701: animate.alwaysRunAfter(mLayout);
0702:
0703: // initialize display
0704: mDisplay.setItemRegistry(mRegistry);
0705: mDisplay.setBackground(Color.WHITE);
0706: mDisplay.addControlListener(new FocusControl(mLayout));
0707: mDisplay.addControlListener(new FocusControl(0,
0708: FocusManager.HOVER_KEY));
0709: mDisplay.addControlListener(new DragControl());
0710: mDisplay.addControlListener(new PanControl());
0711: mDisplay.addControlListener(new ZoomControl());
0712: mDisplay.addControlListener(new NeighborHighlightControl(
0713: update));
0714: mDisplay.addControlListener(new NeighborHighlightControl(
0715: update));
0716:
0717: DefaultFocusSet lHoverKeyFocusSet = new DefaultFocusSet();
0718: mRegistry.getFocusManager().putFocusSet(
0719: FocusManager.HOVER_KEY, lHoverKeyFocusSet);
0720: DefaultFocusSet lDefaultFocusSet = new DefaultFocusSet();
0721: mRegistry.getFocusManager().putFocusSet(
0722: FocusManager.DEFAULT_KEY, lDefaultFocusSet);
0723: lDefaultFocusSet.addFocusListener(mFocusListener);
0724:
0725: // create and display application window
0726: addComponentListener(new ComponentAdapter() {
0727: public void componentResized(ComponentEvent e) {
0728: mLayout.runNow();
0729: }
0730: });
0731: add(mDisplay, BorderLayout.CENTER);
0732: mDisplay.addControlListener(mControlAdapter);
0733: mDisplay.setVisible(true);
0734: setVisible(true);
0735: doLayout();
0736: mLayout.runNow();
0737: } catch (Exception e) {
0738: e.printStackTrace();
0739: }
0740: }
0741:
0742: // Returns name of the icon associated with the given model element
0743: private String getNodeIconName(ModelElement pModelElement) {
0744: MofClass lMetaObject = (MofClass) pModelElement.refMetaObject();
0745: return getNodeIconName((String) lMetaObject.refGetValue("name"));
0746: }
0747:
0748: // Returns name of the icon associated with the given model element type
0749: private String getNodeIconName(RefClass pModelElementClass) {
0750: MofClass lMetaObject = (MofClass) pModelElementClass
0751: .refMetaObject();
0752: return getNodeIconName((String) lMetaObject.refGetValue("name"));
0753: }
0754:
0755: // Returns name of the icon associated with the given model element
0756: private String getNodeIconName(String pTypeName) {
0757:
0758: if (pTypeName.equals("StructureField"))
0759: return "Fields.gif";
0760: if (pTypeName.equals("MessageField"))
0761: return "Fields.gif";
0762: if (pTypeName.equals("SelectorInputField"))
0763: return "Fields.gif";
0764:
0765: if (pTypeName.equals("OperationInputField"))
0766: pTypeName = "InputField";
0767: else if (pTypeName.equals("OperationOutputField"))
0768: pTypeName = "OutputField";
0769: else if (pTypeName.equals("EventSubscriptionOperation"))
0770: pTypeName = "Operation";
0771: else if (pTypeName.equals("EventDataField"))
0772: pTypeName = "OutputField";
0773: else if (pTypeName.equals("EventMessageField"))
0774: pTypeName = "OperationOutputMessage";
0775:
0776: return "ModelElement_" + pTypeName + ".gif";
0777: }
0778:
0779: // Returns icon location or null if none found
0780: private String getNodeIconLocation(ModelElement pModelElement) {
0781: URL lImageURL = IconsHolder.class
0782: .getResource(getNodeIconName(pModelElement));
0783: if (lImageURL != null)
0784: return lImageURL.toString();
0785: return null;
0786: }
0787:
0788: // Returns label
0789: private String getNodeLabel(ModelElement pModelElement) {
0790: if (pModelElement instanceof DesignLibrary)
0791: return "Design Library";
0792: else if (pModelElement instanceof TechnologyLibrary)
0793: return "Tech Library";
0794: else if (pModelElement instanceof DataDictionary)
0795: return "Data Dictionary";
0796: else if (pModelElement instanceof UsageSpecification)
0797: return "Usage Specification";
0798: else if (pModelElement instanceof EventSubscriptionOperation)
0799: return "Event Subscription Operation";
0800: return pModelElement.getName();
0801: }
0802:
0803: public class DemoColorFunction extends ColorFunction {
0804: private Color graphEdgeColor = Color.LIGHT_GRAY;
0805: private Color highlightColor = new Color(50, 50, 255);
0806: private Color focusColor = new Color(255, 50, 50);
0807: private ColorMap colorMap;
0808:
0809: public DemoColorFunction(int thresh) {
0810: colorMap = new ColorMap(ColorMap.getInterpolatedMap(
0811: thresh + 1, Color.RED, Color.BLACK), 0, thresh);
0812: } //
0813:
0814: public Paint getFillColor(VisualItem item) {
0815: if (item instanceof NodeItem) {
0816: return Color.WHITE;
0817: } else if (item instanceof AggregateItem) {
0818: return Color.LIGHT_GRAY;
0819: } else if (item instanceof EdgeItem) {
0820: return getColor(item);
0821: } else {
0822: return Color.BLACK;
0823: }
0824: } //
0825:
0826: public Paint getColor(VisualItem item) {
0827: if (item.isFocus()) {
0828: return focusColor;
0829: } else if (item.isHighlighted()) {
0830: return highlightColor;
0831: } else if (item instanceof NodeItem) {
0832: int d = ((NodeItem) item).getDepth();
0833: return colorMap.getColor(d);
0834: } else if (item instanceof EdgeItem) {
0835: EdgeItem e = (EdgeItem) item;
0836: if (e.isTreeEdge()) {
0837: int d, d1, d2;
0838: d1 = ((NodeItem) e.getFirstNode()).getDepth();
0839: d2 = ((NodeItem) e.getSecondNode()).getDepth();
0840: d = Math.max(d1, d2);
0841: return colorMap.getColor(d);
0842: } else {
0843: return graphEdgeColor;
0844: }
0845: } else {
0846: return Color.BLACK;
0847: }
0848: } //
0849: } // end of inner class DemoColorFunction
0850:
0851: // Helper. Returns true if given model element should be ignored from ther diagram
0852: private boolean isModelElementFromIgnoredPackage(
0853: ModelElement pModelElement) {
0854: Class lElementPackageClass = pModelElement
0855: .refImmediatePackage().getClass();
0856: for (Iterator lIgnoredPackageClassesIterator = sIgnoredPackages
0857: .iterator(); lIgnoredPackageClassesIterator.hasNext();) {
0858: Class lIgnoredPackage = (Class) lIgnoredPackageClassesIterator
0859: .next();
0860: if (lIgnoredPackage.isAssignableFrom(lElementPackageClass))
0861: return true; // This element should be ignored
0862: }
0863: return false; // This element should not be ignored
0864: }
0865:
0866: // Helper. Returns true if given model element should be excluded from the diagram
0867: private boolean isRemovedModelElement(ModelElement pModelElement) {
0868: // First test if this element itself is removed
0869: if (mRemovedModelElements.contains(pModelElement))
0870: return true;
0871: // Now test if all elements of this type are removed
0872: if (mRemovedModelElementTypes
0873: .contains(pModelElement.refClass()))
0874: return true;
0875: return false; // This element should not be made invisible
0876: }
0877:
0878: // Helper. Returns true if given model element's dependencies should be excluded from the diagram
0879: private boolean isModelElementFromExcludedDependenciesList(
0880: ModelElement pModelElement) {
0881: return mExcludedDependenciesModelElements
0882: .contains(pModelElement);
0883: }
0884:
0885: // Helper. Returns true if given model element should be hidden behind the parent
0886: private boolean isHiddenModelElement(ModelElement pModelElement) {
0887: // First test if this element itself is not visible
0888: if (mHiddenModelElements.contains(pModelElement))
0889: return true;
0890: // Now test if all elements of this type are made invisible
0891: if (mHiddenModelElementTypes.contains(pModelElement.refClass()))
0892: return true;
0893: return false; // This element should not be made invisible
0894: }
0895:
0896: // fill actions list
0897: protected void fillActions(ArrayList pActionList) {
0898: if (pActionList == null)
0899: return;
0900: updateActions();
0901: pActionList.add(mBistreamDiagramAction);
0902: pActionList.add(mDownstreamDiagramAction);
0903: pActionList.add(mUpstreamDiagramAction);
0904: pActionList.add(new SeparatorAction());
0905: pActionList.add(mMoreDetailsAction);
0906: pActionList.add(mLessDetailsAction);
0907: }
0908:
0909: /* Auxilary classes */
0910:
0911: private class SpecialFocusListener implements FocusListener {
0912: public void focusChanged(FocusEvent e) {
0913: String lNewSelectedNodeName = null;
0914: Iterator lCurentFocusSetIterator = e.getFocusSet()
0915: .iterator();
0916: if (lCurentFocusSetIterator.hasNext())
0917: lNewSelectedNodeName = ((edu.berkeley.guir.prefuse.graph.Node) lCurentFocusSetIterator
0918: .next()).getAttribute("label");
0919: }
0920: }
0921:
0922: private class SpecialControlAdapter extends ControlAdapter {
0923: public void mousePressed(MouseEvent e) {
0924: super .mousePressed(e);
0925: maybeShowPopup(null, e);
0926: }
0927:
0928: public void mouseReleased(MouseEvent e) {
0929: super .mouseReleased(e);
0930: maybeShowPopup(null, e);
0931: }
0932:
0933: public void itemReleased(VisualItem gi, MouseEvent e) {
0934: maybeShowPopup(gi, e);
0935: }
0936:
0937: public void itemPressed(VisualItem gi, MouseEvent e) {
0938: maybeShowPopup(gi, e);
0939: }
0940:
0941: private void maybeShowPopup(VisualItem gi, MouseEvent e) {
0942: if (e.isPopupTrigger()) {
0943: mLastSelectedForPopupModelElement = (gi != null) ? mMetaBossModelPackage
0944: .getModelElement().getByRef(
0945: gi.getAttribute("id"))
0946: : null;
0947:
0948: updateActions();
0949: showPopUp(e);
0950: }
0951: }
0952:
0953: private void showPopUp(MouseEvent e) {
0954: JPopupMenu lPopupMenu = new JPopupMenu();
0955: // Build either model element context menu or the generic one
0956: if (mLastSelectedForPopupModelElement != null) {
0957: lPopupMenu.add(mEditPropertiesAction);
0958: lPopupMenu.add(mRebaseAction);
0959: lPopupMenu.addSeparator();
0960: lPopupMenu.add(mShowDependenciesActionMenuItem);
0961: lPopupMenu.add(mRemoveDependenciesActionMenuItem);
0962: lPopupMenu.add(mRemoveElementAction);
0963: lPopupMenu.add(mRemoveElementTypeAction);
0964: lPopupMenu.add(mHideElementAction);
0965: lPopupMenu.add(mHideElementTypeAction);
0966: lPopupMenu.addSeparator();
0967: lPopupMenu.add(mShowRemovedElementActionMenuItem);
0968: lPopupMenu.add(mShowRemovedElementTypeActionMenuItem);
0969: lPopupMenu.add(mShowHiddenElementActionMenuItem);
0970: lPopupMenu.add(mShowHiddenElementTypeActionMenuItem);
0971: } else {
0972: lPopupMenu.add(mShowRemovedElementActionMenuItem);
0973: lPopupMenu.add(mShowRemovedElementTypeActionMenuItem);
0974: lPopupMenu.add(mShowHiddenElementActionMenuItem);
0975: lPopupMenu.add(mShowHiddenElementTypeActionMenuItem);
0976: lPopupMenu.addSeparator();
0977: lPopupMenu.add(mBistreamDiagramAction);
0978: lPopupMenu.add(mDownstreamDiagramAction);
0979: lPopupMenu.add(mUpstreamDiagramAction);
0980: lPopupMenu.addSeparator();
0981: lPopupMenu.add(mMoreDetailsAction);
0982: lPopupMenu.add(mLessDetailsAction);
0983: }
0984: lPopupMenu.show(e.getComponent(), e.getX(), e.getY());
0985: }
0986: }
0987:
0988: /* Actions */
0989:
0990: public class EditPropertiesAction extends BaseAction {
0991: public EditPropertiesAction() {
0992: super (
0993: Application.getString("editproperties_action"),
0994: "Displays property editor for the selected model element",
0995: Application.EDIT_ICON);
0996: }
0997:
0998: public void actionPerformed(ActionEvent arg0) {
0999: ModelElement lModelElementToEditProperties = mLastSelectedForPopupModelElement;
1000: mLastSelectedForPopupModelElement = null; // To prevent double entry
1001: if (lModelElementToEditProperties != null)
1002: UserObjectFactory.createUserObject(
1003: lModelElementToEditProperties).getEditAction()
1004: .run();
1005: updateActions();
1006: }
1007: }
1008:
1009: private class ShowDependenciesAction extends AbstractAction {
1010: public ShowDependenciesAction() {
1011: super ("Show dependencies");
1012: putValue(SHORT_DESCRIPTION,
1013: "Include all dependencies of this element in the diagram");
1014: }
1015:
1016: public void actionPerformed(ActionEvent e) {
1017: ModelElement lModelElementToExplore = mLastSelectedForPopupModelElement;
1018: mLastSelectedForPopupModelElement = null; // To prevent double entry
1019: if (mShowDependenciesActionMenuItem.getState()) {
1020: // Need to expand
1021: // Add the selected element to the additional explored elements and reitinialise diagram
1022: mAdditionalExplodedModelElements
1023: .add(lModelElementToExplore);
1024: mRemovedModelElements.remove(lModelElementToExplore);
1025: mExcludedDependenciesModelElements
1026: .remove(lModelElementToExplore);
1027: } else {
1028: // Need to collapse
1029: mAdditionalExplodedModelElements
1030: .remove(lModelElementToExplore);
1031: }
1032: reinitialiseDiagram();
1033: updateActions();
1034: }
1035: };
1036:
1037: private class RemoveDependenciesAction extends AbstractAction {
1038: public RemoveDependenciesAction() {
1039: super ("Remove dependencies");
1040: putValue(SHORT_DESCRIPTION,
1041: "Remove all dependencies of this element from the diagram");
1042: }
1043:
1044: public void actionPerformed(ActionEvent e) {
1045: ModelElement lModelElementToHideDependencies = mLastSelectedForPopupModelElement;
1046: mLastSelectedForPopupModelElement = null; // To prevent double entry
1047: if (mRemoveDependenciesActionMenuItem.getState()) {
1048: // Need to hide dependencies
1049: // Add the selected element to the additional explored elements and reitinialise diagram
1050: mAdditionalExplodedModelElements
1051: .remove(lModelElementToHideDependencies);
1052: mRemovedModelElements
1053: .remove(lModelElementToHideDependencies);
1054: mExcludedDependenciesModelElements
1055: .add(lModelElementToHideDependencies);
1056: } else {
1057: // Need to show dependencies
1058: mExcludedDependenciesModelElements
1059: .remove(lModelElementToHideDependencies);
1060: }
1061: reinitialiseDiagram();
1062: updateActions();
1063: }
1064: };
1065:
1066: private class RemoveElementAction extends AbstractAction {
1067: public RemoveElementAction() {
1068: super ("Remove element");
1069: putValue(SHORT_DESCRIPTION,
1070: "Remove this element and all its dependencies from the diagram");
1071: }
1072:
1073: public void actionPerformed(ActionEvent e) {
1074: ModelElement lModelElementToRemove = mLastSelectedForPopupModelElement;
1075: mLastSelectedForPopupModelElement = null; // To prevent double entry
1076: // Manipulate elements and types collections and reinitialise the diagram
1077: mRemovedModelElements.add(lModelElementToRemove);
1078: reinitialiseDiagram();
1079: updateActions();
1080: }
1081: };
1082:
1083: private class RemoveElementTypeAction extends AbstractAction {
1084: public RemoveElementTypeAction() {
1085: super ("Remove type");
1086: putValue(SHORT_DESCRIPTION,
1087: "Remove all elements of this type with all their dependencies from the diagram");
1088: }
1089:
1090: public void actionPerformed(ActionEvent e) {
1091: ModelElement lModelElementToRemove = mLastSelectedForPopupModelElement;
1092: mLastSelectedForPopupModelElement = null; // To prevent double entry
1093: // Manipulate elements and types collections and reinitialise the diagram
1094: mRemovedModelElementTypes.add(lModelElementToRemove
1095: .refClass());
1096: reinitialiseDiagram();
1097: updateActions();
1098: }
1099: };
1100:
1101: private class HideElementAction extends AbstractAction {
1102: public HideElementAction() {
1103: super ("Hide element");
1104: putValue(SHORT_DESCRIPTION,
1105: "Combine this element with the parent element(i.e. hide it within the parent)");
1106: }
1107:
1108: public void actionPerformed(ActionEvent e) {
1109: ModelElement lModelElementToHide = mLastSelectedForPopupModelElement;
1110: mLastSelectedForPopupModelElement = null; // To prevent double entry
1111: // Manipulate elements and types collections and reinitialise the diagram
1112: mHiddenModelElements.add(lModelElementToHide);
1113: reinitialiseDiagram();
1114: updateActions();
1115: }
1116: };
1117:
1118: private class HideElementTypeAction extends AbstractAction {
1119: public HideElementTypeAction() {
1120: super ("Hide type");
1121: putValue(
1122: SHORT_DESCRIPTION,
1123: "Combine all elements of this type with the parent element(i.e. hide them within the parent)");
1124: }
1125:
1126: public void actionPerformed(ActionEvent e) {
1127: ModelElement lModelElementToHideTypeFor = mLastSelectedForPopupModelElement;
1128: mLastSelectedForPopupModelElement = null; // To prevent double entry
1129: // Manipulate elements and types collections and reinitialise the diagram
1130: mHiddenModelElementTypes.add(lModelElementToHideTypeFor
1131: .refClass());
1132: reinitialiseDiagram();
1133: updateActions();
1134: }
1135: };
1136:
1137: private class ShowRemovedElementAction extends AbstractAction {
1138: private ModelElement mSpecificHiddenElement = null;
1139:
1140: // Default constructor. Creates action for the opening of the popup menu
1141: public ShowRemovedElementAction() {
1142: super ("Show removed elements");
1143: putValue(SHORT_DESCRIPTION,
1144: "Show some or all elements which have been removed from this diagram");
1145: }
1146:
1147: // Default constructor. Creates action for the opening of the popup menu
1148: public ShowRemovedElementAction(ModelElement pHiddenElement) {
1149: mSpecificHiddenElement = pHiddenElement;
1150: if (mSpecificHiddenElement != null) {
1151: String lHiddenElementType = (String) pHiddenElement
1152: .refMetaObject().refGetValue("name");
1153: putValue(Action.NAME, pHiddenElement.getName() + " "
1154: + lHiddenElementType);
1155: putValue(
1156: SHORT_DESCRIPTION,
1157: "Show "
1158: + pHiddenElement.getName()
1159: + " "
1160: + lHiddenElementType
1161: + " element. It is currently removed from this diagram.");
1162: ImageIcon lElementIcon = IconsHolder
1163: .loadIcon(getNodeIconName(pHiddenElement));
1164: if (lElementIcon != null)
1165: putValue(Action.SMALL_ICON, lElementIcon);
1166: } else {
1167: putValue(Action.NAME, "Show all");
1168: putValue(SHORT_DESCRIPTION,
1169: "Show all elements which are currently removed from this diagram.");
1170: }
1171: }
1172:
1173: public void actionPerformed(ActionEvent e) {
1174: if (!mRemovedModelElements.isEmpty()) {
1175: if (mSpecificHiddenElement == null) {
1176: // Clear all excluded elements
1177: mRemovedModelElements.clear();
1178: reinitialiseDiagram();
1179: updateActions();
1180: } else if (mRemovedModelElements
1181: .remove(mSpecificHiddenElement)) {
1182: // Clear particular excluded element
1183: reinitialiseDiagram();
1184: updateActions();
1185: }
1186: }
1187: }
1188: };
1189:
1190: private class ShowRemovedElementTypeAction extends AbstractAction {
1191: private RefClass mSpecificRemovedElementClass = null;
1192:
1193: // Default constructor. Creates action for the opening of the popup menu
1194: public ShowRemovedElementTypeAction() {
1195: super ("Show removed types");
1196: putValue(SHORT_DESCRIPTION,
1197: "Show some or all element types which have been removed from this diagram");
1198: }
1199:
1200: // Default constructor. Creates action for the opening of the popup menu
1201: public ShowRemovedElementTypeAction(RefClass pHiddenElementClass) {
1202: mSpecificRemovedElementClass = pHiddenElementClass;
1203: if (mSpecificRemovedElementClass != null) {
1204: String lHiddenElementType = (String) mSpecificRemovedElementClass
1205: .refMetaObject().refGetValue("name");
1206: putValue(Action.NAME, lHiddenElementType);
1207: putValue(
1208: SHORT_DESCRIPTION,
1209: "Show all "
1210: + lHiddenElementType
1211: + " elements. They are currently removed from this diagram.");
1212: ImageIcon lElementIcon = IconsHolder
1213: .loadIcon(getNodeIconName(mSpecificRemovedElementClass));
1214: if (lElementIcon != null)
1215: putValue(Action.SMALL_ICON, lElementIcon);
1216: } else {
1217: putValue(Action.NAME, "Show all");
1218: putValue(SHORT_DESCRIPTION,
1219: "Show all element types which are currently removed from this diagram.");
1220: }
1221: }
1222:
1223: public void actionPerformed(ActionEvent e) {
1224: if (!mRemovedModelElementTypes.isEmpty()) {
1225: if (mSpecificRemovedElementClass == null) {
1226: // Clear all excluded elements
1227: mRemovedModelElementTypes.clear();
1228: reinitialiseDiagram();
1229: updateActions();
1230: } else if (mRemovedModelElementTypes
1231: .remove(mSpecificRemovedElementClass)) {
1232: // Clear particular excluded element
1233: reinitialiseDiagram();
1234: updateActions();
1235: }
1236: }
1237: }
1238: };
1239:
1240: private class ShowHiddenElementAction extends AbstractAction {
1241: private ModelElement mSpecificHiddenElement = null;
1242:
1243: // Default constructor. Creates action for the opening of the popup menu
1244: public ShowHiddenElementAction() {
1245: super ("Show hidden elements");
1246: putValue(SHORT_DESCRIPTION,
1247: "Show some or all elements which have been hidden behind parents");
1248: }
1249:
1250: // Default constructor. Creates action for the opening of the popup menu
1251: public ShowHiddenElementAction(ModelElement pHiddenElement) {
1252: mSpecificHiddenElement = pHiddenElement;
1253: if (mSpecificHiddenElement != null) {
1254: String lHiddenElementType = (String) pHiddenElement
1255: .refMetaObject().refGetValue("name");
1256: putValue(Action.NAME, pHiddenElement.getName() + " "
1257: + lHiddenElementType);
1258: putValue(
1259: SHORT_DESCRIPTION,
1260: "Show "
1261: + pHiddenElement.getName()
1262: + " "
1263: + lHiddenElementType
1264: + " element. It is currently hidden behind the parent element.");
1265: ImageIcon lElementIcon = IconsHolder
1266: .loadIcon(getNodeIconName(pHiddenElement));
1267: if (lElementIcon != null)
1268: putValue(Action.SMALL_ICON, lElementIcon);
1269: } else {
1270: putValue(Action.NAME, "Show all");
1271: putValue(SHORT_DESCRIPTION,
1272: "Show all elements which are currently hidden behind parent elements.");
1273: }
1274: }
1275:
1276: public void actionPerformed(ActionEvent e) {
1277: if (!mHiddenModelElements.isEmpty()) {
1278: if (mSpecificHiddenElement == null) {
1279: // Clear all excluded elements
1280: mHiddenModelElements.clear();
1281: reinitialiseDiagram();
1282: updateActions();
1283: } else if (mHiddenModelElements
1284: .remove(mSpecificHiddenElement)) {
1285: // Clear particular excluded element
1286: reinitialiseDiagram();
1287: updateActions();
1288: }
1289: }
1290: }
1291: };
1292:
1293: private class ShowHiddenElementTypeAction extends AbstractAction {
1294: private RefClass mSpecificHiddenElementClass = null;
1295:
1296: // Default constructor. Creates action for the opening of the popup menu
1297: public ShowHiddenElementTypeAction() {
1298: super ("Show hidden types");
1299: putValue(
1300: SHORT_DESCRIPTION,
1301: "Show some or all element types which have been hidden behind the parent elements");
1302: }
1303:
1304: // Default constructor. Creates action for the opening of the popup menu
1305: public ShowHiddenElementTypeAction(RefClass pHiddenElementClass) {
1306: mSpecificHiddenElementClass = pHiddenElementClass;
1307: if (mSpecificHiddenElementClass != null) {
1308: String lHiddenElementType = (String) mSpecificHiddenElementClass
1309: .refMetaObject().refGetValue("name");
1310: putValue(Action.NAME, lHiddenElementType);
1311: putValue(
1312: SHORT_DESCRIPTION,
1313: "Show all "
1314: + lHiddenElementType
1315: + " elements. They are currently hidden behind parent elements.");
1316: ImageIcon lElementIcon = IconsHolder
1317: .loadIcon(getNodeIconName(mSpecificHiddenElementClass));
1318: if (lElementIcon != null)
1319: putValue(Action.SMALL_ICON, lElementIcon);
1320: } else {
1321: putValue(Action.NAME, "Show all");
1322: putValue(SHORT_DESCRIPTION,
1323: "Show all element types which are currently hidden behind parent elements.");
1324: }
1325: }
1326:
1327: public void actionPerformed(ActionEvent e) {
1328: if (!mHiddenModelElementTypes.isEmpty()) {
1329: if (mSpecificHiddenElementClass == null) {
1330: // Clear all excluded elements
1331: mHiddenModelElementTypes.clear();
1332: reinitialiseDiagram();
1333: updateActions();
1334: } else if (mHiddenModelElementTypes
1335: .remove(mSpecificHiddenElementClass)) {
1336: // Clear particular excluded element
1337: reinitialiseDiagram();
1338: updateActions();
1339: }
1340: }
1341: }
1342: };
1343:
1344: private class RebaseAction extends AbstractAction {
1345: public RebaseAction() {
1346: super ("Rebase diagram");
1347: putValue(
1348: SHORT_DESCRIPTION,
1349: "Make this element the epicenter of the diagram. This will clear all hidden or explored elements information.");
1350: }
1351:
1352: public void actionPerformed(ActionEvent e) {
1353: ModelElement lModelElementToRebaseTo = mLastSelectedForPopupModelElement;
1354: mLastSelectedForPopupModelElement = null; // To prevent double entry
1355: // Reinitialise diagram and forget about all interactive permissions
1356: mCurrentModelElement = lModelElementToRebaseTo;
1357: mAdditionalExplodedModelElements.clear();
1358: mRemovedModelElements.clear();
1359: reinitialiseDiagram();
1360: updateActions();
1361: }
1362: };
1363:
1364: private class DownstreamDiagramAction extends BaseAction {
1365: public DownstreamDiagramAction() {
1366: super (
1367: "Downstream diagram",
1368: "Redraw the diagram to show only downstream dependencies",
1369: Application.DOWNSTREAM_ICON);
1370: }
1371:
1372: public void actionPerformed(ActionEvent e) {
1373: // Reinitialise diagram showing only downstream dependencies
1374: mShowDownstream = true;
1375: mShowUpstream = false;
1376: reinitialiseDiagram();
1377: updateActions();
1378: }
1379: };
1380:
1381: private class UpstreamDiagramAction extends BaseAction {
1382: public UpstreamDiagramAction() {
1383: super (
1384: "Upstream diagram",
1385: "Redraw the diagram to show only upstream dependencies",
1386: Application.UPSTREAM_ICON);
1387: }
1388:
1389: public void actionPerformed(ActionEvent e) {
1390: // Reinitialise diagram showing only upstream dependencies
1391: mShowDownstream = false;
1392: mShowUpstream = true;
1393: reinitialiseDiagram();
1394: updateActions();
1395: }
1396: };
1397:
1398: private class BistreamDiagramAction extends BaseAction {
1399: public BistreamDiagramAction() {
1400: super (
1401: "Bistream diagram",
1402: "Redraw the diagram to show both upstream and downstream dependencies",
1403: Application.BISTREAM_ICON);
1404: }
1405:
1406: public void actionPerformed(ActionEvent e) {
1407: // Reinitialise diagram showing both upstream and downstream dependencies
1408: mShowDownstream = true;
1409: mShowUpstream = true;
1410: reinitialiseDiagram();
1411: updateActions();
1412: }
1413: };
1414:
1415: private class LessDetailsAction extends BaseAction {
1416: public LessDetailsAction() {
1417: super ("Less details", "Decreases the depth of the diagram",
1418: Application.LESSDETAILS_ICON);
1419: }
1420:
1421: public void actionPerformed(ActionEvent e) {
1422: if (mCurrentDepthLevel > 1) {
1423: // Reinitialise diagram with lesser level of details
1424: mCurrentDepthLevel--;
1425: reinitialiseDiagram();
1426: }
1427: updateActions();
1428: }
1429: };
1430:
1431: private class MoreDetailsAction extends BaseAction {
1432: public MoreDetailsAction() {
1433: super ("More details", "Increases the depth of the diagram",
1434: Application.MOREDETAILS_ICON);
1435: }
1436:
1437: public void actionPerformed(ActionEvent e) {
1438: // Reinitialise diagram with higher level of details
1439: mCurrentDepthLevel++;
1440: reinitialiseDiagram();
1441: updateActions();
1442: }
1443: };
1444:
1445: }
|