/******************************************************************************* | |
* <copyright> | |
* | |
* Copyright (c) 2013, 2013 SAP AG. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* SAP AG - initial API, implementation and documentation | |
* | |
* </copyright> | |
* | |
*******************************************************************************/ | |
package org.eclipse.fmc.blockdiagram.editor.meta.features.add; | |
import org.eclipse.fmc.blockdiagram.editor.meta.BlockDiagramMetaFeatureProvider; | |
import org.eclipse.fmc.blockdiagram.editor.meta.util.AddConnectionHelper; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IAddContext; | |
import org.eclipse.graphiti.features.context.IContext; | |
import org.eclipse.graphiti.mm.pictograms.PictogramElement; | |
import org.eclipse.fmc.blockdiagram.editor.features.add.HumanAgentAddFeature; | |
import org.eclipse.fmc.blockdiagram.editor.model.ShapeStyle; | |
public class HumanAgentAddMetaFeature extends HumanAgentAddFeature { | |
/** | |
* Object for creating all connections which are existing in the meta model. | |
*/ | |
AddConnectionHelper connHelper = null; | |
/** | |
* Constructor just calls the super constructor. | |
* | |
* @param fp | |
*/ | |
public HumanAgentAddMetaFeature(IFeatureProvider fp) { | |
super(fp); | |
} | |
/** | |
* Constructor just calls the super constructor. | |
* | |
* @param fp | |
* @param text | |
* @param width | |
* @param height | |
* @param angle | |
*/ | |
public HumanAgentAddMetaFeature(IFeatureProvider fp, String text, | |
int width, int height, int angle) { | |
super(fp, text, width, height, angle); | |
} | |
/** | |
* Constructor just calls the super constructor. | |
* | |
* @param fp | |
* @param style | |
*/ | |
public HumanAgentAddMetaFeature(IFeatureProvider fp, ShapeStyle style) { | |
super(fp, style); | |
} | |
/** | |
* Call the AddConnectionHelper for creating all connections which are | |
* existing in the meta model and draw the right multiplicity. | |
*/ | |
@Override | |
public PictogramElement add(IAddContext context) { | |
PictogramElement picEl = super.add(context); | |
// When the Model has connections and channels to Elements in the | |
// current Diagram we must add them. | |
connHelper = new AddConnectionHelper(); | |
connHelper.addAgentConnections(picEl, | |
(BlockDiagramMetaFeatureProvider) this.getFeatureProvider(), | |
getDiagram()); | |
return picEl; | |
} | |
/** | |
* Decides if the feature of the connection helper or the current feature | |
* (if the feature of the connection helper is null) is available with the | |
* given context. | |
*/ | |
@Override | |
public boolean isAvailable(IContext context) { | |
if (connHelper == null) | |
return super.isAvailable(context); | |
if (!connHelper.isAvailable(context)) | |
return false; | |
return super.isAvailable(context); | |
} | |
/** | |
* Decides if the feature of the connection helper or the current feature | |
* (if the feature of the connection helper is null) is available with the | |
* given context. | |
*/ | |
@Override | |
public boolean canExecute(IContext context) { | |
if (connHelper == null) | |
return super.canExecute(context); | |
if (!connHelper.canExecute(context)) | |
return false; | |
return super.canExecute(context); | |
} | |
/** | |
* Executes the current feature and the builded feature of the connection | |
* helper with the given context. | |
*/ | |
@Override | |
public void execute(IContext context) { | |
super.execute(context); | |
if (connHelper != null) | |
connHelper.execute(context); | |
} | |
/** | |
* Decides if the feature of the connection helper or the current feature | |
* (if the feature of the connection helper is null) can be undone - this is | |
* the undo of the execute operation. | |
*/ | |
@Override | |
public boolean canUndo(IContext context) { | |
if (connHelper == null) | |
return super.canUndo(context); | |
if (!connHelper.canUndo(context)) | |
return false; | |
return super.canUndo(context); | |
} | |
/** | |
* Check if this feature or the connection helper feature has done changes. | |
*/ | |
@Override | |
public boolean hasDoneChanges() { | |
if (connHelper == null) | |
return super.hasDoneChanges(); | |
return (connHelper.hasDoneChanges() || super.hasDoneChanges()); | |
} | |
} |