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-2006 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: package org.netbeans.modules.bpel.editors.multiview;
0042:
0043: import java.awt.BorderLayout;
0044: import java.awt.Component;
0045: import java.awt.Dimension;
0046: import java.awt.GridBagConstraints;
0047: import java.awt.event.ActionEvent;
0048: import java.io.IOException;
0049: import java.io.ObjectInput;
0050: import java.io.ObjectOutput;
0051: import javax.swing.Box;
0052: import javax.swing.JComboBox;
0053: import javax.swing.JToggleButton;
0054: import org.netbeans.core.spi.multiview.CloseOperationState;
0055: import org.netbeans.core.spi.multiview.MultiViewElement;
0056: import org.netbeans.core.spi.multiview.MultiViewElementCallback;
0057: import org.netbeans.modules.bpel.core.BPELDataEditorSupport;
0058: import org.netbeans.modules.bpel.core.BPELDataObject;
0059: import org.netbeans.modules.bpel.design.DesignView;
0060: import org.netbeans.modules.bpel.design.NavigationTools;
0061: import org.netbeans.modules.bpel.design.PartnerLinkFilterButton;
0062: import org.netbeans.modules.bpel.design.SequenceFilterButton;
0063: import org.netbeans.modules.bpel.diagram.DiagramImpl;
0064: import org.openide.awt.UndoRedo;
0065: import org.openide.windows.TopComponent;
0066: import java.beans.PropertyChangeListener;
0067: import java.beans.PropertyVetoException;
0068: import java.io.Serializable;
0069: import java.util.Enumeration;
0070: import java.util.HashMap;
0071: import java.util.Iterator;
0072: import java.util.List;
0073: import java.util.Map;
0074: import javax.swing.ActionMap;
0075: import javax.swing.JButton;
0076: import javax.swing.JComponent;
0077: import javax.swing.JToolBar;
0078: import javax.swing.text.DefaultEditorKit;
0079: import javax.swing.text.JTextComponent;
0080: import org.netbeans.core.api.multiview.MultiViewHandler;
0081: import org.netbeans.core.api.multiview.MultiViewPerspective;
0082: import org.netbeans.core.api.multiview.MultiViews;
0083: import org.netbeans.core.spi.multiview.MultiViewFactory;
0084: import org.netbeans.modules.bpel.core.util.BPELValidationController;
0085: import org.netbeans.modules.bpel.core.util.SelectBpelElement;
0086: import org.netbeans.modules.bpel.design.ZoomManager;
0087: import org.netbeans.modules.bpel.design.actions.BreakpointsDeleteAction;
0088: import org.netbeans.modules.bpel.design.actions.BreakpointsDisableAction;
0089: import org.netbeans.modules.bpel.design.actions.BreakpointsEnableAction;
0090: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
0091: import org.netbeans.modules.bpel.model.api.Assign;
0092: import org.netbeans.modules.bpel.model.api.BpelEntity;
0093: import org.openide.util.Lookup;
0094: import org.openide.util.lookup.Lookups;
0095: import org.openide.util.lookup.ProxyLookup;
0096: import org.openide.nodes.Node;
0097: import org.openide.util.lookup.AbstractLookup;
0098: import org.openide.util.lookup.InstanceContent;
0099: import org.openide.windows.CloneableTopComponent;
0100: import org.netbeans.modules.bpel.model.api.BpelModel;
0101: import org.netbeans.modules.bpel.model.api.Catch;
0102: import org.netbeans.modules.bpel.model.api.CatchAll;
0103: import org.netbeans.modules.bpel.model.api.CompensatableActivityHolder;
0104: import org.netbeans.modules.bpel.model.api.Compensate;
0105: import org.netbeans.modules.bpel.model.api.CompensateScope;
0106: import org.netbeans.modules.bpel.model.api.CompensationHandler;
0107: import org.netbeans.modules.bpel.model.api.Copy;
0108: import org.netbeans.modules.bpel.model.api.Correlation;
0109: import org.netbeans.modules.bpel.model.api.CorrelationSet;
0110: import org.netbeans.modules.bpel.model.api.Else;
0111: import org.netbeans.modules.bpel.model.api.ElseIf;
0112: import org.netbeans.modules.bpel.model.api.Empty;
0113: import org.netbeans.modules.bpel.model.api.EventHandlers;
0114: import org.netbeans.modules.bpel.model.api.Exit;
0115: import org.netbeans.modules.bpel.model.api.FaultHandlers;
0116: import org.netbeans.modules.bpel.model.api.Flow;
0117: import org.netbeans.modules.bpel.model.api.ForEach;
0118: import org.netbeans.modules.bpel.model.api.FromPart;
0119: import org.netbeans.modules.bpel.model.api.If;
0120: import org.netbeans.modules.bpel.model.api.Import;
0121: import org.netbeans.modules.bpel.model.api.Invoke;
0122: import org.netbeans.modules.bpel.model.api.MessageExchange;
0123: import org.netbeans.modules.bpel.model.api.OnAlarmEvent;
0124: import org.netbeans.modules.bpel.model.api.OnAlarmPick;
0125: import org.netbeans.modules.bpel.model.api.OnEvent;
0126: import org.netbeans.modules.bpel.model.api.OnMessage;
0127: import org.netbeans.modules.bpel.model.api.PartnerLink;
0128: import org.netbeans.modules.bpel.model.api.PatternedCorrelation;
0129: import org.netbeans.modules.bpel.model.api.Pick;
0130: import org.netbeans.modules.bpel.model.api.Receive;
0131: import org.netbeans.modules.bpel.model.api.RepeatUntil;
0132: import org.netbeans.modules.bpel.model.api.Reply;
0133: import org.netbeans.modules.bpel.model.api.Scope;
0134: import org.netbeans.modules.bpel.model.api.Sequence;
0135: import org.netbeans.modules.bpel.model.api.Throw;
0136: import org.netbeans.modules.bpel.model.api.Wait;
0137: import org.netbeans.modules.bpel.model.api.While;
0138: import org.netbeans.modules.bpel.model.api.Process;
0139: import org.netbeans.modules.bpel.model.api.TerminationHandler;
0140: import org.netbeans.modules.bpel.model.api.ToPart;
0141: import org.netbeans.modules.bpel.model.api.Variable;
0142: import org.netbeans.modules.bpel.model.api.VariableContainer;
0143: import org.netbeans.modules.bpel.model.api.VariableDeclarationScope;
0144: import org.netbeans.modules.bpel.model.api.events.ChangeEventListenerAdapter;
0145: import org.netbeans.modules.bpel.model.api.events.PropertyUpdateEvent;
0146: import org.netbeans.modules.bpel.palette.SoaPaletteFactory;
0147: import org.netbeans.modules.bpel.properties.PropertyNodeFactory;
0148: import org.netbeans.modules.xml.validation.ValidateAction;
0149: import org.netbeans.modules.xml.validation.ValidateAction.RunAction;
0150: import org.netbeans.modules.xml.xam.Model;
0151: import org.netbeans.modules.xml.xam.Model.State;
0152: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
0153: import org.netbeans.modules.xml.xam.ui.undo.QuietUndoManager;
0154: import org.netbeans.modules.print.api.PrintManager;
0155: import org.netbeans.modules.xml.xam.ui.multiview.ActivatedNodesMediator;
0156: import org.netbeans.modules.xml.xam.ui.multiview.CookieProxyLookup;
0157: import org.netbeans.modules.reportgenerator.api.CustomizeReportAction;
0158: import org.netbeans.modules.reportgenerator.api.GenerateReportAction;
0159: import org.netbeans.modules.bpel.search.api.SearchManager;
0160: import org.netbeans.modules.bpel.documentation.DocumentationCookie;
0161: import org.openide.explorer.ExplorerManager;
0162: import org.openide.explorer.ExplorerUtils;
0163: import org.openide.loaders.DataNode;
0164: import org.openide.util.NbBundle;
0165: import org.openide.util.RequestProcessor;
0166: import org.openide.windows.Mode;
0167: import org.openide.windows.TopComponentGroup;
0168: import org.openide.windows.WindowManager;
0169:
0170: /**
0171: * @author ads
0172: */
0173: public class DesignerMultiViewElement extends TopComponent implements
0174: MultiViewElement, ExplorerManager.Provider, Serializable,
0175: SelectBpelElement {
0176: private static final long serialVersionUID = 1L;
0177:
0178: // for deexternalization
0179: private DesignerMultiViewElement() {
0180: super ();
0181: }
0182:
0183: /** Creates a new instance of DesignerMultiViewElement. This is the visual
0184: * canvas 'Design' view in the multiview
0185: */
0186: public DesignerMultiViewElement(BPELDataObject dataObject) {
0187: myDataObject = dataObject;
0188: initialize();
0189: // initializeLookup();
0190: //
0191: // FIX ME
0192: //
0193: initializeUI();
0194: }
0195:
0196: // private void removeActiveNodeChangeListener() {
0197: // if (myActiveNodeChangeListener != null) {
0198: // removePropertyChangeListener(myActiveNodeChangeListener);
0199: // }
0200: // myActiveNodeChangeListener = null;
0201: // }
0202:
0203: // private void initActiveNodeChangeListener() {
0204: // if (myActiveNodeChangeListener == null) {
0205: // myActiveNodeChangeListener = new PropertyChangeListener() {
0206: // /**
0207: // * TODO: may not be needed at some point when parenting
0208: // * MultiViewTopComponent delegates properly to its peer's
0209: // * activatedNodes. see
0210: // * http://www.netbeans.org/issues/show_bug.cgi?id=67257 note:
0211: // * TopComponent.setActivatedNodes is final
0212: // */
0213: // public void propertyChange(PropertyChangeEvent event) {
0214: // // no constant in TopComponent...lame
0215: // if(event.getPropertyName().equals("activatedNodes")) { // NOI18N
0216: //
0217: // TopComponent tc = TopComponent.getRegistry().getActivated();
0218: // /* Ignore event coming from my TC */
0219: // // if(DEBUG)
0220: // // Debug.verboseWithin(this,"propertyChange",getDataObject());
0221: // nodesHack.set(Arrays.asList(getActivatedNodes()),null);
0222: // }
0223: // };
0224: // };
0225: // } else {
0226: // removePropertyChangeListener(myActiveNodeChangeListener);
0227: // }
0228: //
0229: // addPropertyChangeListener(myActiveNodeChangeListener);
0230: // setActivatedNodes(new Node[] {getDataObject().getNodeDelegate()});
0231: // }
0232:
0233: public void writeExternal(ObjectOutput out) throws IOException {
0234: super .writeExternal(out);
0235: out.writeObject(myDataObject);
0236: }
0237:
0238: /**
0239: * we are using Externalization semantics so that we can get a hook to call
0240: * initialize() upon deserialization
0241: */
0242: public void readExternal(ObjectInput in) throws IOException,
0243: ClassNotFoundException {
0244: super .readExternal(in);
0245:
0246: myDataObject = (BPELDataObject) in.readObject();
0247:
0248: initialize();
0249: // initializeLookup();
0250: //
0251: // FIX ME
0252: //
0253: initializeUI();
0254: }
0255:
0256: ////////////////////////////////////////////////////////////////////////////
0257: // UI
0258: ////////////////////////////////////////////////////////////////////////////
0259: /**
0260: * This method is added on QA engeneer request
0261: * to simplify automated test creation.
0262: */
0263: public DesignView getDesignView() {
0264: return myDesignView;
0265: }
0266:
0267: private GridBagConstraints createGBConstraints() {
0268: GridBagConstraints gc = new GridBagConstraints();
0269: gc.fill = java.awt.GridBagConstraints.BOTH;
0270: gc.insets = new java.awt.Insets(0, 0, 0, 0);
0271: gc.weightx = 1.0;
0272: gc.weighty = 1.0;
0273: gc.anchor = GridBagConstraints.NORTHWEST;
0274: return gc;
0275: }
0276:
0277: ////////////////////////////////////////////////////////////////////////////
0278: // MultiViewElement
0279: ////////////////////////////////////////////////////////////////////////////
0280:
0281: public int getPersistenceType() {
0282: return TopComponent.PERSISTENCE_NEVER;
0283: }
0284:
0285: public CloseOperationState canCloseElement() {
0286: //
0287: // actually if there are any visual changed NOT committed to the model
0288: // then we may need to flush something here or something
0289: //
0290: boolean lastView = isLastView();
0291:
0292: if (!lastView) {
0293: return CloseOperationState.STATE_OK;
0294: }
0295:
0296: BPELDataEditorSupport editorSupport = myDataObject
0297: .getEditorSupport();
0298: boolean modified = editorSupport.isModified();
0299:
0300: if (!modified) {
0301: return CloseOperationState.STATE_OK;
0302: } else {
0303: return MultiViewFactory.createUnsafeCloseState(
0304: "Data Object Modified", null, null); // NOI18N
0305: }
0306: }
0307:
0308: public void componentActivated() {
0309: // System.out.println("component activated");
0310: super .componentActivated();
0311: ExplorerUtils.activateActions(myExplorerManager, true);
0312: // not sure that we need to add undo manager each time when
0313: // component is activated, but calling method addUndoManager() more
0314: // than once is not a problem.
0315: // addUndoManager();
0316: myDesignView.getView().requestFocusInWindow();
0317: myDesignView.getModel().setActivated();
0318:
0319: // push NodeAction.Listener update context state
0320: Node[] aNodes = getActivatedNodes();
0321: setActivatedNodes(new Node[0]);
0322: setActivatedNodes(aNodes);
0323:
0324: getValidationController().triggerValidation(true);
0325: }
0326:
0327: public void componentClosed() {
0328: super .componentClosed();
0329:
0330: //required to release all references to OM
0331: // myDesignView.closeView();
0332: // myDesignView = null;
0333: // todo r | m
0334: cleanup();
0335: // DataObject dObj = getDataObject();
0336: // if (dObj.isValid()) {
0337: // setActivatedNodes(new Node[] {dObj.getNodeDelegate()});
0338: // }
0339: }
0340:
0341: public void componentDeactivated() {
0342: // System.out.println("component deactivated");
0343: super .componentDeactivated();
0344: ExplorerUtils.activateActions(myExplorerManager, false);
0345: }
0346:
0347: public void componentHidden() {
0348: super .componentHidden();
0349:
0350: //
0351: // memory conservation?
0352: //
0353:
0354: if (myDesignView != null) {
0355: myDesignView.setVisible(false);
0356: }
0357: //
0358: updateBpelTcGroupVisibility(false);
0359: // removeActiveNodeChangeListener();
0360: }
0361:
0362: public void componentOpened() {
0363: super .componentOpened();
0364: }
0365:
0366: public void componentShowing() {
0367: super .componentShowing();
0368: Node[] curNodes = getActivatedNodes();
0369: if (curNodes != null) {
0370: curNodes = curNodes.clone();
0371: }
0372:
0373: //
0374: // memory conservation?
0375: //
0376: if (myDesignView != null) {
0377: myDesignView.setVisible(true);
0378: }
0379: //// addUndoManager();
0380: //
0381: updateBpelTcGroupVisibility(true);
0382:
0383: // initActiveNodeChangeListener();
0384:
0385: // activate cur node
0386: // if (myMultiViewObserver != null) {
0387: // TopComponent thisTc = myMultiViewObserver.getTopComponent();
0388: // if ( thisTc != null ) {
0389: //
0390: // // data node is the node associated with dataobject(BPELDataObject)
0391: // if (curNodes == null || curNodes.length == 0 || curNodes[0] instanceof DataNode) {
0392: // Node node = myDesignView.getNodeForPattern(myDesignView.getRootPattern());
0393: //
0394: // if (node != null) {
0395: // curNodes = new Node[] { node };
0396: // }
0397: // }
0398: //
0399: // if (curNodes != null && curNodes.length > 0) {
0400: // thisTc.setActivatedNodes(new Node[0]);
0401: // setActivatedNodes(new Node[0]);
0402: //
0403: // thisTc.setActivatedNodes(curNodes);
0404: // setActivatedNodes(curNodes);
0405: // }
0406: // }
0407: // }
0408: }
0409:
0410: public JComponent getToolbarRepresentation() {
0411: if (myToolBarPanel == null) {
0412: JToolBar toolbar = new JToolBar();
0413: toolbar.setFloatable(false);
0414: toolbar.setFocusable(false);
0415: toolbar.addSeparator();
0416:
0417: toolbar.add(new PartnerLinkFilterButton(myDesignView));
0418: toolbar.add(Box.createHorizontalStrut(1));
0419: toolbar.add(new SequenceFilterButton(myDesignView));
0420: toolbar.addSeparator();
0421: //FIXME toolbar.add(myDesignView.createExpandAllPatternsToolBarButton());
0422: //toolbar.addSeparator();
0423:
0424: NavigationTools navigationTools = myDesignView
0425: .getNavigationTools();
0426: for (int i = 0; i < navigationTools.getControllersCount(); i++) {
0427: toolbar.add(navigationTools.getController(i));
0428: if (i + 1 < navigationTools.getControllersCount()) {
0429: toolbar.add(Box.createHorizontalStrut(1));
0430: }
0431: }
0432: toolbar.addSeparator();
0433:
0434: // vlv: report
0435: toolbar.add(new GenerateReportAction(myDataObject,
0436: new DocumentationCookie(myDataObject,
0437: getDesignView().getProcessView())));
0438: toolbar.add(new CustomizeReportAction(myDataObject));
0439: toolbar.addSeparator();
0440:
0441: // zoom
0442: ZoomManager zoomManager = myDesignView.getZoomManager();
0443:
0444: for (int i = 0; i < zoomManager.getComponentCount(); i++) {
0445: toolbar.add(zoomManager.getComponent(i));
0446:
0447: if (i + 1 < zoomManager.getComponentCount()) {
0448: toolbar.add(Box.createHorizontalStrut(1));
0449: }
0450: }
0451: // vlv: print
0452: toolbar.addSeparator();
0453: toolbar.add(PrintManager.getDefault()
0454: .getPrintPreviewAction());
0455:
0456: // vlv: search
0457: SearchManager manager = SearchManager.getDefault();
0458:
0459: if (manager != null) {
0460: toolbar.addSeparator();
0461: toolbar.add(manager.getSearchAction());
0462: }
0463: // vlv: valdiation
0464: toolbar.addSeparator();
0465: toolbar.add(new BPELValidateAction(myDesignView
0466: .getBPELModel()));
0467:
0468: // ksorokin: breakpoints
0469: toolbar.addSeparator();
0470: toolbar.add(new BreakpointsEnableAction(myDesignView));
0471: toolbar.add(new BreakpointsDisableAction(myDesignView));
0472: toolbar.add(new BreakpointsDeleteAction(myDesignView));
0473:
0474: int maxButtonHeight = 0;
0475:
0476: for (Component c : toolbar.getComponents()) {
0477: if (c instanceof JButton || c instanceof JToggleButton) {
0478: maxButtonHeight = Math.max(
0479: c.getPreferredSize().height,
0480: maxButtonHeight);
0481: }
0482: }
0483: for (Component c : toolbar.getComponents()) {
0484: if (c instanceof JButton || c instanceof JToggleButton) {
0485: Dimension size = c.getMaximumSize();
0486: size.height = maxButtonHeight;
0487: c.setMaximumSize(size);
0488: c.setMinimumSize(c.getPreferredSize());
0489: c.setFocusable(false);
0490: } else if ((c instanceof JTextComponent)
0491: || (c instanceof JComboBox)) {
0492: c.setMaximumSize(c.getPreferredSize());
0493: c.setMinimumSize(c.getPreferredSize());
0494: } else {
0495: c.setMinimumSize(c.getPreferredSize());
0496: c.setFocusable(false);
0497: }
0498: }
0499: myToolBarPanel = toolbar;
0500: }
0501: return myToolBarPanel;
0502: }
0503:
0504: public UndoRedo getUndoRedo() {
0505: return getDataObject().getEditorSupport().getUndoManager();
0506: }
0507:
0508: public JComponent getVisualRepresentation() {
0509: return this ;
0510: }
0511:
0512: public void setMultiViewCallback(MultiViewElementCallback callback) {
0513: myMultiViewObserver = callback;
0514: }
0515:
0516: public void requestVisible() {
0517: if (myMultiViewObserver != null) {
0518: myMultiViewObserver.requestVisible();
0519: } else {
0520: super .requestVisible();
0521: }
0522: }
0523:
0524: public void requestActive() {
0525: if (myMultiViewObserver != null) {
0526: myMultiViewObserver.requestActive();
0527: } else {
0528: super .requestActive();
0529: }
0530: }
0531:
0532: protected boolean closeLast() {
0533: return true;
0534: }
0535:
0536: private JButton createExpandAllPatternsToolBarButton() {
0537: //FIXME
0538: return null;
0539: // JButton button = new JButton(new ExpandAllPatternsAction(myDesignView));
0540: // button.setText(null);
0541: // button.setFocusable(false);
0542: // return button;
0543: }
0544:
0545: private DesignView createDesignView() {
0546: DesignView view = new DesignView(getLookup()); // got TC's lookup or no Palette
0547: return view;
0548: }
0549:
0550: private BPELValidationController getValidationController() {
0551: return (BPELValidationController) getDataObject().getLookup()
0552: .lookup(BPELValidationController.class);
0553: }
0554:
0555: private void initializeUI() {
0556: // TODO : add listener for replacing view in the case broken OM.
0557: //getBpelModel().addEntityChangeListener( new ProxyListener() );
0558:
0559: setLayout(new BorderLayout());
0560:
0561: myDesignView = createDesignView();
0562:
0563: //FIXME ThumbScrollPane scroll = new ThumbScrollPane(myDesignView.getView());
0564: // scroll.setBorder(null);
0565: // scroll.getVerticalScrollBar().setUnitIncrement(16);
0566: // scroll.getHorizontalScrollBar().setUnitIncrement(16);
0567: // add(scroll, BorderLayout.CENTER);
0568:
0569: add(myDesignView, BorderLayout.CENTER);
0570: // add copy, cut, paste actions into actionMap to be visible in external menus
0571: ActionMap map = getActionMap();
0572: ActionMap designViewMap = myDesignView.getActionMap();
0573: map.setParent(designViewMap);
0574:
0575: designViewMap.put(DefaultEditorKit.copyAction, designViewMap
0576: .get("copy-pattern"));
0577: designViewMap.put(DefaultEditorKit.cutAction, designViewMap
0578: .get("cut-pattern"));
0579: designViewMap.put(DefaultEditorKit.pasteAction, designViewMap
0580: .get("paste-pattern"));
0581: map.put("delete", designViewMap.get("delete-something"));
0582: add(myDesignView.getRightStripe(), BorderLayout.EAST);
0583:
0584: // vlv: find
0585: SearchManager manager = SearchManager.getDefault();
0586:
0587: if (manager != null) {
0588: myFind = manager.createFind(
0589: new DiagramImpl(getDesignView()), getDesignView());
0590: myFind.setVisible(false);
0591: add(myFind, BorderLayout.SOUTH);
0592: }
0593: initActiveNodeContext();
0594: setVisible(true);
0595:
0596: getAccessibleContext().setAccessibleName(
0597: NbBundle.getMessage(DesignerMultiViewElement.class,
0598: "ACSN_DesignerMultiviewElement", getName())); // NOI18N
0599: getAccessibleContext().setAccessibleDescription(
0600: NbBundle.getMessage(DesignerMultiViewElement.class,
0601: "ACSD_DesignerMultiviewElement", getName())); // NOI18N
0602: }
0603:
0604: private Component myFind;
0605:
0606: private void initActiveNodeContext() {
0607:
0608: Node[] aNodes = getActivatedNodes();
0609:
0610: // activate cur node
0611: // data node is the node associated with dataobject(BPELDataObject)
0612: if (aNodes == null || aNodes.length == 0
0613: || aNodes[0] instanceof DataNode) {
0614: Node node = null;
0615:
0616: node = node != null ? node
0617: : myDesignView != null ? myDesignView
0618: .getNodeForPattern(myDesignView
0619: .getRootPattern()) : null;
0620:
0621: if (node != null) {
0622: aNodes = new Node[] { node };
0623: }
0624: }
0625:
0626: if (aNodes != null && aNodes.length > 0) {
0627: setActivatedNodes(aNodes);
0628: }
0629: }
0630:
0631: /**
0632: * Open or close the bpel_designer TopComponentGroup.
0633: */
0634: private static void updateBpelTcGroupVisibility(final boolean show) {
0635: // when active TopComponent changes, check if we should open or close
0636: // the BPEL editor group of windows
0637: WindowManager wm = WindowManager.getDefault();
0638: final TopComponentGroup group = wm
0639: .findTopComponentGroup("bpel_designer"); // NOI18N
0640: if (group == null) {
0641: return; // group not found (should not happen)
0642: }
0643: //
0644: boolean designerSelected = false;
0645: Iterator it = wm.getModes().iterator();
0646: while (it.hasNext()) {
0647: Mode mode = (Mode) it.next();
0648: TopComponent selected = mode.getSelectedTopComponent();
0649: if (selected != null) {
0650: MultiViewHandler mvh = MultiViews
0651: .findMultiViewHandler(selected);
0652: if (mvh != null) {
0653: MultiViewPerspective mvp = mvh
0654: .getSelectedPerspective();
0655: if (mvp != null) {
0656: String id = mvp.preferredID();
0657: if (DesignerMultiViewElementDesc.PREFERRED_ID
0658: .equals(id)) {
0659: designerSelected = true;
0660: break;
0661: }
0662: }
0663: }
0664: }
0665: }
0666: //
0667: if (designerSelected && !Boolean.TRUE.equals(groupVisible)) {
0668: group.open();
0669: } else if (!designerSelected
0670: && !Boolean.FALSE.equals(groupVisible)) {
0671: group.close();
0672: }
0673: //
0674: groupVisible = designerSelected ? Boolean.TRUE : Boolean.FALSE;
0675: }
0676:
0677: public static String getMVEditorActivePanelPrefferedId() {
0678: TopComponent activeTC = WindowManager.getDefault()
0679: .getRegistry().getActivated();
0680: MultiViewHandler mvh = MultiViews
0681: .findMultiViewHandler(activeTC);
0682: if (mvh == null) {
0683: return null;
0684: }
0685:
0686: MultiViewPerspective mvp = mvh.getSelectedPerspective();
0687: if (mvp != null) {
0688: return mvp.preferredID();
0689: }
0690:
0691: return null;
0692: }
0693:
0694: private boolean isLastView() {
0695: boolean oneOrLess = true;
0696: Enumeration en = ((CloneableTopComponent) myMultiViewObserver
0697: .getTopComponent()).getReference().getComponents();
0698: if (en.hasMoreElements()) {
0699: en.nextElement();
0700: if (en.hasMoreElements()) {
0701: oneOrLess = false;
0702: }
0703: }
0704:
0705: return oneOrLess;
0706: }
0707:
0708: private BPELDataObject getDataObject() {
0709: return myDataObject;
0710: }
0711:
0712: private boolean isModelValid() {
0713: if (getDataObject().getEditorSupport().getBpelModel() != null) {
0714: State state = getDataObject().getEditorSupport()
0715: .getBpelModel().getState();
0716: return State.VALID.equals(state);
0717: } else {
0718: return false;
0719: }
0720: }
0721:
0722: private void initialize() {
0723: myExplorerManager = new ExplorerManager();
0724: // Install our own actions.
0725: ActionMap actionMap = getActionMap();
0726: // actionMap.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(myExplorerManager));
0727: // actionMap.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(myExplorerManager));
0728: // actionMap.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(myExplorerManager));
0729: // actionMap.put("delete", ExplorerUtils.actionDelete(manager, false));
0730:
0731: Node delegate = myDataObject.getNodeDelegate();
0732: myNodesMediator = new ActivatedNodesMediator(delegate);
0733: myNodesMediator.setExplorerManager(this );
0734:
0735: /**
0736: new ProxyLookup(new Lookup[] {
0737: //
0738: // other than nodesHack what else do we need in the associated
0739: // lookup? I think that XmlNavigator needs DataObject
0740: //
0741: myDataObject.getLookup(), // this lookup contain objects that are used in OM clients
0742:
0743: // This lookup is used by BPELDataEditorSupport
0744: // to obtain SelectBpelElement interface implementation
0745: Lookups.singleton(this),
0746:
0747: new AbstractLookup(nodesHack),
0748: Lookups.singleton(SoaPaletteFactory.getPalette())
0749: })
0750: */
0751:
0752: myCookieProxyLookup = new CookieProxyLookup(new Lookup[] {
0753: Lookups.fixed(new Object[] {
0754: // Need ActionMap in lookup so our actions are used.
0755: actionMap,
0756: // Need the data object registered in the lookup so that the
0757: // projectui code will close our open editor windows when the
0758: // project is closed.
0759: myDataObject, }),
0760: myDataObject.getLookup(),// this lookup contain objects that are used in OM clients
0761: Lookups.singleton(this ),
0762:
0763: Lookups.singleton(SoaPaletteFactory.getPalette()),
0764: myNodesMediator.getLookup(),
0765: // The Node delegate Lookup must be the last one in the list
0766: // for the CookieProxyLookup to work properly.
0767: delegate.getLookup(), }, delegate);
0768:
0769: associateLookup(myCookieProxyLookup);
0770: addPropertyChangeListener(ACTIVATED_NODES, myNodesMediator);
0771: addPropertyChangeListener(ACTIVATED_NODES, myCookieProxyLookup);
0772:
0773: setLayout(new BorderLayout());
0774: }
0775:
0776: private void cleanup() {
0777: try {
0778: myExplorerManager.setSelectedNodes(new Node[0]);
0779: } catch (PropertyVetoException e) {
0780: }
0781: removePropertyChangeListener(ACTIVATED_NODES, myNodesMediator);
0782: removePropertyChangeListener(ACTIVATED_NODES,
0783: myCookieProxyLookup);
0784: myNodesMediator = null;
0785: myCookieProxyLookup = null;
0786:
0787: //required to release all references to OM
0788: myDesignView.closeView();
0789: myDesignView = null;
0790:
0791: // # 127503
0792: if (myFind != null) {
0793: myFind.setEnabled(false);
0794: myFind = null;
0795: }
0796: removeAll();
0797: }
0798:
0799: // private void initializeLookup() {
0800: // associateLookup(createAssociateLookup());
0801: // initActiveNodeChangeListener();
0802: //// addPropertyChangeListener( new PropertyChangeListener() {
0803: //// /**
0804: //// * TODO: may not be needed at some point when parenting
0805: //// * MultiViewTopComponent delegates properly to its peer's
0806: //// * activatedNodes. see
0807: //// * http://www.netbeans.org/issues/show_bug.cgi?id=67257 note:
0808: //// * TopComponent.setActivatedNodes is final
0809: //// */
0810: //// public void propertyChange(PropertyChangeEvent event) {
0811: //// // no constant in TopComponent...lame
0812: //// if(event.getPropertyName().equals("activatedNodes")) {
0813: //// // if(DEBUG)
0814: //// // Debug.verboseWithin(this,"propertyChange",getDataObject());
0815: //// nodesHack.set(Arrays.asList(getActivatedNodes()),null);
0816: //// }
0817: //// };
0818: //// });
0819: ////
0820: //// setActivatedNodes(new Node[] {getDataObject().getNodeDelegate()});
0821: // }
0822:
0823: private Lookup createAssociateLookup() {
0824:
0825: //
0826: // see http://www.netbeans.org/issues/show_bug.cgi?id=67257
0827: //
0828: nodesHack = new InstanceContent();
0829: return new ProxyLookup(new Lookup[] {
0830: //
0831: // other than nodesHack what else do we need in the associated
0832: // lookup? I think that XmlNavigator needs DataObject
0833: //
0834: myDataObject.getLookup(), // this lookup contain objects that are used in OM clients
0835:
0836: // This lookup is used by BPELDataEditorSupport
0837: // to obtain SelectBpelElement interface implementation
0838: Lookups.singleton(this ),
0839:
0840: new AbstractLookup(nodesHack),
0841: Lookups.singleton(SoaPaletteFactory.getPalette()) });
0842: }
0843:
0844: public void select(BpelEntity bpelEntity) {
0845:
0846: // Bubble up because some elements may not have
0847: // a valid NodeType.
0848: while (BPELENTITY_NODETYPE_MAP.get(bpelEntity.getElementType()) == null) {
0849: bpelEntity = bpelEntity.getParent();
0850: }
0851:
0852: PropertyNodeFactory factory = PropertyNodeFactory.getInstance();
0853: Node node = factory.createNode(BPELENTITY_NODETYPE_MAP
0854: .get(bpelEntity.getElementType()), bpelEntity,
0855: getLookup());
0856:
0857: if (node != null) // double check.
0858: this .setActivatedNodes(new Node[] { node });
0859:
0860: requestVisible();
0861: }
0862:
0863: /**
0864: * Adds the undo/redo manager to the bpel model as an undoable
0865: * edit listener, so it receives the edits onto the queue.
0866: */
0867: private void addUndoManager() {
0868: BPELDataEditorSupport support = myDataObject.getEditorSupport();
0869: if (support != null) {
0870: QuietUndoManager undo = support.getUndoManager();
0871: support.addUndoManagerToModel(undo);
0872: }
0873: }
0874:
0875: private BpelModel getBpelModel() {
0876: return getDataObject().getEditorSupport().getBpelModel();
0877: }
0878:
0879: /*
0880: 1) Get a element from bpel.api package
0881: 2) If it does not implement BpelEntity ignore.
0882: 3) Check if there is matching NodeType. [Otherwise the bubbling up will eventually lead to a BpelEntity]
0883: 4) If yes then make an entry into the map.
0884:
0885: No entry in map as no matching NodeType:
0886: [Activity, ActivityHolder, AssignChild, BaseCorrelation, BaseFaultHandlers,
0887: BaseScope, BooleanExpr, BpelContainer, Branches,
0888: CompensateScope, CompensationHandlerHolder, CompletionCondition, CompositeActivity,
0889: Condition, ConditionHolder, CorrelationsHolder, DeadlineExpression, Documentation,
0890: DurationExpression, Expression, ExtendableActivity, ExtensibleAssign, ExtensibleElements,
0891: Extension, ExtensionActivity, ExtensionContainer, ExtensionEntity, FinalCounterValue,
0892: For, From, FromPartContainer, Link*, LinkContainer, Literal, MessageExchangeContainer,
0893: NamedElement, OnAlarmEvent, OnAlarmPick, OnMessage, OnMessageCommon, PartnerLinkContainer,
0894: PatternedCorrelationContainer, RepeatEvery, ReThrow, ServiceRef, Source,
0895: SourceContainer, StartCounterValue, Target, TargetContainer, TimeEvent, TimeEventHolder,
0896: To, Validate, VariableDeclaration,
0897:
0898:
0899:
0900: These have an entry in the map:
0901: [Assign, Catch, CatchAll, Compensate, CompensatableActivityHolder, CompensationHandler, Copy,
0902: Correlation, CorrelationContainer,
0903: CorrelationSet, CorrelationSet, Else, ElseIf, Empty, EventHandlers, Exit, FaultHandlers, Flow,
0904: ForEach, FromPart, If, Import, Invoke, MessageExchange, OnEvent, PartnerLink, PatternedCorrelation,
0905: Pick, Process,
0906: Receive, RepeatUntil, Reply, Scope, Sequence, TerminationHandler, Throw, ToPart, Variable,
0907: VariableContainer, VariableDeclarationScope, Wait, While]
0908:
0909: */
0910: protected static Map<Class<? extends BpelEntity>, NodeType> BPELENTITY_NODETYPE_MAP;
0911: static {
0912: BPELENTITY_NODETYPE_MAP = new HashMap<Class<? extends BpelEntity>, NodeType>();
0913: BPELENTITY_NODETYPE_MAP.put(Assign.class, NodeType.ASSIGN);
0914: BPELENTITY_NODETYPE_MAP.put(Catch.class, NodeType.CATCH);
0915: BPELENTITY_NODETYPE_MAP.put(CatchAll.class, NodeType.CATCH_ALL);
0916: BPELENTITY_NODETYPE_MAP.put(CompensatableActivityHolder.class,
0917: NodeType.CATCH_ALL);
0918: BPELENTITY_NODETYPE_MAP.put(Compensate.class,
0919: NodeType.COMPENSATE);
0920: BPELENTITY_NODETYPE_MAP.put(CompensateScope.class,
0921: NodeType.COMPENSATE_SCOPE);
0922: BPELENTITY_NODETYPE_MAP.put(CompensationHandler.class,
0923: NodeType.COMPENSATION_HANDLER);
0924: BPELENTITY_NODETYPE_MAP.put(Copy.class, NodeType.COPY);
0925: BPELENTITY_NODETYPE_MAP.put(Correlation.class,
0926: NodeType.CORRELATION);
0927: BPELENTITY_NODETYPE_MAP.put(CorrelationSet.class,
0928: NodeType.CORRELATION_SET);
0929: BPELENTITY_NODETYPE_MAP.put(Else.class, NodeType.ELSE);
0930: BPELENTITY_NODETYPE_MAP.put(ElseIf.class, NodeType.ELSE_IF);
0931: BPELENTITY_NODETYPE_MAP.put(Empty.class, NodeType.EMPTY);
0932: BPELENTITY_NODETYPE_MAP.put(EventHandlers.class,
0933: NodeType.EVENT_HANDLERS);
0934: BPELENTITY_NODETYPE_MAP.put(Exit.class, NodeType.EXIT);
0935: BPELENTITY_NODETYPE_MAP.put(FaultHandlers.class,
0936: NodeType.FAULT_HANDLERS);
0937: BPELENTITY_NODETYPE_MAP.put(Flow.class, NodeType.FLOW);
0938: BPELENTITY_NODETYPE_MAP.put(ForEach.class, NodeType.FOR_EACH);
0939: BPELENTITY_NODETYPE_MAP.put(FromPart.class, NodeType.FROM_PART);
0940: BPELENTITY_NODETYPE_MAP.put(If.class, NodeType.IF);
0941: BPELENTITY_NODETYPE_MAP.put(Import.class, NodeType.IMPORT);
0942: BPELENTITY_NODETYPE_MAP.put(Invoke.class, NodeType.INVOKE);
0943: BPELENTITY_NODETYPE_MAP.put(MessageExchange.class,
0944: NodeType.MESSAGE_EXCHANGE);
0945: BPELENTITY_NODETYPE_MAP.put(OnAlarmEvent.class,
0946: NodeType.ALARM_HANDLER);
0947: BPELENTITY_NODETYPE_MAP.put(OnAlarmPick.class,
0948: NodeType.ALARM_HANDLER);
0949: BPELENTITY_NODETYPE_MAP.put(OnEvent.class, NodeType.ON_EVENT);
0950: BPELENTITY_NODETYPE_MAP.put(OnMessage.class,
0951: NodeType.MESSAGE_HANDLER);
0952: BPELENTITY_NODETYPE_MAP.put(PartnerLink.class,
0953: NodeType.PARTNER_LINK);
0954: BPELENTITY_NODETYPE_MAP.put(PatternedCorrelation.class,
0955: NodeType.CORRELATION_P);
0956: BPELENTITY_NODETYPE_MAP.put(Pick.class, NodeType.PICK);
0957: BPELENTITY_NODETYPE_MAP.put(Process.class, NodeType.PROCESS);
0958: BPELENTITY_NODETYPE_MAP.put(Receive.class, NodeType.RECEIVE);
0959: BPELENTITY_NODETYPE_MAP.put(RepeatUntil.class,
0960: NodeType.REPEAT_UNTIL);
0961: BPELENTITY_NODETYPE_MAP.put(Reply.class, NodeType.REPLY);
0962: BPELENTITY_NODETYPE_MAP.put(Scope.class, NodeType.SCOPE);
0963: BPELENTITY_NODETYPE_MAP.put(Sequence.class, NodeType.SEQUENCE);
0964: BPELENTITY_NODETYPE_MAP.put(TerminationHandler.class,
0965: NodeType.TERMINATION_HANDLER);
0966: BPELENTITY_NODETYPE_MAP.put(Throw.class, NodeType.THROW);
0967: BPELENTITY_NODETYPE_MAP.put(ToPart.class, NodeType.TO_PART);
0968: BPELENTITY_NODETYPE_MAP.put(Variable.class, NodeType.VARIABLE);
0969: BPELENTITY_NODETYPE_MAP.put(VariableContainer.class,
0970: NodeType.VARIABLE_CONTAINER);
0971: BPELENTITY_NODETYPE_MAP.put(VariableDeclarationScope.class,
0972: NodeType.VARIABLE_SCOPE);
0973: BPELENTITY_NODETYPE_MAP.put(Wait.class, NodeType.WAIT);
0974: BPELENTITY_NODETYPE_MAP.put(While.class, NodeType.WHILE);
0975: }
0976:
0977: /*
0978: * This class could be used for changing diagram with error message
0979: * in the case when model is broken.
0980: */
0981: private class ProxyListener extends ChangeEventListenerAdapter {
0982:
0983: /* (non-Javadoc)
0984: * @see org.netbeans.modules.bpel.model.api.events.ChangeEventListenerAdapter#notifyPropertyUpdated(org.netbeans.modules.bpel.model.api.events.PropertyUpdateEvent)
0985: */
0986: @Override
0987: public void notifyPropertyUpdated(PropertyUpdateEvent event) {
0988: if (BpelModel.STATE.equals(event.getName())
0989: && Model.State.NOT_WELL_FORMED.equals(event
0990: .getNewValue())) {
0991: setActivatedNodes(new Node[] { getDataObject()
0992: .getNodeDelegate() });
0993: }
0994: }
0995:
0996: }
0997:
0998: /**
0999: * Override the ValidateAction so that complete validation results
1000: * can be sent to the BPELValidationController.
1001: */
1002: private class BPELValidateAction extends ValidateAction {
1003:
1004: public BPELValidateAction(BpelModel model) {
1005: super (model);
1006: }
1007:
1008: public void actionPerformed(ActionEvent event) {
1009: RequestProcessor.getDefault().post(new Runnable() {
1010: public void run() {
1011: RunAction runAction = new RunAction();
1012: runAction.run();
1013:
1014: List<ResultItem> validationResults = runAction
1015: .getValidationResults();
1016: BPELValidationController controller = (BPELValidationController) ((BPELDataObject) getDataObject())
1017: .getLookup().lookup(
1018: BPELValidationController.class);
1019:
1020: // Send the complete validation results to the validation controller
1021: // so that clients can be notified.
1022: if (controller != null) {
1023: controller
1024: .notifyCompleteValidationResults(validationResults);
1025: }
1026: }
1027: });
1028: }
1029: }
1030:
1031: public ExplorerManager getExplorerManager() {
1032: return myExplorerManager;
1033: }
1034:
1035: private static final String ACTIVATED_NODES = "activatedNodes";
1036: private transient MultiViewElementCallback myMultiViewObserver;
1037: private transient DesignView myDesignView;
1038: private transient UndoRedo.Manager myUndoManager;
1039: private transient InstanceContent nodesHack;
1040: private BPELDataObject myDataObject;
1041: private transient JComponent myToolBarPanel;
1042: private static Boolean groupVisible = null;
1043:
1044: private PropertyChangeListener myActiveNodeChangeListener;
1045: private ExplorerManager myExplorerManager;
1046: private ActivatedNodesMediator myNodesMediator;
1047: private CookieProxyLookup myCookieProxyLookup;
1048:
1049: // private class ProxyActionMap extends ActionMap {
1050: // private ActionMap originalActionMap;
1051: //
1052: // public ProxyActionMap(ActionMap originalActionMap) {
1053: // this.originalActionMap = originalActionMap;
1054: // }
1055: //
1056: //
1057: // public void remove(Object key) {
1058: // originalActionMap.remove(key);
1059: // }
1060: //
1061: // public Action get(Object key) {
1062: // return originalActionMap.get();
1063: // Action retValue;
1064: //
1065: // retValue = super.get(key);
1066: // return retValue;
1067: // }
1068: //
1069: // public void put(Object key, Action action) {
1070: // super.put(key, action);
1071: // }
1072: //
1073: // public void setParent(ActionMap map) {
1074: // super.setParent(map);
1075: // }
1076: //
1077: // public int size() {
1078: // int retValue;
1079: //
1080: // retValue = super.size();
1081: // return retValue;
1082: // }
1083: //
1084: // public Object[] keys() {
1085: // Object[] retValue;
1086: //
1087: // retValue = super.keys();
1088: // return retValue;
1089: // }
1090: //
1091: // public ActionMap getParent() {
1092: // ActionMap retValue;
1093: //
1094: // retValue = super.getParent();
1095: // return retValue;
1096: // }
1097: //
1098: // public void clear() {
1099: // super.clear();
1100: // }
1101: //
1102: // public Object[] allKeys() {
1103: // Object[] retValue;
1104: //
1105: // retValue = super.allKeys();
1106: // return retValue;
1107: // }
1108: //
1109: // }
1110:
1111: // private class ProxyInputMap extends InputMap {
1112: // private InputMap originalInputMap;
1113: //
1114: // public ProxyInputMap(InputMap originalInputMap) {
1115: // this.originalInputMap = originalInputMap;
1116: // }
1117: //
1118: //
1119: // public void setParent(InputMap map) {
1120: //
1121: // originalInputMap.setParent(map);
1122: // }
1123: //
1124: //
1125: // public void put(KeyStroke keyStroke, Object actionMapKey) {
1126: // originalInputMap.put(keyStroke, actionMapKey);
1127: // }
1128: //
1129: //
1130: // public void remove(KeyStroke key) {
1131: // originalInputMap.remove(key);
1132: // }
1133: //
1134: //
1135: // public Object get(KeyStroke keyStroke) {
1136: // return originalInputMap.get(keyStroke);
1137: // }
1138: //
1139: //
1140: // public int size() {
1141: // return originalInputMap.size();
1142: // }
1143: //
1144: //
1145: // public void clear() {
1146: // super.clear();
1147: // }
1148: //
1149: //
1150: // public KeyStroke[] keys() {
1151: // return originalInputMap.keys();
1152: // }
1153: //
1154: //
1155: // public InputMap getParent() {
1156: // InputMap retValue;
1157: //
1158: // retValue = super.getParent();
1159: // return retValue;
1160: // }
1161: //
1162: //
1163: // public KeyStroke[] allKeys() {
1164: // KeyStroke[] retValue;
1165: //
1166: // retValue = super.allKeys();
1167: // return retValue;
1168: // }
1169: //
1170: // }
1171: }
|