Java tutorial
/* Copyright (C) 2007-20013 BlueXML - www.bluexml.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /******************************************************************************* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Boston, MA 02111. ******************************************************************************/ package com.bluexml.side.Workflow.modeler.diagram.edit; import org.apache.commons.lang.StringUtils; import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.RequestConstants; import org.eclipse.gef.commands.Command; import org.eclipse.jface.window.Window; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.topcased.modeler.ModelerEditPolicyConstants; import org.topcased.modeler.di.model.GraphNode; import org.topcased.modeler.edit.EMFGraphNodeEditPart; import org.topcased.modeler.edit.policies.LabelDirectEditPolicy; import org.topcased.modeler.edit.policies.ResizableEditPolicy; import org.topcased.modeler.edit.policies.RestoreEditPolicy; import org.topcased.modeler.internal.ModelerPlugin; import org.topcased.modeler.requests.RestoreConnectionsRequest; import org.topcased.modeler.utils.Utils; import com.bluexml.side.Workflow.modeler.diagram.WfEditPolicyConstants; import com.bluexml.side.Workflow.modeler.diagram.commands.ActionRestoreConnectionCommand; import com.bluexml.side.Workflow.modeler.diagram.commands.update.ActionUpdateCommand; import com.bluexml.side.Workflow.modeler.diagram.dialogs.ActionEditDialog; import com.bluexml.side.Workflow.modeler.diagram.figures.ActionFigure; import com.bluexml.side.Workflow.modeler.diagram.policies.actionsEdgeCreationEditPolicy; import com.bluexml.side.Workflow.modeler.diagram.preferences.WfDiagramPreferenceConstants; import com.bluexml.side.workflow.Action; /** * The Action object controller * * @generated */ public class ActionEditPart extends EMFGraphNodeEditPart { /** * Constructor * * @param obj * the graph node * @generated */ public ActionEditPart(GraphNode obj) { super(obj); } /** * Creates edit policies and associates these with roles * * @generated */ protected void createEditPolicies() { super.createEditPolicies(); installEditPolicy(WfEditPolicyConstants.ACTIONS_EDITPOLICY, new actionsEdgeCreationEditPolicy()); installEditPolicy(ModelerEditPolicyConstants.RESTORE_EDITPOLICY, new RestoreEditPolicy() { protected Command getRestoreConnectionsCommand(RestoreConnectionsRequest request) { return new ActionRestoreConnectionCommand(getHost()); } }); installEditPolicy(ModelerEditPolicyConstants.RESIZABLE_EDITPOLICY, new ResizableEditPolicy()); installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy()); } /** * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() * @generated */ protected IFigure createFigure() { return new ActionFigure(); } /** * @see org.topcased.modeler.edit.GraphNodeEditPart#getPreferenceDefaultBackgroundColor() * @generated */ protected Color getPreferenceDefaultBackgroundColor() { String backgroundColor = getPreferenceStore() .getString(WfDiagramPreferenceConstants.ACTION_DEFAULT_BACKGROUND_COLOR); if (backgroundColor.length() != 0) { return Utils.getColor(backgroundColor); } return null; } /** * @see org.topcased.modeler.edit.GraphNodeEditPart#getPreferenceDefaultForegroundColor() * @generated */ protected Color getPreferenceDefaultForegroundColor() { String foregroundColor = getPreferenceStore() .getString(WfDiagramPreferenceConstants.ACTION_DEFAULT_FOREGROUND_COLOR); if (foregroundColor.length() != 0) { return Utils.getColor(foregroundColor); } return null; } /** * @see org.topcased.modeler.edit.GraphNodeEditPart#getPreferenceDefaultFont() * @generated */ protected Font getPreferenceDefaultFont() { String preferenceFont = getPreferenceStore().getString(WfDiagramPreferenceConstants.ACTION_DEFAULT_FONT); if (preferenceFont.length() != 0) { return Utils.getFont(new FontData(preferenceFont)); } return null; } @Override public void performRequest(Request request) { if (request.getType() == RequestConstants.REQ_OPEN) { Action action = (Action) Utils.getElement(getGraphNode()); ActionEditDialog dlg = new ActionEditDialog(action, ModelerPlugin.getActiveWorkbenchShell()); if (dlg.open() == Window.OK) { ActionUpdateCommand command = new ActionUpdateCommand(action, dlg.getData()); getViewer().getEditDomain().getCommandStack().execute(command); refresh(); } } else { super.performRequest(request); } } @Override protected void refreshHeaderLabel() { Action action = (Action) Utils.getElement(getGraphNode()); if (StringUtils.trimToNull(action.getExpression()) != null) { getLabel().setText(action.getExpression()); } else if (action.getScript().size() > 0) { getLabel().setText(action.getScript().get(0).getExpression()); } else { super.refreshHeaderLabel(); } } }