Java Code Examples for org.eclipse.gef.commands.Command#canExecute()

The following examples show how to use org.eclipse.gef.commands.Command#canExecute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DraggableElementCreationTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void redrawFeedback() {
    this.calculateCursor();
    final Command command = getCommand();

    if (command != null && command.canExecute()) {

        if (!draggableElement.getLayer().getChildren().contains(figure)) {
            draggableElement.getLayer().add(figure);
        }
        final IFigure parentFigure = draggableElement.getLayer();

        final Point location = ((CreateRequest) getTargetRequest()).getLocation();
        FiguresHelper.translateToAbsolute(parentFigure, location);

        showTargetCompartmentFeedback();
        Point translated = getLocation().getTranslated(-figure.getSize().width / 2, -figure.getSize().height / 2);
        FiguresHelper.translateToAbsolute(figure, translated);
        figure.setLocation(translated);
    } else {
        if (draggableElement.getLayer().getChildren().contains(figure)) {
            draggableElement.getLayer().remove(figure);
        }
    }
}
 
Example 2
Source File: MessageFlowFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void createMessageFlow(TransactionalEditingDomain editingDomain, Message event, ThrowMessageEvent source,
        AbstractCatchMessageEvent target, DiagramEditPart dep) {
    EditPart targetEP = findEditPart(dep, target);
    EditPart sourceEP = findEditPart(dep, source);

    CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(
            ProcessElementTypes.MessageFlow_4002, ((IHintedType) ProcessElementTypes.MessageFlow_4002).getSemanticHint(),
            dep.getDiagramPreferencesHint());
    Command createMessageFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceEP,
            targetEP);
    if (createMessageFlowCommand.canExecute()) {
        dep.getDiagramEditDomain().getDiagramCommandStack().execute(createMessageFlowCommand);
        dep.getDiagramEditDomain().getDiagramCommandStack().flush();
        dep.refresh();

        ConnectionViewAndElementDescriptor desc = (ConnectionViewAndElementDescriptor) request.getNewObject();
        MessageFlow message = desc.getElementAdapter().getAdapter(MessageFlow.class);
        SetCommand setCommand = new SetCommand(editingDomain, message, ProcessPackage.Literals.ELEMENT__NAME,
                event.getName());
        editingDomain.getCommandStack().execute(setCommand);
    }
}
 
Example 3
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Hides the labels on the connections of the given elements
 * 
 * @param elements
 *            - The EditParts which's connection labels is to be hidden
 * @param excluding
 *            - The types of connection labels which are not wanted to be
 *            hidden
 */
public static void hideConnectionLabelsForEditParts(List<GraphicalEditPart> elements,
		List<java.lang.Class<?>> excluding) {
	for (EditPart editpart : elements) {
		GraphicalEditPart ep = ((GraphicalEditPart) editpart);
		@SuppressWarnings("unchecked")
		List<ConnectionNodeEditPart> connections = ep.getSourceConnections();
		for (ConnectionNodeEditPart connection : connections) {
			@SuppressWarnings("unchecked")
			List<ConnectionNodeEditPart> labels = connection.getChildren();
			for (EditPart label : labels) {
				if (!isInstanceOfAny(label, excluding)) {
					ShowHideLabelsRequest request = new ShowHideLabelsRequest(false, ((View) label.getModel()));
					Command com = connection.getCommand(request);
					if (com != null && com.canExecute())
						com.execute();
				}
			}

		}
	}
}
 
Example 4
Source File: DeleteAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isEnabled( )
{
	Object selection = getSelection( );
	if (selection instanceof IMixedHandle)
	{
		selection = ((IMixedHandle) selection).getChildren( ).toArray( );
	}
	else if ( selection != null && selection instanceof StructuredSelection )
	{
		Object element = ( (StructuredSelection) selection ).getFirstElement( );
		if ( element != null && element instanceof LibraryHandle )
		{
			if ( ( (LibraryHandle) element ).getHostHandle( ) != null )
			{
				return true;
			}
		}
	}
	Command cmd = createDeleteCommand( selection );
	if ( cmd == null )
		return false;
	return cmd.canExecute( );
}
 
Example 5
Source File: VerticalLineAction.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
    final Command cmd = createCommand();
    if (cmd == null) {
        return false;
    }
    return cmd.canExecute();
}
 
Example 6
Source File: VerticalLineAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
	Command cmd = this.createCommand();
	if (cmd == null) {
		return false;
	}
	return cmd.canExecute();
}
 
