use of com.archimatetool.editor.model.commands.FeatureCommand in project archi by archimatetool.
the class FormatPainterTool method createCommand.
protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
// IFontAttribute
if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
IFontAttribute target = (IFontAttribute) targetComponent;
Command cmd = new FontStyleCommand(target, source.getFont());
if (cmd.canExecute()) {
result.add(cmd);
}
cmd = new FontColorCommand(target, source.getFontColor());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ILineObject
if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
ILineObject source = (ILineObject) pf.getSourceComponent();
ILineObject target = (ILineObject) targetComponent;
Command cmd = new LineColorCommand(target, source.getLineColor());
if (cmd.canExecute()) {
result.add(cmd);
}
cmd = new LineWidthCommand(target, source.getLineWidth());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IBorderObject
if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
IBorderObject source = (IBorderObject) pf.getSourceComponent();
IBorderObject target = (IBorderObject) targetComponent;
Command cmd = new BorderColorCommand(target, source.getBorderColor());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ITextPosition
if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
ITextPosition source = (ITextPosition) pf.getSourceComponent();
ITextPosition target = (ITextPosition) targetComponent;
Command cmd = new TextPositionCommand(target, source.getTextPosition());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// ITextAlignment
if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
ITextAlignment target = (ITextAlignment) targetComponent;
Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IDiagramModelObject
if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
IDiagramModelObject target = (IDiagramModelObject) targetComponent;
// Source fill colour is null which is "default"
String fillColorString = source.getFillColor();
if (fillColorString == null) {
fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
}
Command cmd = new FillColorCommand(target, fillColorString);
if (cmd.canExecute()) {
result.add(cmd);
}
// Alpha fill opacity
cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
if (cmd.canExecute()) {
result.add(cmd);
}
// Alpha line opacity
cmd = new DiagramModelObjectOutlineAlphaCommand(target, source.getLineAlpha());
if (cmd.canExecute()) {
result.add(cmd);
}
// Gradient
// $NON-NLS-1$
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
// Icon Visibility, but paste only if the target object has an icon
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(target);
if (provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider) provider).hasIcon()) {
// $NON-NLS-1$
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_ICON_VISIBLE, source.getIconVisibleState(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
// Archimate objects
if (pf.getSourceComponent() instanceof IDiagramModelArchimateObject && targetComponent instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject source = (IDiagramModelArchimateObject) pf.getSourceComponent();
IDiagramModelArchimateObject target = (IDiagramModelArchimateObject) targetComponent;
// Image Source
Command cmd = new // $NON-NLS-1$
FeatureCommand(// $NON-NLS-1$
"", // $NON-NLS-1$
target, // $NON-NLS-1$
IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, source.getImageSource(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
// IDiagramModelConnection
if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
// Connection text position
Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
if (cmd.canExecute()) {
result.add(cmd);
}
// If a non-Archimate connection, connection line type
if (!(target instanceof IDiagramModelArchimateConnection)) {
cmd = new ConnectionLineTypeCommand(target, source.getType());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
// IIconic
if (pf.getSourceComponent() instanceof IIconic && targetComponent instanceof IIconic) {
IIconic source = (IIconic) pf.getSourceComponent();
IIconic target = (IIconic) targetComponent;
// If we have an image path and the source and target models are different, copy the image bytes
String imagePath = source.getImagePath();
if (imagePath != null && source.getArchimateModel() != target.getArchimateModel()) {
IArchiveManager sourceArchiveManager = (IArchiveManager) source.getAdapter(IArchiveManager.class);
IArchiveManager targetArchiveManager = (IArchiveManager) target.getAdapter(IArchiveManager.class);
try {
imagePath = targetArchiveManager.copyImageBytes(sourceArchiveManager, imagePath);
} catch (IOException ex) {
ex.printStackTrace();
// $NON-NLS-1$
Logger.logError("Could not copy image bytes when copying and pasting objects.", ex);
}
}
// $NON-NLS-1$
Command cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, imagePath);
if (cmd.canExecute()) {
result.add(cmd);
}
// Image position
// $NON-NLS-1$
cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, source.getImagePosition());
if (cmd.canExecute()) {
result.add(cmd);
}
}
return result;
}
use of com.archimatetool.editor.model.commands.FeatureCommand in project archi by archimatetool.
the class IconVisibleSection method createControls.
@Override
protected void createControls(Composite parent) {
// $NON-NLS-1$
createLabel(parent, Messages.IconVisibleSection_0 + ":", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fIconVisibleCombo = new Combo(parent, SWT.READ_ONLY);
getWidgetFactory().adapt(fIconVisibleCombo, true, true);
fIconVisibleCombo.setItems(VISIBLE_CHOICES);
fIconVisibleCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject selected : getEObjects()) {
if (isAlive(selected)) {
Command cmd = new FeatureCommand(Messages.IconVisibleSection_0, (IFeatures) selected, IDiagramModelObject.FEATURE_ICON_VISIBLE, mapFromComboToValue(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of com.archimatetool.editor.model.commands.FeatureCommand in project archi by archimatetool.
the class ImageSourceSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.ImageSourceSection_3, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fImageSourceCombo = new Combo(parent, SWT.READ_ONLY);
getWidgetFactory().adapt(fImageSourceCombo, true, true);
fImageSourceCombo.setItems(IMAGE_SOURCE_CHOICES);
fImageSourceCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject selected : getEObjects()) {
if (isAlive(selected)) {
Command cmd = new FeatureCommand(Messages.ImageSourceSection_2, (IFeatures) selected, IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, mapFromComboToValue(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of com.archimatetool.editor.model.commands.FeatureCommand in project archi by archimatetool.
the class JunctionConnectionArrowsSection method createHideArrowsControl.
private void createHideArrowsControl(Composite parent) {
// $NON-NLS-1$
createLabel(parent, Messages.JunctionConnectionArrowsSection_0 + ":", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
buttonHideArrowHeads = getWidgetFactory().createButton(parent, null, SWT.CHECK);
buttonHideArrowHeads.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject junctionObject : getEObjects()) {
if (isAlive(junctionObject)) {
Command cmd = new FeatureCommand(Messages.JunctionConnectionArrowsSection_1, (IFeatures) junctionObject, IDiagramModelArchimateObject.FEATURE_HIDE_JUNCTION_ARROWS, buttonHideArrowHeads.getSelection(), IDiagramModelArchimateObject.FEATURE_HIDE_JUNCTION_ARROWS_DEFAULT);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
}
use of com.archimatetool.editor.model.commands.FeatureCommand in project archi by archimatetool.
the class LabelRendererSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.LabelRendererSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
styledTextControl.setMessage(Messages.LabelRendererSection_1);
fTextRender = new PropertySectionTextControl(styledTextControl.getControl(), TextRenderer.FEATURE_NAME) {
@Override
protected void textChanged(String oldText, String newText) {
CompoundCommand result = new CompoundCommand();
for (EObject eObject : getEObjects()) {
if (isAlive(eObject)) {
// $NON-NLS-1$
Command cmd = new FeatureCommand(Messages.LabelRendererSection_2, (IFeatures) eObject, TextRenderer.FEATURE_NAME, newText, "");
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
};
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Aggregations