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

The following examples show how to use org.eclipse.gef.EditPart#getModel() . 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: MeasureHandleDropAdapter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public int canDrop( Object transfer, Object target, int operation,
		DNDLocation location )
{
	if ( !isMeasureHandle( transfer ) )
	{
		return DNDService.LOGIC_UNKNOW;
	}
	if ( target instanceof EditPart )
	{
		EditPart editPart = (EditPart) target;
		if ( editPart.getModel( ) instanceof IVirtualValidator )
		{
			if ( ( (IVirtualValidator) editPart.getModel( ) ).handleValidate( transfer ) )
				return DNDService.LOGIC_TRUE;
			else
				return DNDService.LOGIC_FALSE;
		}
	}
	return DNDService.LOGIC_UNKNOW;
}
 
Example 2
Source File: ERDiagramTransferDragSourceListener.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private Object getTargetModel(final DragSourceEvent event) {
    final List editParts = dragSourceViewer.getSelectedEditParts();
    if (editParts.size() != 1) {
        // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする
        return null;
    }

    final EditPart editPart = (EditPart) editParts.get(0);

    final Object model = editPart.getModel();
    if (model instanceof NormalColumn || model instanceof ColumnGroup || model instanceof Word) {
        return model;
    }

    return null;
}
 
Example 3
Source File: ExtendedDataColumnXtabDropAdapter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public int canDrop( Object transfer, Object target, int operation,
		DNDLocation location )
{
	if ( !(transfer instanceof ReportElementHandle) 
			|| adapter == null || !adapter.isExtendedDataItem( (ReportElementHandle) transfer ))
	{
		return DNDService.LOGIC_UNKNOW;
	}
	if ( target instanceof EditPart )
	{
		EditPart editPart = (EditPart) target;
		if ( editPart.getModel( ) instanceof IVirtualValidator )
		{
			if ( handleValidate(editPart, transfer).size( ) > 0 )
				return DNDService.LOGIC_TRUE;
			else
				return DNDService.LOGIC_FALSE;
		}
	}
	return DNDService.LOGIC_UNKNOW;
}
 
Example 4
Source File: CreateIndexAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void execute(final Event event) {

    final ERDiagram diagram = getDiagram();

    final List selectedEditParts = getTreeViewer().getSelectedEditParts();
    final EditPart editPart = (EditPart) selectedEditParts.get(0);
    final ERTable table = (ERTable) editPart.getModel();

    final IndexDialog dialog = new IndexDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null, table);

    if (dialog.open() == IDialogConstants.OK_ID) {
        final CreateIndexCommand command = new CreateIndexCommand(diagram, dialog.getResultIndex());

        this.execute(command);
    }
}
 
Example 5
Source File: ChangeNameAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
	@Override
	public void execute(Event event) {

		ERDiagram diagram = this.getDiagram();

		List selectedEditParts = this.getTreeViewer().getSelectedEditParts();
		EditPart editPart = (EditPart) selectedEditParts.get(0);
		Object model = editPart.getModel();
		if (model instanceof ERModel) {
			ERModel ermodel = (ERModel) model;
			
			InputDialog dialog = new InputDialog(
					PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
					"���O�ύX", "�_�C�A�O����������͂��ĉ������B", ermodel.getName(), null);
			if (dialog.open() == IDialogConstants.OK_ID) {
				ermodel.setName(dialog.getValue());
				diagram.getDiagramContents().getModelSet().changeModel(ermodel);
				ermodel.getDiagram().getEditor().setDirty(true);
//				ermodel.changeAll();
//				AddERModelCommand command = new AddERModelCommand(diagram, dialog.getValue());
//				this.execute(command);
			}
		}

	}
 
Example 6
Source File: ProcessValidationDecoratorProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
public void createDecorators(IDecoratorTarget decoratorTarget) {
	EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
	if (editPart instanceof GraphicalEditPart || editPart instanceof AbstractConnectionEditPart) {
		Object model = editPart.getModel();
		if ((model instanceof View)) {
			View view = (View) model;
			if (!(view instanceof Edge) && !view.isSetElement()) {
				return;
			}
		}
		EditDomain ed = editPart.getViewer().getEditDomain();
		if (!(ed instanceof DiagramEditDomain)) {
			return;
		}
		if (((DiagramEditDomain) ed).getEditorPart() instanceof ProcessDiagramEditor) {
			decoratorTarget.installDecorator(KEY, new StatusDecorator(decoratorTarget));
		}
	}
}
 
Example 7
Source File: ExtendedDataColumnXtabDropAdapter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private CrosstabReportItemHandle getCrosstab( EditPart editPart )
{
	CrosstabReportItemHandle crosstab = null;
	Object tmp = editPart.getModel( );
	if ( !( tmp instanceof CrosstabCellAdapter ) )
	{
		return null;
	}
	if ( tmp instanceof VirtualCrosstabCellAdapter )
	{
		return ( (VirtualCrosstabCellAdapter) tmp ).getCrosstabReportItemHandle( );
	}

	CrosstabCellHandle handle = ( (CrosstabCellAdapter) tmp ).getCrosstabCellHandle( );
	if ( handle != null )
	{
		crosstab = handle.getCrosstab( );
	}

	return crosstab;

}
 