Example 7
Source File: HorizontalLineAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
	Command cmd = this.createCommand();
	if (cmd == null) {
		return false;
	}
	return cmd.canExecute();
}
 
Example 8
Source File: ERDiagramAlignmentAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
 */
@Override
protected boolean calculateEnabled() {
	operationSet = null;
	Command cmd = createAlignmentCommand();
	if (cmd == null)
		return false;
	return cmd.canExecute();
}
 
Example 9
Source File: ColorAndFontPropertySection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected final void execute(Command command,
		IProgressMonitor progressMonitor) {
	if (command == null || !command.canExecute())
		return;
	if (getDiagramCommandStack() != null)
		getDiagramCommandStack().execute(command, progressMonitor);
}
 
Example 10
Source File: AbstractDiagramElementsGmfArranger.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Calls an autosize on the given GraphicalEditPart
 * @param graphicalEditPart - The GraphicalEditPart that is to be resized
 */
public void autoresizeGraphicalEditPart(GraphicalEditPart graphicalEditPart) {
	List<IGraphicalEditPart> l = new ArrayList<IGraphicalEditPart>();
	l.add(graphicalEditPart);
	SizeAction action = new SizeAction(SizeAction.PARAMETER_AUTOSIZE, l);
	Command cmd = action.getCommand();
	
	if (cmd != null && cmd.canExecute()){
		cmd.execute();
	}
}
 
Example 11
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Moves a GraphicalEditPart to the given location
 * 
 * @param graphEP
 *            - The GraphicalEditPart
 * @param new_X
 *            - The new x coordinate
 * @param new_Y
 *            - The new y coordinate
 */
public static void moveGraphicalEditPart(GraphicalEditPart graphEP, int new_X, int new_Y) {
	Rectangle figurebounds = graphEP.getFigure().getBounds();
	ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	move_req.setMoveDelta(new Point(new_X - figurebounds.x(), new_Y - figurebounds.y()));
	move_req.setEditParts(graphEP);

	Command cmd = graphEP.getCommand(move_req);
	if (cmd != null && cmd.canExecute())
		cmd.execute();
}
 
Example 12
Source File: ERDiagramAlignmentAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
 */
@Override
protected boolean calculateEnabled() {
    operationSet = null;
    final Command cmd = createAlignmentCommand();
    if (cmd == null)
        return false;
    return cmd.canExecute();
}
 
Example 13
Source File: HorizontalLineAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final Command cmd = createCommand();
    if (cmd == null) {
        return false;
    }
    return cmd.canExecute();
}
 
Example 14
Source File: VerticalLineAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final Command cmd = createCommand();
    if (cmd == null) {
        return false;
    }
    return cmd.canExecute();
}
 
