Search in sources :

Example 51 with Command

use of org.eclipse.gef.commands.Command in project dbeaver by serge-rider.

the class ExtendedDirectEditManager method commit.

/**
	 * Commits the current value of the cell editor by getting a {@link Command}
	 * from the source edit part and executing it via the {@link CommandStack}.
	 * Finally, {@link #bringDown()}is called to perform and necessary cleanup.
	 */
@Override
protected void commit() {
    if (committing)
        return;
    committing = true;
    try {
        //we set the cell editor control to invisible to remove any
        // possible flicker
        getCellEditor().getControl().setVisible(false);
        if (isDirty()) {
            CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
            Command command = getEditPart().getCommand(getDirectEditRequest());
            if (command != null && command.canExecute())
                stack.execute(command);
        }
    } finally {
        bringDown();
        committing = false;
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Command(org.eclipse.gef.commands.Command)

Example 52 with Command

use of org.eclipse.gef.commands.Command in project cubrid-manager by CUBRID.

the class GefViewerKeyHandler method moveHANodesByKey.

/**
	 * move figures by keyboard.
	 * 
	 * @param event KeyEvent
	 * @return if handled the event return true else return false.
	 */
private boolean moveHANodesByKey(KeyEvent event) {
    List<?> selectedEditParts = getViewer().getSelectedEditParts();
    boolean flag = false;
    for (Object obj : selectedEditParts) {
        if (!(obj instanceof HANodePart)) {
            continue;
        }
        GraphicalEditPart editPart = (GraphicalEditPart) obj;
        Command command = null;
        if ((event.stateMask & SWT.ALT) == 0 && (event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT || event.keyCode == SWT.ARROW_UP)) {
            HANode node = (HANode) editPart.getModel();
            ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
            request.setLocation(node.getLocation());
            request.setEditParts(editPart);
            //get move delta
            Point moveDelta = null;
            switch(event.keyCode) {
                case SWT.ARROW_LEFT:
                    moveDelta = new Point(-1, 0);
                    break;
                case SWT.ARROW_RIGHT:
                    moveDelta = new Point(1, 0);
                    break;
                case SWT.ARROW_UP:
                    moveDelta = new Point(0, -1);
                    break;
                case SWT.ARROW_DOWN:
                    moveDelta = new Point(0, 1);
                    break;
                default:
                    return true;
            }
            request.setMoveDelta(moveDelta);
            command = editPart.getCommand(request);
        }
        if (command != null && !(command instanceof UnexecutableCommand)) {
            command.execute();
            flag = true;
        }
    }
    return flag;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) Command(org.eclipse.gef.commands.Command) Point(org.eclipse.draw2d.geometry.Point) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) HANode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HANode) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) HANodePart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HANodePart)

