use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class SpecializationSection method createControls.
@Override
protected void createControls(Composite parent) {
NONE_PROFILE = IArchimateFactory.eINSTANCE.createProfile();
NONE_PROFILE.setName(Messages.SpecializationSection_0);
createLabel(parent, Messages.SpecializationSection_1, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
Composite comp = createComposite(parent, 2);
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fComboViewer = new ComboViewer(new Combo(comp, SWT.READ_ONLY | SWT.BORDER));
fComboViewer.getCombo().setVisibleItemCount(12);
fComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
getWidgetFactory().adapt(fComboViewer.getControl(), true, true);
fComboViewer.addSelectionChangedListener(event -> {
if (fIsRefreshing) {
// A Viewer will get a selectionChanged event when setting it
return;
}
IProfile profile = (IProfile) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (profile != null) {
// None Profile is null
if (profile == NONE_PROFILE) {
profile = null;
}
CompoundCommand result = new CompoundCommand();
for (EObject object : getEObjects()) {
if (isAlive(object)) {
Command cmd = new SetProfileCommand((IArchimateConcept) object, profile);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
fComboViewer.setContentProvider(new IStructuredContentProvider() {
/**
* Return a list of suitable Profiles in the model given the concept type of the first selected object
*/
@Override
public Object[] getElements(Object inputElement) {
IArchimateConcept firstSelected = (IArchimateConcept) getFirstSelectedObject();
if (firstSelected == null) {
return new Object[0];
}
List<IProfile> list = ArchimateModelUtils.findProfilesForConceptType(firstSelected.getArchimateModel(), firstSelected.eClass());
// Sort the Profiles by name
Collections.sort(list, new Comparator<IProfile>() {
@Override
public int compare(IProfile p1, IProfile p2) {
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
// Add the "none" Profile at the top
list.add(0, NONE_PROFILE);
return list.toArray();
}
});
fComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((IProfile) element).getName();
}
});
// $NON-NLS-1$
fComboViewer.setInput("");
// Open Profiles Manager Dialog button
Button button = getWidgetFactory().createButton(comp, null, SWT.PUSH);
// $NON-NLS-1$
button.setText(" ... ");
button.setToolTipText(Messages.SpecializationSection_2);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IArchimateModelObject selected = getFirstSelectedObject();
if (selected != null && selected.getArchimateModel() != null) {
ProfilesManagerDialog dialog = new ProfilesManagerDialog(getPart().getSite().getShell(), selected.getArchimateModel());
dialog.setDefaultClass(selected.eClass());
dialog.open();
}
}
});
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class TextContentSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.TextContentSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
styledTextControl.setMessage(Messages.TextContentSection_2);
fTextContentControl = new PropertySectionTextControl(styledTextControl.getControl(), IArchimatePackage.Literals.TEXT_CONTENT__CONTENT) {
@Override
protected void textChanged(String oldText, String newText) {
CompoundCommand result = new CompoundCommand();
for (EObject textContent : getEObjects()) {
if (isAlive(textContent)) {
Command cmd = new EObjectFeatureCommand(Messages.TextContentSection_1, textContent, IArchimatePackage.Literals.TEXT_CONTENT__CONTENT, newText);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
};
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextContentControl.getTextControl(), HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class IconSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.IconSection_9, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
fCanvas = new Canvas(parent, SWT.BORDER);
getWidgetFactory().adapt(fCanvas);
GridData gd = new GridData(SWT.NONE, SWT.NONE, false, false);
gd.widthHint = IMAGE_SIZE;
gd.heightHint = IMAGE_SIZE;
fCanvas.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
fCanvas.setLayout(layout);
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
disposeImage();
}
});
fCanvas.addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
if (fImageButton.isEnabled()) {
chooseImage();
}
}
});
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (fImage != null) {
e.gc.setAntialias(SWT.ON);
e.gc.setInterpolation(SWT.HIGH);
Rectangle imageBounds = fImage.getBounds();
Rectangle newSize = ImageFactory.getScaledImageSize(fImage, IMAGE_SIZE);
// Centre the image
int x = (IMAGE_SIZE - newSize.width) / 2;
int y = (IMAGE_SIZE - newSize.height) / 2;
e.gc.drawImage(fImage, 0, 0, imageBounds.width, imageBounds.height, x, y, newSize.width, newSize.height);
}
}
});
String tooltip = Messages.IconSection_10;
fCanvas.setToolTipText(tooltip);
DropTarget target = new DropTarget(fCanvas, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
target.setTransfer(new Transfer[] { FileTransfer.getInstance() });
target.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
if (event.data instanceof String[] && fImageButton.isEnabled()) {
File file = new File(((String[]) event.data)[0]);
setImage(file);
}
}
});
// Image Button
createImageButton(parent);
// Position
createLabel(parent, Messages.IconSection_11, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fComboPosition = new Combo(parent, SWT.READ_ONLY);
fComboPosition.setItems(fComboPositionItems);
getWidgetFactory().adapt(fComboPosition, true, true);
gd = new GridData(SWT.NONE, SWT.NONE, false, false);
fComboPosition.setLayoutData(gd);
fComboPosition.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject iconic : getEObjects()) {
if (isAlive(iconic)) {
Command cmd = new EObjectFeatureCommand(Messages.IconSection_12, iconic, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, fComboPosition.getSelectionIndex());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class JunctionTypeSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.JunctionTypeSection_2, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
fComboType = new Combo(parent, SWT.READ_ONLY);
fComboType.setItems(fComboTypeItems);
fComboType.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
getWidgetFactory().adapt(fComboType, true, true);
fComboType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject junction : getEObjects()) {
if (isAlive(junction)) {
Command cmd = new EObjectFeatureCommand(Messages.JunctionTypeSection_3, junction, IArchimatePackage.Literals.JUNCTION__TYPE, fTypeValues[fComboType.getSelectionIndex()]);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class BorderTypeSection method createControls.
@Override
protected void createControls(Composite parent) {
createLabel(parent, Messages.BorderTypeSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
// Combo
fComboBorderType = new Combo(parent, SWT.READ_ONLY);
getWidgetFactory().adapt(fComboBorderType, true, true);
fComboBorderType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();
for (EObject eObject : getEObjects()) {
if (isAlive(eObject)) {
Command cmd = new EObjectFeatureCommand(Messages.BorderTypeSection_1, eObject, IArchimatePackage.Literals.BORDER_TYPE__BORDER_TYPE, fComboBorderType.getSelectionIndex());
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Aggregations