Example 15
Source File: MainProcessCanonicalEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private Collection<IAdaptable> createConnections(Collection<ProcessLinkDescriptor> linkDescriptors,
		Domain2Notation domain2NotationMap) {
	LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>();
	for (ProcessLinkDescriptor nextLinkDescriptor : linkDescriptors) {
		EditPart sourceEditPart = getSourceEditPart(nextLinkDescriptor, domain2NotationMap);
		EditPart targetEditPart = getTargetEditPart(nextLinkDescriptor, domain2NotationMap);
		if (sourceEditPart == null || targetEditPart == null) {
			continue;
		}
		CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
				nextLinkDescriptor.getSemanticAdapter(),
				ProcessVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), ViewUtil.APPEND, false,
				((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
		CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
		ccr.setType(RequestConstants.REQ_CONNECTION_START);
		ccr.setSourceEditPart(sourceEditPart);
		sourceEditPart.getCommand(ccr);
		ccr.setTargetEditPart(targetEditPart);
		ccr.setType(RequestConstants.REQ_CONNECTION_END);
		Command cmd = targetEditPart.getCommand(ccr);
		if (cmd != null && cmd.canExecute()) {
			executeCommand(cmd);
			IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
			if (viewAdapter != null) {
				adapters.add(viewAdapter);
			}
		}
	}
	return adapters;
}
 
Example 16
Source File: WorkflowCanonicalEditPolicy.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private Collection<IAdaptable> createConnections(Collection<CrossflowLinkDescriptor> linkDescriptors,
		Domain2Notation domain2NotationMap) {
	LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>();
	for (CrossflowLinkDescriptor nextLinkDescriptor : linkDescriptors) {
		EditPart sourceEditPart = getSourceEditPart(nextLinkDescriptor, domain2NotationMap);
		EditPart targetEditPart = getTargetEditPart(nextLinkDescriptor, domain2NotationMap);
		if (sourceEditPart == null || targetEditPart == null) {
			continue;
		}
		CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
				nextLinkDescriptor.getSemanticAdapter(),
				CrossflowVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), ViewUtil.APPEND, false,
				((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
		CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
		ccr.setType(RequestConstants.REQ_CONNECTION_START);
		ccr.setSourceEditPart(sourceEditPart);
		sourceEditPart.getCommand(ccr);
		ccr.setTargetEditPart(targetEditPart);
		ccr.setType(RequestConstants.REQ_CONNECTION_END);
		Command cmd = targetEditPart.getCommand(ccr);
		if (cmd != null && cmd.canExecute()) {
			executeCommand(cmd);
			IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
			if (viewAdapter != null) {
				adapters.add(viewAdapter);
			}
		}
	}
	return adapters;
}
 
Example 17
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addSequenceFlow(final String name, final String sourceId, final String targetId, final boolean isDefault, final Point sourceAnchor,
        final Point targetAnchor, final PointList bendpoints) throws ProcBuilderException {
    final String srcId = NamingUtils.convertToId(sourceId);
    final String trgtId = NamingUtils.convertToId(targetId);
    final ShapeNodeEditPart sourceNode = editParts.get(srcId);
    final ShapeNodeEditPart targetNode = editParts.get(trgtId);

    if (!canSequenceFlowBeCreated(srcId, trgtId, sourceNode, targetNode)) {
        return;
    }

    final CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(ProcessElementTypes.SequenceFlow_4001,
            ((IHintedType) ProcessElementTypes.SequenceFlow_4001).getSemanticHint(), diagramPart
                    .getDiagramPreferencesHint());
    final Command createSequenceFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceNode, targetNode);
    if(!createSequenceFlowCommand.canExecute()) {
       return;
    }
    createSequenceFlowCommand.execute();
    
    final ConnectionViewAndElementDescriptor newObject = (ConnectionViewAndElementDescriptor) request.getNewObject();
    final Edge edge = (Edge) newObject.getAdapter(Edge.class);
    final SequenceFlow createdElement = (SequenceFlow) newObject.getElementAdapter().getAdapter(EObject.class);
    if (createdElement == null) {
        throw new ProcBuilderException("Impossible to create SequenceFlow " + name);
    }

    if (bendpoints != null && bendpoints.size() > 1) {
        setBendPoints(bendpoints, newObject);
    }

    handleSequenceFlowAnchors(sourceAnchor, targetAnchor, newObject);
    if (name != null) {
        commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.Literals.ELEMENT__NAME, name));
    }
    commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getSequenceFlow_IsDefault(), isDefault));
    if (edge != null) {
        commandStack.append(SetCommand.create(editingDomain, edge.getStyle(NotationPackage.eINSTANCE.getLineStyle()),
                NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.colorToInteger(ColorConstants.lightGray)));
    }

    createdSequenceFlows.add(new Pair<String, String>(srcId, trgtId));
    currentElement = createdElement;
    currentView = edge;
    execute();
}
 
Example 18
Source File: LevelAttributeHandleDropAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean performDrop( Object transfer, Object target, int operation,
		DNDLocation location )
{
	if (transfer instanceof IAdaptable)
	{
		if (((IAdaptable)transfer).getAdapter( StructureHandle.class ) instanceof LevelAttributeHandle)
		{
			transfer = ((IAdaptable)transfer).getAdapter( StructureHandle.class );
		}
	}
	if ( target instanceof EditPart )// drop on layout
	{
		EditPart editPart = (EditPart) target;

		if ( editPart != null )
		{
			CreateRequest request = new CreateRequest( );

			request.getExtendedData( )
					.put( DesignerConstants.KEY_NEWOBJECT, transfer );
			request.setLocation( location.getPoint( ) );
			Command command = editPart.getCommand( request );
			if ( command != null && command.canExecute( ) )
			{
				CommandStack stack = SessionHandleAdapter.getInstance( )
						.getCommandStack( );
				stack.startTrans( Messages.getString( "LevelHandleDropAdapter.ActionText" ) ); //$NON-NLS-1$

				editPart.getViewer( )
						.getEditDomain( )
						.getCommandStack( )
						.execute( command );
				CrosstabReportItemHandle crosstab = getCrosstab( editPart );
				if ( crosstab != null )
				{
					AggregationCellProviderWrapper providerWrapper = new AggregationCellProviderWrapper( crosstab );
					providerWrapper.updateAllAggregationCells( AggregationCellViewAdapter.SWITCH_VIEW_TYPE );
				}
				stack.commit( );
				return true;
			}
			else
				return false;
		}
	}
	return false;
}
 
