Java Code Examples for org.eclipse.gef.EditPart#getCommand()

The following examples show how to use org.eclipse.gef.EditPart#getCommand() . 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: ElementsManagerUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Calls the {@link DropObjectsRequest} on an EditPart. 
 * @param EP - The EditPart that is to be added to
 * @param diagramElements - The Elements that are to be added
 */
@SuppressWarnings("unchecked")
public static void addElementsToEditPart(EditPart EP, Collection<? extends Element> diagramElements) {
	List<Element> diagramElementsList;
	
	if(!(diagramElements instanceof List<?>)){
		diagramElementsList = (List<Element>) createList(diagramElements);
	}else{
		diagramElementsList = (List<Element>) diagramElements;
	}
	
	if(!diagramElementsList.isEmpty()){
		DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
		dropObjectsRequest.setObjects(diagramElementsList);
		dropObjectsRequest.setLocation(new Point(0,0));
		Command commandDrop = EP.getCommand(dropObjectsRequest);
		if (commandDrop != null){
			commandDrop.execute();
		}
	}
}
 
Example 2
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 3
Source File: AbstractDiagramElementsGmfArranger.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Arranges the children of an EditPart with the GMF arranging algorithm 
 * @param parent - The children of this EditPart will be arranged
 */
protected void arrangeChildren(EditPart parent) {
	@SuppressWarnings("unchecked")
	List<EditPart> elements = parent.getChildren();

	if(!elements.isEmpty()){
		ArrangeRequest arrangeRequest = new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);
		List<EditPart> l = new ArrayList<EditPart>();
		l.addAll(elements);
		arrangeRequest.setPartsToArrange(l);
		Command cmd = parent.getCommand(arrangeRequest);
		cmd.execute();
	}
}
 
Example 4
Source File: ColorAndFontPropertySection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Command getCommand(Request request) {
	List operationSet = getInput();
	Iterator editParts = operationSet.iterator();
	CompoundCommand command = new CompoundCommand("Change Font");
	while (editParts.hasNext()) {
		EditPart editPart = (EditPart) editParts.next();
		Command curCommand = editPart.getCommand(request);
		if (curCommand != null) {
			command.add(curCommand);
		}
	}
	return command.isEmpty() || command.size() != operationSet.size() ? UnexecutableCommand.INSTANCE
			: (Command) command;
}
 
Example 5
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 6
Source File: ParameterDropAdapter.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( );
			if ( transfer instanceof Object[] )
			{
				Object[] newObjs = (Object[]) transfer;
				transfer = UIUtil.getInsertPamaterElements( newObjs );
			}
			try
			{
				if ( transfer instanceof ScalarParameterHandle )
				{
					transfer = InsertInLayoutUtil.performInsertParameter( (ScalarParameterHandle) transfer );
				}
				else if ( transfer instanceof Object[] )
				{
					Object[] objs = (Object[])transfer;
					Object[] copys = new Object[objs.length];
					for (int i=0; i<objs.length; i++)
					{
						if (objs[i] instanceof ScalarParameterHandle)
						{
							copys[i] = InsertInLayoutUtil.performInsertParameter( (ScalarParameterHandle) objs[i] );
						}
						else
						{
							// Return now , don't support the other type
							return false;
						}
						
					}
					
					transfer = copys;
				}

			}
			catch ( SemanticException e )
			{
				// do nothing
				return false;
			}
			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 );
				stack.commit( );
				return true;
			}
			else
				return false;
		}
	}
	return false;
}
 
Example 7
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 8
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 9
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;
}
 
Example 10
Source File: VariableDropAdapter.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 )
{

	EditPart editPart = (EditPart) target;

	VariableElementHandle variable = (VariableElementHandle) transfer;

	DataItemHandle dataHandle = DesignElementFactory.getInstance( )
			.newDataItem( null );

	try
	{
		ComputedColumn bindingColumn = StructureFactory.newComputedColumn( dataHandle,
				variable.getName( ) );
		// FIXME currently variable does not support data type, so just set
		// string
		bindingColumn.setDataType( "string" );
		ExpressionUtility.setBindingColumnExpression( variable,
				bindingColumn,
				true );
		bindingColumn.setDisplayName( variable.getDisplayLabel( ) );
		dataHandle.addColumnBinding( bindingColumn, false );
		dataHandle.setResultSetColumn( bindingColumn.getName( ) );
	}
	catch ( Exception e )
	{
		ExceptionHandler.handle( e );
	}

	CreateRequest request = new CreateRequest( );
	request.getExtendedData( ).put( DesignerConstants.KEY_NEWOBJECT,
			dataHandle );
	request.setLocation( location.getPoint( ) );
	Command command = editPart.getCommand( request );
	if ( command != null && command.canExecute( ) )
	{
		CommandStack stack = SessionHandleAdapter.getInstance( )
				.getCommandStack( );
		stack.startTrans( TRANS_NAME ); //$NON-NLS-1$

		editPart.getViewer( )
				.getEditDomain( )
				.getCommandStack( )
				.execute( command );
		stack.commit( );
		return true;
	}
	else
		return false;
}
 
Example 11
Source File: CustomLaneItemSemanticEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static CommandProxy arrangeAll(final EditPart ep, final List<GraphicalEditPart> newList) {
	final ArrangeRequest request = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED);
	request.setPartsToArrange(newList);
	request.setViewAdaptersToArrange(newList);
	return new CommandProxy(ep.getCommand(request));
}