Example 8
Source File: ResizeModelAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected List<Command> getCommand(EditPart editPart, Event event) {
	List<Command> commandList = new ArrayList<Command>();

	if (editPart instanceof IResizable) {
		NodeElement nodeElement = (NodeElement) editPart.getModel();

		MoveElementCommand command = new MoveElementCommand(this
				.getDiagram(), ((NodeElementEditPart) editPart).getFigure()
				.getBounds(), nodeElement.getX(), nodeElement.getY(), -1,
				-1, nodeElement);

		commandList.add(command);
	}

	return commandList;
}
 
Example 9
Source File: CrosstabBreadcrumbNodeProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Object getRealModel( Object element )
{
	if ( element instanceof EditPart )
	{
		EditPart editpart = (EditPart) element;
		return editpart.getModel( );
	}
	return element;
}
 
Example 10
Source File: ChangeBackgroundColorAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
private void setRGB(RGB rgb) {
    this.rgb = rgb;
    final EditPart editPart = ((MainDiagramEditor) getWorkbenchPart()).getGraphicalViewer().getContents();
    final IERDiagram erd = (IERDiagram) editPart.getModel();
    erd.toMaterializedDiagram().setDefaultColor(DesignResources.getColor(rgb));
    setColorToImage();
}
 
Example 11
Source File: DatasetNodeEditPart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param impl
 */
public DatasetNodeEditPart( EditPart parent, DataSetHandle dataset )
{
	setModel( dataset );
	setParent( parent );

	this.cube = (TabularCubeHandle) parent.getModel( );
}
 
Example 12
Source File: AutoResizeModelAction.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected List<Command> getCommand(final EditPart editPart, final Event event) {
    final List<Command> commandList = new ArrayList<Command>();

    if (editPart instanceof IResizable) {
        final NodeElement nodeElement = (NodeElement) editPart.getModel();

        final MoveElementCommand command = new MoveElementCommand(getDiagram(), ((NodeElementEditPart) editPart).getFigure().getBounds(), nodeElement.getX(), nodeElement.getY(), -1, -1, nodeElement);

        commandList.add(command);
    }

    return commandList;
}
 
Example 13
Source File: CreateChartAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean calculateEnabled( )
{
	List selected = getSelectedObjects( );

	if ( selected.size( ) != 1 || !( selected.get( 0 ) instanceof EditPart ) )
	{
		return false;
	}

	EditPart part = (EditPart) selected.get( 0 );
	Object model = part.getModel( );
	if ( !( model instanceof ReportItemHandle )
			&& model instanceof IAdaptable )
	{
		model = ( (IAdaptable) model ).getAdapter( DesignElementHandle.class );
	}
	if ( !( model instanceof ReportItemHandle )
			|| DEUtil.isReferenceElement( (ReportItemHandle) model ) )
	{
		return false;
	}
	Object[] objs = ElementAdapterManager.getAdapters( model,
			IReportItemViewProvider.class );
	if ( objs == null || objs.length > 1 )
	{
		return false;
	}
	if ( ( (ReportItemHandle) model ).getViews( ).size( ) != 0 || !( (ReportItemHandle) model ).canAddView( "Chart" ))//$NON-NLS-1$
	{
		return false;
	}
	return true;
}
 
Example 14
Source File: InsertInLayoutUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean handleValidateLabel( LabelHandle handle,
		EditPart targetPart )
{
	if ( targetPart.getModel( ) instanceof IAdaptable )
	{
		Object obj = ( (IAdaptable) targetPart.getModel( ) ).getAdapter( DesignElementHandle.class );
		if ( obj instanceof ExtendedItemHandle )
		{
			return ( (ExtendedItemHandle) obj ).canContain( DEUtil.getDefaultContentName( obj ),
					handle );
		}
	}
	return false;
}
 
Example 15
Source File: ERModelUtil.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public static ERDiagram getDiagram(EditPart editPart) {
	Object model = editPart.getModel();
	if (model instanceof ERModel) {
		return ((ERModel) model).getDiagram();

	}
	return (ERDiagram) model;
}
 
Example 16
Source File: DeferredGraphicalViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public List convertSelectionToModelLisr( List list )
{
	List retValue = new ArrayList( );
	int size = list.size( );
	boolean isDummy = false;
	for ( int i = 0; i < size; i++ )
	{
		Object object = list.get( i );
		if ( !( object instanceof EditPart ) )
		{
			continue;
		}
		EditPart part = (EditPart) object;
		if ( part instanceof DummyEditpart )
		{
			retValue.add( part.getModel( ) );
			isDummy = true;
		}
		else if ( isDummy )
		{
			break;
		}
		else if ( part.getModel( ) instanceof ListBandProxy )
		{
			retValue.add( ( (ListBandProxy) part.getModel( ) ).getSlotHandle( ) );
		}
		else
		{
			Object model = part.getModel( );
			if (model instanceof IAdaptable)
			{
				Object temp = ((IAdaptable)model).getAdapter( DesignElementHandle.class );
				model = temp==null?model:temp;
			}
			if (model instanceof ReportItemHandle)
			{
				ReportItemHandle handle = (ReportItemHandle)model;
				if (handle.getCurrentView( ) != null)
				{
					model = handle.getCurrentView( );
				}
			}
			retValue.add(model);
			
		}
	}

	return retValue;
}
 
