Search in sources :

Example 61 with CompoundCommand

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);
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SetProfileCommand(com.archimatetool.editor.model.commands.SetProfileCommand) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Comparator(java.util.Comparator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) SetProfileCommand(com.archimatetool.editor.model.commands.SetProfileCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) Button(org.eclipse.swt.widgets.Button) EObject(org.eclipse.emf.ecore.EObject) ProfilesManagerDialog(com.archimatetool.editor.tools.ProfilesManagerDialog) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IProfile(com.archimatetool.model.IProfile) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 62 with CompoundCommand

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);
}
Also used : StyledTextControl(com.archimatetool.editor.ui.components.StyledTextControl) Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 63 with CompoundCommand

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);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintListener(org.eclipse.swt.events.PaintListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Combo(org.eclipse.swt.widgets.Combo) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) File(java.io.File)

Example 64 with CompoundCommand

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);
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 65 with CompoundCommand

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);
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)193 Command (org.eclipse.gef.commands.Command)86 EObject (org.eclipse.emf.ecore.EObject)40 ArrayList (java.util.ArrayList)28 EditPart (org.eclipse.gef.EditPart)28 List (java.util.List)24 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)18 Point (org.eclipse.draw2d.geometry.Point)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 Combo (org.eclipse.swt.widgets.Combo)15 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14