Example 19
Source File: LevelHandleDropAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean performDrop( Object transfer, Object target, int operation,
		DNDLocation location )
{

	if ( target instanceof EditPart )//drop on layout
	{
		EditPart editPart = (EditPart) target;

		if ( editPart != null )
		{
			CreateRequest request = new CreateRequest( );

			request.getExtendedData( )
					.put( DesignerConstants.KEY_NEWOBJECT, transfer );
			request.setLocation( location.getPoint( ) );
			Command command = editPart.getCommand( request );
			if ( command != null && command.canExecute( ) )
			{
				CommandStack stack = SessionHandleAdapter.getInstance( )
				.getCommandStack( );
				stack.startTrans( Messages.getString( "LevelHandleDropAdapter.ActionText" ) ); //$NON-NLS-1$
		
				editPart.getViewer( )
						.getEditDomain( )
						.getCommandStack( )
						.execute( command );
				CrosstabReportItemHandle crosstab = getCrosstab( editPart );
				if ( crosstab != null )
				{
					AggregationCellProviderWrapper providerWrapper = new AggregationCellProviderWrapper( crosstab );
					providerWrapper.updateAllAggregationCells( AggregationCellViewAdapter.SWITCH_VIEW_TYPE );
				}
				stack.commit( );
				return true;
			}
			else
				return false;
		}
	}
	return false;
}
 
Example 20
Source File: MeasureHandleDropAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean performDrop( Object transfer, Object target, int operation,
		DNDLocation location )
{
	// if ( transfer instanceof Object[] )
	// {
	// Object[] objects = (Object[]) transfer;
	// for ( int i = 0; i < objects.length; i++ )
	// {
	// if ( !performDrop( objects[i], target, operation, location ) )
	// return false;
	// }
	// return true;
	// }

	if ( target instanceof EditPart )
	{
		EditPart editPart = (EditPart) target;

		CreateRequest request = new CreateRequest( );

		request.getExtendedData( ).put( DesignerConstants.KEY_NEWOBJECT,
				transfer );
		request.setLocation( location.getPoint( ) );
		Command command = editPart.getCommand( request );
		if ( command != null && command.canExecute( ) )
		{
			CrosstabReportItemHandle crosstab = getCrosstab( editPart );
			if ( crosstab != null )
			{
				crosstab.getModuleHandle( ).getCommandStack( ).startTrans( Messages.getString("MeasureHandleDropAdapter_trans_name") ); //$NON-NLS-1$
			}

			// Carl: Add this part below to set the binding for the crosstab in case it is not already set
			// Carl: This binding property should be set before execute the drop command
			// Carl: This behavior is the same as taken from ExtendedDataColumnXtabDropAdapter

			CubeHandle measureCubeHandle = CrosstabAdaptUtil
					.getCubeHandle( (ReportElementHandle) transfer );

			if ( measureCubeHandle == null )
			{

				ReportElementHandle extendedData = adapter.getBoundExtendedData( (ReportItemHandle) crosstab.getModelHandle( ) );
				
				if(extendedData == null || !extendedData.equals( adapter.resolveExtendedData( (ReportElementHandle) transfer)))
				{
					if(! adapter.setExtendedData( (ReportItemHandle)crosstab.getModelHandle( ), 
							adapter.resolveExtendedData( (ReportElementHandle) transfer)))
					{
						crosstab.getModuleHandle( ).getCommandStack( ).rollback( );
						return false;
					}
				}

			}

			editPart.getViewer( )
					.getEditDomain( )
					.getCommandStack( )
					.execute( command );

			
			if ( crosstab != null )
			{
				AggregationCellProviderWrapper providerWrapper = new AggregationCellProviderWrapper( crosstab );
				providerWrapper.updateAllAggregationCells( AggregationCellViewAdapter.SWITCH_VIEW_TYPE );
				
				if (crosstab.getDimensionCount( ICrosstabConstants.COLUMN_AXIS_TYPE ) != 0)
				{
					DimensionViewHandle viewHnadle = crosstab.getDimension( ICrosstabConstants.COLUMN_AXIS_TYPE, 
							crosstab.getDimensionCount( ICrosstabConstants.COLUMN_AXIS_TYPE ) - 1 );
					CrosstabUtil.addLabelToHeader( viewHnadle.getLevel( viewHnadle.getLevelCount( ) - 1 ) );
				}
				
				crosstab.getModuleHandle( ).getCommandStack( ).commit( );
			}
			return true;
		}
		else
			return false;

	}
	return false;
}