Example 17
Source File: ReportTemplateTransferDropTargetListener.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private boolean handleValidateLibrary( Object dragObj )
{
	EditPart targetEditPart = getTargetEditPart( );
	if ( targetEditPart == null )
	{
		return true;
	}
	if ( dragObj != null )
	{
		Object[] dragObjs;
		if ( dragObj instanceof Object[] )
		{
			dragObjs = (Object[]) dragObj;
		}
		else
		{
			dragObjs = new Object[]{
				dragObj
			};
		}
		if ( dragObjs.length == 0 )
		{
			return false;
		}
		for ( int i = 0; i < dragObjs.length; i++ )
		{
			dragObj = dragObjs[i];
			if ( dragObj instanceof ReportElementHandle )
			{
				if ( ( (ReportElementHandle) dragObj ).getRoot( ) instanceof LibraryHandle )
				{
					// enable DataSetHandle,ParameterHandle to drag in lib
					// explorer view.
					// 180426 disabled drop to library editor
					if ( ( dragObj instanceof DataSetHandle || dragObj instanceof ParameterHandle )
							&& getTargetEditPart( ) == null )
						return true;
					if ( dragObj instanceof DataSourceHandle
							|| dragObj instanceof MasterPageHandle )
					{
						return targetEditPart instanceof ReportDesignEditPart
								&& ( (ReportElementHandle) dragObj ).getRoot( ) != targetEditPart.getModel( );
					}
					if ( !DNDUtil.handleValidateTargetCanContain( targetEditPart.getModel( ),
							dragObj )
							|| !DNDUtil.handleValidateTargetCanContainMore( targetEditPart.getModel( ),
									1 ) )
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
			else if ( dragObj instanceof EmbeddedImageHandle
					&& ( (EmbeddedImageHandle) dragObj ).getElementHandle( )
							.getRoot( ) instanceof LibraryHandle )
			{
				int canContain = DNDUtil.handleValidateTargetCanContain( targetEditPart.getModel( ),
						dragObj,
						true );
				return canContain == DNDUtil.CONTAIN_THIS;
			}

			else
			{
				return false;
			}
		}
		Object root = getTargetEditPart( ).getRoot( ).getContents( ).getModel( );
		return root instanceof ReportDesignHandle || root instanceof LibraryHandle;
		//return true;
	}
	return false;
}
 
Example 18
Source File: PrintERDiagramOperation.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
protected ERDiagram getDiagram() {
    final EditPart editPart = getViewer().getContents();
    final ERDiagram diagram = (ERDiagram) editPart.getModel();

    return diagram;
}
 
Example 19
Source File: AbstractOutlineBaseAction.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
protected ERDiagram getDiagram() {
	EditPart editPart = treeViewer.getContents();
	ERDiagram diagram = (ERDiagram) editPart.getModel();

	return diagram;
}
 
Example 20
Source File: CustomFeedbackXYLayoutPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override to compute position of Subprocess event children when changing parent
 */
@Override
protected Command createAddCommand(final EditPart child, final Object constraint) {
    if (child instanceof CustomSubProcessEvent2EditPart && constraint instanceof Rectangle) {
        final Rectangle rect = (Rectangle) constraint;

        final CompoundCommand cmds = new CompoundCommand("Move Subprocesss Event");

        ICommand boundsCommand = new SetBoundsCommand(((ShapeEditPart) child).getEditingDomain(),
                DiagramUIMessages.SetLocationCommand_Label_Resize,
                new EObjectAdapter((View) child.getModel()),
                rect.getTopLeft());

        cmds.add(new ICommandProxy(boundsCommand));

        ShapeCompartmentEditPart compartment = null;
        for (final Object c : child.getChildren()) {
            if (c instanceof ShapeCompartmentEditPart) {
                compartment = (ShapeCompartmentEditPart) c;
            }
        }

        final Location origin = (Location) ((Node) child.getModel()).getLayoutConstraint();
        for (final Object ep : compartment.getChildren()) {
            if (ep instanceof IGraphicalEditPart) {
                final Node view = (Node) ((IGraphicalEditPart) ep).getModel();
                final Location loc = (Location) view.getLayoutConstraint();
                final Point delta = new Point(loc.getX() - origin.getX(), loc.getY() - origin.getY());

                final Point newLoc = new Point(rect.getTopLeft().x + delta.x, rect.getTopLeft().y + delta.y);

                boundsCommand = new SetBoundsCommand(((IGraphicalEditPart) ep).getEditingDomain(),
                        DiagramUIMessages.SetLocationCommand_Label_Resize,
                        new EObjectAdapter((View) ((IGraphicalEditPart) ep).getModel()),
                        newLoc);

                cmds.add(new ICommandProxy(boundsCommand));
            }
        }

        return cmds.unwrap();
    } else {
        return super.createAddCommand(child, constraint);
    }

}