Java Code Examples for org.eclipse.gef.requests.CreateRequest#setLocation()

The following examples show how to use org.eclipse.gef.requests.CreateRequest#setLocation() . 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: PaletteToolTransferDropTargetListenerWithSelection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Overridden to select the created object.
 *
 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDrop()
 *      /!\ don't call super, this method is copied from AbstractTransferDropTargetListener,
 *      and added a method to select added object (method copied from CreationTool)
 *      Please note that intermediate class are also trying to
 */
@Override
protected void handleDrop() {
    final CreateRequest request = getCreateRequest();
    final Point loc = super.getDropLocation().getCopy();
    request.setLocation(loc);
    updateTargetEditPart();

    if (getTargetEditPart() != null) {
        final Command command = getCommand();
        if (command != null && command.canExecute()) {
            getViewer().getEditDomain().getCommandStack().execute(command);
            insertOnSequenceFlow(command, getTargetEditPart(), getViewer(), true);
            selectAddedObject(getViewer(), DiagramCommandStack.getReturnValues(command));
            getViewer().getEditDomain().loadDefaultTool();
        } else {
            getCurrentEvent().detail = DND.DROP_NONE;
        }
    } else {
        getCurrentEvent().detail = DND.DROP_NONE;
    }

}
 
Example 2
Source File: BonitaUnspecifiedTypeCreationTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void snapPoint(CreateRequest request) {
	Dimension delta =getDragMoveDelta();
	Point moveDelta = new Point(delta.preciseWidth(),delta.preciseHeight());

	if (helper != null && sourceRectangle != null && compoundSrcRect != null) {
		PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
		PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
		baseRect.translate(moveDelta);
		jointRect.translate(moveDelta);
		PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
		helper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] {
				baseRect, jointRect }, preciseDelta);

		request.setLocation(preciseDelta);
	}

}
 
Example 3
Source File: DraggableElementCreationTool.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void updateTargetRequest() {
    ((CreateRequest) getTargetRequest()).setLocation(getLocation());
    final CreateRequest req = getCreateRequest();
    req.getExtendedData().clear();

    if (isInState(STATE_DRAG_IN_PROGRESS)) {
        snapPoint(req);
    } else {
        req.setLocation(getLocation());
        req.setSize(null);
    }

}
 
Example 4
Source File: DraggableElementCreationTool.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void snapPoint(CreateRequest request) {
    if (helper != null && figure != null) {
        final PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
        final PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
        Point location = getLocation().getTranslated(-figure.getSize().width / 2, -figure.getSize().height / 2);
        final PrecisionPoint preciseDelta = new PrecisionPoint(location.preciseX(), location.preciseY());
        baseRect.translate(preciseDelta);
        jointRect.translate(preciseDelta);
        helper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] {
                baseRect, jointRect }, preciseDelta);
        request.setLocation(preciseDelta);
    }

}
 
Example 5
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 6
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 7
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 8
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 9
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;
}