001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.actions;
025:
026: import java.util.List;
027:
028: import org.eclipse.emf.transaction.RecordingCommand;
029: import org.eclipse.emf.transaction.TransactionalEditingDomain;
030: import org.eclipse.emf.transaction.util.TransactionUtil;
031: import org.eclipse.gef.EditPart;
032: import org.eclipse.gef.RequestConstants;
033: import org.eclipse.gef.commands.Command;
034: import org.eclipse.gef.commands.CompoundCommand;
035: import org.eclipse.gef.internal.GEFMessages;
036: import org.eclipse.gef.requests.GroupRequest;
037: import org.eclipse.gef.ui.actions.SelectionAction;
038: import org.eclipse.gmf.runtime.notation.View;
039: import org.eclipse.ui.IWorkbenchPart;
040:
041: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
042: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
043: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Comment;
044: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JDBC;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Parser;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Sequencer;
052: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
053: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Transformer;
054: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.XSLT;
055: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.CBREditPart;
056: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.CommentEditPart;
057: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.FTPEditPart;
058: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.FileEditPart;
059: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.HTTPEditPart;
060: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.IUpdatableEditPart;
061: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.JDBCEditPart;
062: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.JMSEditPart;
063: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.ParserEditPart;
064: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.ScriptEditPart;
065: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.SequencerEditPart;
066: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.TCPIPEditPart;
067: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.TransformerEditPart;
068: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.XSLTEditPart;
069: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.IConstants;
070:
071: /**
072: * An action to delete selected objects.
073: */
074: public class ModifyAction extends SelectionAction {
075:
076: public String ID = IConstants.MODIFY;
077:
078: public ModifyAction(IWorkbenchPart part) {
079: super (part);
080:
081: }
082:
083: public String getId() {
084: return ID;
085: }
086:
087: /**
088: * Returns <code>true</code> if the selected objects can
089: * be deleted. Returns <code>false</code> if there are
090: * no objects selected or the selected objects are not
091: * {@link EditPart}s.
092: * @return <code>true</code> if the command should be enabled
093: */
094: protected boolean calculateEnabled() {
095: Command cmd = createDeleteCommand(getSelectedObjects());
096: if (cmd == null)
097: return false;
098: return cmd.canExecute();
099: }
100:
101: /**
102: * Create a command to remove the selected objects.
103: * @param objects The objects to be deleted.
104: * @return The command to remove the selected objects.
105: */
106: public Command createDeleteCommand(List objects) {
107: if (objects.isEmpty()) {
108:
109: return null;
110: }
111: if (!(objects.get(0) instanceof EditPart)
112: || objects.size() != 1) {
113:
114: return null;
115: }
116:
117: GroupRequest deleteReq = new GroupRequest(
118: RequestConstants.REQ_DELETE);
119: deleteReq.setEditParts(objects);
120:
121: CompoundCommand compoundCmd = new CompoundCommand(
122: GEFMessages.DeleteAction_ActionDeleteCommandName);
123: for (int i = 0; i < objects.size(); i++) {
124: EditPart object = (EditPart) objects.get(i);
125: Command cmd = object.getCommand(deleteReq);
126: if (cmd != null)
127: compoundCmd.add(cmd);
128: }
129:
130: return compoundCmd;
131: }
132:
133: /**
134: * Initializes this action's text and images.
135: */
136: protected void init() {
137: super .init();
138: setText("Modify");
139:
140: setId(ID);
141:
142: setEnabled(true);
143: }
144:
145: /**
146: * Performs the jumping out for wizards.
147: */
148: public void run() {
149: List objects = getSelectedObjects();
150: EditPart object = (EditPart) objects.get(0);
151:
152: View view = (View) object.getModel();
153:
154: // the IUpdatableEditPart interface has the wizardOut method defined.
155: ((IUpdatableEditPart) object).wizardOut(view, false);
156:
157: }
158:
159: }
|