Example 53 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class PropertyTypeController method createComboCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    Connection repositoryConnection = null;
    ConnectionItem repositoryConnectionItem = null;
    // hwang add
    FileItem repositoryFileItem = null;
    String paramName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    String value = combo.getText();
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    if (value.equals(param.getValue())) {
        return null;
    }
    // Map<String, ConnectionItem> repositoryConnectionItemMap = null;
    IElementParameter repositoryParam = null;
    // hywang add for feature 6484
    Map<String, FileItem> repositoryFileItemMap = null;
    if (value.equals(EmfComponent.REPOSITORY)) {
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
            repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
        }
        repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
        String connectionSelected = (String) repositoryParam.getValue();
        // if (repositoryConnectionItemMap.containsKey(connectionSelected)) {
        try {
            Item item = null;
            if (!StringUtils.isEmpty(connectionSelected)) {
                IRepositoryViewObject repobj = factory.getLastVersion(connectionSelected);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    repositoryConnectionItem = (ConnectionItem) factory.getLastVersion(connectionSelected).getProperty().getItem();
                    repositoryConnection = repositoryConnectionItem.getConnection();
                } else {
                    repositoryConnection = null;
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        // for ruleItem,hywang add
        if (repositoryFileItemMap.containsKey(connectionSelected)) {
            repositoryFileItem = repositoryFileItemMap.get(connectionSelected);
        } else {
            if (!repositoryFileItemMap.isEmpty()) {
                repositoryFileItem = repositoryFileItemMap.values().iterator().next();
            } else {
                repositoryFileItem = null;
            }
        }
    }
    CompoundCommand cc = new CompoundCommand();
    if (repositoryConnectionItem != null) {
        initCDC(cc, repositoryConnectionItem);
    }
    ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
    cc.add(changeValuesFromRepository1);
    if (repositoryConnection != null) {
        ChangeValuesFromRepository changeValuesFromRepository2 = new ChangeValuesFromRepository(elem, repositoryConnection, repositoryParam.getParentParameter().getName() + ":" + repositoryParam.getName(), //$NON-NLS-1$
        repositoryConnectionItem.getProperty().getId());
        cc.add(changeValuesFromRepository2);
    }
    // hywang add for feature 6484
    if (repositoryFileItem != null) {
        final String id = repositoryFileItem.getProperty().getId();
        cc.add(new Command() {

            @Override
            public void execute() {
                IElementParameter elementParameter = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
                if (elementParameter != null) {
                    elementParameter = elementParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                    if (elementParameter != null) {
                        elementParameter.setValue(id);
                    }
                }
            }
        });
    }
    if (value.equals(EmfComponent.REPOSITORY)) {
        updateDBType(cc, repositoryConnection);
    }
    return cc;
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Point(org.eclipse.swt.graphics.Point) MultipleThreadDynamicComposite(org.talend.designer.core.ui.views.properties.MultipleThreadDynamicComposite) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FileItem(org.talend.core.model.properties.FileItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 54 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class RadioController method createCommand.

private List<Command> createCommand(SelectionEvent event) {
    Set<String> elementsName;
    Control ctrl = (Control) event.getSource();
    elementsName = hashCurControls.keySet();
    List<Command> commands = new ArrayList<Command>();
    for (String name : elementsName) {
        Object o = hashCurControls.get(name);
        if (o instanceof Control) {
            ctrl = (Control) o;
            if (ctrl == null) {
                hashCurControls.remove(name);
                return null;
            }
            if (ctrl.equals(event.getSource())) {
                if (ctrl instanceof Button) {
                    // before
                    if (!elem.getPropertyValue(name).equals(new Boolean(((Button) ctrl).getSelection()))) {
                        Command cmd = null;
                        Boolean value = new Boolean(((Button) ctrl).getSelection());
                        if (name.equals(EParameterName.ACTIVATE.getName())) {
                            if (elem instanceof Node) {
                                List<Node> nodeList = new ArrayList<Node>();
                                nodeList.add((Node) elem);
                                List<Connection> connList = new ArrayList<Connection>();
                                cmd = new ChangeActivateStatusElementCommand(value, nodeList, connList);
                                commands.add(cmd);
                            }
                        } else {
                            IElementParameter param = elem.getElementParameter(name);
                            if (Boolean.TRUE.equals(value)) {
                                List<IElementParameter> parameters = DesignerUtilities.findRadioParamInSameGroup(elem.getElementParameters(), param);
                                for (IElementParameter currentRadioParam : parameters) {
                                    if (Boolean.TRUE.equals(currentRadioParam.getValue())) {
                                        cmd = new PropertyChangeCommand(elem, currentRadioParam.getName(), Boolean.FALSE);
                                        commands.add(cmd);
                                    }
                                }
                            }
                            cmd = new PropertyChangeCommand(elem, name, value);
                            commands.add(cmd);
                            String groupName = param.getGroup();
                            if (groupName != null && elem.getElementParameter(groupName) != null) {
                                Command cmd2 = new PropertyChangeCommand(elem, groupName, name);
                                commands.add(cmd2);
                            }
                        }
                        return commands;
                    }
                }
            }
        }
    }
    return null;
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) Connection(org.talend.designer.core.ui.editor.connections.Connection) Control(org.eclipse.swt.widgets.Control) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ChangeActivateStatusElementCommand(org.talend.designer.core.ui.editor.cmd.ChangeActivateStatusElementCommand) Button(org.eclipse.swt.widgets.Button) IElementParameter(org.talend.core.model.process.IElementParameter) ChangeActivateStatusElementCommand(org.talend.designer.core.ui.editor.cmd.ChangeActivateStatusElementCommand)

Example 55 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class PropertyTypeController method updateDBType.

// see bug 0004305
private void updateDBType(CompoundCommand compoundCommand, Connection repositoryConnection) {
    if (repositoryConnection == null) {
        return;
    }
    if (!(repositoryConnection instanceof DatabaseConnection)) {
        return;
    }
    //$NON-NLS-1$
    final String property = "DBTYPE";
    if (elem.getElementParameter(property) == null) {
        return;
    }
    String currentDbType = ((DatabaseConnection) repositoryConnection).getDatabaseType();
    EDatabaseTypeName typeName = EDatabaseTypeName.getTypeFromDbType(currentDbType);
    Command command = new PropertyChangeCommand(elem, property, typeName.getXMLType());
    compoundCommand.add(command);
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Aggregations

Command (org.eclipse.gef.commands.Command)100 ArrayList (java.util.ArrayList)38 List (java.util.List)35 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)35 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)28 IElementParameter (org.talend.core.model.process.IElementParameter)22 Node (org.talend.designer.core.ui.editor.nodes.Node)20 INode (org.talend.core.model.process.INode)17 EditPart (org.eclipse.gef.EditPart)15 CommandStack (org.eclipse.gef.commands.CommandStack)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)14 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 RepositoryNode (org.talend.repository.model.RepositoryNode)13 RepositoryChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand)12 Request (org.eclipse.gef.Request)11 NonResizableEditPolicy (org.eclipse.gef.editpolicies.NonResizableEditPolicy)11 DirectEditRequest (org.eclipse.gef.requests.DirectEditRequest)11 LabelDirectEditPolicy (org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy)11