org.eclipse.gef.GraphicalViewer Java Examples

The following examples show how to use org.eclipse.gef.GraphicalViewer. 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: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void setRulerContainer( GraphicalViewer container, int orientation )
{
	if ( orientation == PositionConstants.NORTH )
	{
		if ( top == container )
			return;
		disposeRulerViewer( top );
		top = container;
	}
	else if ( orientation == PositionConstants.WEST )
	{
		if ( left == container )
			return;
		disposeRulerViewer( left );
		left = container;
	}
}
 
Example #2
Source File: RightAngleLineAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    for (final Object object : viewer.getSelectedEditParts()) {
        if (object instanceof ConnectionEditPart) {
            return true;

        } else if (object instanceof NodeElementEditPart) {
            final NodeElementEditPart nodeElementEditPart = (NodeElementEditPart) object;

            if (!nodeElementEditPart.getSourceConnections().isEmpty()) {
                return true;
            }
        }
    }

    return false;
}
 
Example #3
Source File: ResizeModelAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    for (final Object object : viewer.getSelectedEditParts()) {
        if (object instanceof NodeElementEditPart) {
            final NodeElementEditPart nodeElementEditPart = (NodeElementEditPart) object;

            if (nodeElementEditPart instanceof ERTableEditPart || nodeElementEditPart instanceof NoteEditPart) {
                return true;
            }
        }
    }

    return false;
}
 
Example #4
Source File: PrintImageAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void run() {
    GraphicalViewer viewer;
    viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);

    final PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    final PrinterData data = dialog.open();

    if (data != null) {
        final Printer printer = new Printer(data);
        final PrintGraphicalViewerOperation op = new PrintERDiagramOperation(printer, viewer);

        op.run(getWorkbenchPart().getTitle());
    }
}
 
Example #5
Source File: DefaultLineAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    for (final Object object : viewer.getSelectedEditParts()) {
        if (object instanceof ConnectionEditPart) {
            return true;

        } else if (object instanceof NodeElementEditPart) {
            final NodeElementEditPart nodeElementEditPart = (NodeElementEditPart) object;

            if (!nodeElementEditPart.getSourceConnections().isEmpty()) {
                return true;
            }
        }
    }

    return false;
}
 
Example #6
Source File: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void disposeRulerViewer( GraphicalViewer viewer )
{
	if ( viewer == null )
		return;
	/*
	 * There's a tie from the editor's range model to the RulerViewport (via
	 * a listener) to the RulerRootEditPart to the RulerViewer. Break this
	 * tie so that the viewer doesn't leak and can be garbage collected.
	 */

	RangeModel rModel = new DefaultRangeModel( );
	Viewport port = ( (FigureCanvas) viewer.getControl( ) ).getViewport( );
	port.setHorizontalRangeModel( new RulerDefaultRangeModel( rModel ) );
	port.setVerticalRangeModel( new RulerDefaultRangeModel( rModel ) );
	rulerEditDomain.removeViewer( viewer );
	viewer.getControl( ).dispose( );
}
 
Example #7
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private Dimension getDistance( )
	{
//		Point p = getStartLocation( );
//		
//		Control canvas = getGuideEditPart( ).getViewer( ).getControl( );
//		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
//	
//		Dimension retValue = new Dimension(rect.width - p.x, p.y);
//		
//		return retValue;
		
		Point p = getStartLocation( );
		
		FigureCanvas canvas = ((DeferredGraphicalViewer)getGuideEditPart().getViewer( ).getProperty( GraphicalViewer.class.toString( ))).getFigureCanvas( );
		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
	
		Dimension retValue = new Dimension(rect.width - p.x, p.y);
		if (canvas.getVerticalBar( ).isVisible( ))
		{
			retValue.width = retValue.width - canvas.getVerticalBar( ).getSize( ).x;
		}
		return retValue;
	}
 
Example #8
Source File: AutoResizeModelAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    for (final Object object : viewer.getSelectedEditParts()) {
        if (object instanceof NodeElementEditPart) {
            final NodeElementEditPart nodeElementEditPart = (NodeElementEditPart) object;

            if (nodeElementEditPart instanceof ERTableEditPart || nodeElementEditPart instanceof NoteEditPart) {
                return true;
            }
        }
    }

    return false;
}
 
Example #9
Source File: AbstractBaseSelectionAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
protected void execute(final Event event) {
    final GraphicalViewer viewer = getGraphicalViewer();

    final List<Command> commandList = new ArrayList<Command>();

    for (final Object object : viewer.getSelectedEditParts()) {
        final List<Command> subCommandList = getCommand((EditPart) object, event);
        commandList.addAll(subCommandList);
    }

    if (!commandList.isEmpty()) {
        final CompoundCommand compoundCommand = new CompoundCommand();
        for (final Command command : commandList) {
            compoundCommand.add(command);
        }

        this.execute(compoundCommand);
    }
}
 
Example #10
Source File: SelectAllContentsAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void run() {
	GraphicalViewer viewer = (GraphicalViewer) part
			.getAdapter(GraphicalViewer.class);

	if (viewer != null) {
		List<NodeElementEditPart> children = new ArrayList<NodeElementEditPart>();

		for (Object child : viewer.getContents().getChildren()) {
			if (child instanceof NodeElementEditPart) {
				NodeElementEditPart editPart = (NodeElementEditPart) child;
				if (editPart.getFigure().isVisible()) {
					children.add(editPart);
				}
			}
		}

		viewer.setSelection(new StructuredSelection(children));
	}
}
 
Example #11
Source File: AbstractExportAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
protected void save(final IEditorPart editorPart, final GraphicalViewer viewer) throws Exception {

        final String saveFilePath = getSaveFilePath(editorPart, viewer, getDiagram().getDiagramContents().getSettings().getExportSetting());
        if (saveFilePath == null) {
            return;
        }

        final File file = new File(saveFilePath);
        if (file.exists()) {
            final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
            messageBox.setText(ResourceString.getResourceString("dialog.title.warning"));
            messageBox.setMessage(ResourceString.getResourceString(getConfirmOverrideMessage()));

            if (messageBox.open() == SWT.CANCEL) {
                return;
            }
        }

        this.save(editorPart, viewer, saveFilePath);
        refreshProject();
    }
 
Example #12
Source File: ResizeModelAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected boolean calculateEnabled() {
	GraphicalViewer viewer = this.getGraphicalViewer();

	for (Object object : viewer.getSelectedEditParts()) {
		if (object instanceof NodeElementEditPart) {
			NodeElementEditPart nodeElementEditPart = (NodeElementEditPart) object;

			if (nodeElementEditPart instanceof ERTableEditPart
					|| nodeElementEditPart instanceof NoteEditPart) {
				return true;
			}
		}
	}

	return false;
}
 
Example #13
Source File: AbstractBaseSelectionAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
protected void execute(Event event) {
    final GraphicalViewer viewer = getGraphicalViewer();

    final List<Command> commandList = new ArrayList<>();

    for (final Object object : viewer.getSelectedEditParts()) {
        final List<Command> subCommandList = getCommand((EditPart) object, event);
        commandList.addAll(subCommandList);
    }

    if (!commandList.isEmpty()) {
        final CompoundCommand compoundCommand = new CompoundCommand();
        for (final Command command : commandList) {
            compoundCommand.add(command);
        }

        execute(compoundCommand);
    }
}
 
Example #14
Source File: ResizeModelAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    for (final Object object : viewer.getSelectedEditParts()) {
        if (object instanceof DiagramWalkerEditPart) {
            final DiagramWalkerEditPart nodeElementEditPart = (DiagramWalkerEditPart) object;

            if (nodeElementEditPart instanceof ERTableEditPart || nodeElementEditPart instanceof WalkerNoteEditPart) {
                return true;
            }
        }
    }

    return false;
}
 
Example #15
Source File: AbstractBaseSelectionAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
protected void execute(Event event) {
	GraphicalViewer viewer = this.getGraphicalViewer();

	List<Command> commandList = new ArrayList<Command>();

	for (Object object : viewer.getSelectedEditParts()) {
		List<Command> subCommandList = this.getCommand((EditPart) object,
				event);
		commandList.addAll(subCommandList);
	}

	if (!commandList.isEmpty()) {
		CompoundCommand compoundCommand = new CompoundCommand();
		for (Command command : commandList) {
			compoundCommand.add(command);
		}

		this.execute(compoundCommand);
	}
}
 
Example #16
Source File: ExportToHtmlAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected String getSaveFilePath(IEditorPart editorPart,
		GraphicalViewer viewer) {

	IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile();

	DirectoryDialog fileDialog = new DirectoryDialog(editorPart
			.getEditorSite().getShell(), SWT.SAVE);

	IProject project = file.getProject();

	fileDialog.setFilterPath(project.getLocation().toString());
	fileDialog.setMessage(ResourceString
			.getResourceString("dialog.message.export.html.dir.select"));

	String saveFilePath = fileDialog.open();

	if (saveFilePath != null) {
		saveFilePath = saveFilePath + OUTPUT_DIR;
	}

	return saveFilePath;
}
 
Example #17
Source File: ReportEditorWithPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param request
 */
protected void handleCreateElement( final ReportRequest request )
{
	final GraphicalViewer viewer = getGraphicalViewer( );
	if ( !viewer.getControl( ).isVisible( ) )
	{
		return;
	}

	final List list = request.getSelectionModelList( );
	if ( list.size( ) != 1 )
	{
		return;
	}
	if ( request.getSource( ) instanceof ParameterHandle
			&& list.get( 0 ) instanceof DataItemHandle )
	{
		return;
	}
	Display.getCurrent( ).asyncExec( new Runnable( ) {

		public void run( )
		{
			Object part = viewer.getEditPartRegistry( ).get( list.get( 0 ) );
			if ( part instanceof EditPart )
			{
				Request directEditRequest = new Request( ReportRequest.CREATE_ELEMENT );
				directEditRequest.getExtendedData( )
						.putAll( request.getExtendedData( ) );
				if ( ( (EditPart) part ).understandsRequest( directEditRequest ) )
				{
					( (EditPart) part ).performRequest( directEditRequest );
				}
			}
		}
	} );

}
 
Example #18
Source File: LibraryMasterPageEditorFormPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public boolean onBroughtToTop( IReportEditorPage prePage )
{
	if ( getEditorInput( ) != prePage.getEditorInput( ) )
	{
		setInput( prePage.getEditorInput( ) );
	}

	ModuleHandle newModel = getProvider( ).queryReportModuleHandle( );
	boolean reload = false;
	if (getStaleType( ) == IPageStaleType.MODEL_RELOAD)
	{
		setModel( null );
		doSave( null );
		reload = true;
	}
	if ( (newModel != null && getModel( ) != newModel) || reload )
	{
		ModuleHandle oldModel = getModel( );

		getProvider( ).connect( newModel );
		setModel( newModel );

		rebuildReportDesign( oldModel );
		if ( getModel( ) != null )
		{
			setViewContentsAsMasterPage( );
			markPageStale( IPageStaleType.NONE );
		}
		updateStackActions( );

	}
	//reselect the selection
	GraphicalViewer view = getGraphicalViewer( );

	UIUtil.resetViewSelection( view, true );
	return true;
}
 
Example #19
Source File: ERDiagramOutlinePage.java    From erflute with Apache License 2.0 5 votes vote down vote up
public void setCategory(EditDomain editDomain, GraphicalViewer graphicalViewer, ActionRegistry registry) {
    this.graphicalViewer = graphicalViewer;

    viewer.setEditDomain(editDomain);
    this.registry = registry;

    if (getSite() != null) {
        resetView(registry);
    }
}
 
Example #20
Source File: ReportEditorWithPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void initializeGraphicalViewer( )
{
	super.initializeGraphicalViewer( );
	GraphicalViewer viewer = getGraphicalViewer( );

	if ( getModel( ) != null )
	{
		setContents( );
		hookModelEventManager( getModel( ) );
	}
	viewer.addDropTargetListener( createTemplateTransferDropTargetListener( viewer ) );
}
 
Example #21
Source File: ReportEditorWithPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void configureGraphicalViewer( )
{
	super.configureGraphicalViewer( );

	GraphicalViewer viewer = getGraphicalViewer( );
	ActionRegistry actionRegistry = getActionRegistry( );
	ReportRootEditPart root = new ReportRootEditPart( );
	viewer.setRootEditPart( root );

	// hook zoom actions
	hookZoom( root );

	// set key events
	viewer.setKeyHandler( new ReportViewerKeyHandler( viewer,
			actionRegistry ) );

	// configure the context menu
	ContextMenuProvider provider = new SchematicContextMenuProvider( viewer,
			actionRegistry );
	viewer.setContextMenu( provider );

	// hook the viewer into the EditDomain TODO create a function
	getEditDomain( ).addViewer( viewer );
	// acticate the viewer as selection provider for Eclipse
	getSite( ).setSelectionProvider( viewer );

	// initialize the viewer with input
	viewer.setEditPartFactory( getEditPartFactory( ) );

	ModuleHandle model = getModel( );
	WrapperCommandStack commandStack = new WrapperCommandStack( model == null ? null
			: model.getCommandStack( ) );

	viewer.getEditDomain( ).setCommandStack( commandStack );

}
 
Example #22
Source File: AbstractBaseSelectionAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean calculateEnabled() {
    final GraphicalViewer viewer = getGraphicalViewer();

    if (viewer.getSelectedEditParts().isEmpty()) {
        return false;
    }

    return true;
}
 
Example #23
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.gef.Tool#setViewer(org.eclipse.gef.EditPartViewer)
 */
public void setViewer( EditPartViewer viewer )
{
	if ( viewer == getCurrentViewer( ) )
		return;
	super.setViewer( viewer );
	if ( viewer instanceof GraphicalViewer )
		setDefaultCursor( SharedCursors.CROSS );
	else
		setDefaultCursor( SharedCursors.NO );
}
 
Example #24
Source File: ExportToExcelDialog.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public ExportToExcelDialog(Shell parentShell, ERDiagram diagram,
		IEditorPart editorPart, GraphicalViewer viewer) {
	super(parentShell, 3);

	this.diagram = diagram;
	this.editorPart = editorPart;
	this.viewer = viewer;
}
 
Example #25
Source File: SearchDialog.java    From erflute with Apache License 2.0 5 votes vote down vote up
public SearchDialog(Shell parentShell, GraphicalViewer viewer, MainDiagramEditor erDiagramEditor, ERDiagram diagram) {
    super(parentShell);

    setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE);
    setBlockOnOpen(false);

    this.viewer = viewer;
    this.diagram = diagram;

    this.searchManager = new SearchManager(diagram);
}
 
Example #26
Source File: ERDiagramOutlinePage.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
public void setCategory(final EditDomain editDomain, final GraphicalViewer graphicalViewer, final MenuManager outlineMenuMgr, final ActionRegistry registry) {
    this.graphicalViewer = graphicalViewer;
    viewer.setContextMenu(outlineMenuMgr);

    // エディット・ドメインの設定
    viewer.setEditDomain(editDomain);
    this.registry = registry;

    if (getSite() != null) {
        resetView(registry);
    }
}
 
Example #27
Source File: ERDiagramOutlinePage.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public void setCategory(EditDomain editDomain,
		GraphicalViewer graphicalViewer, MenuManager outlineMenuMgr,
		ActionRegistry registry) {
	this.graphicalViewer = graphicalViewer;
	this.viewer.setContextMenu(outlineMenuMgr);

	// �G�f�B�b�g�E�h���C���̐ݒ�
	this.viewer.setEditDomain(editDomain);
	this.registry = registry;

	if (this.getSite() != null) {
		this.resetView(registry);
	}
}
 
Example #28
Source File: MainDiagramEditor.java    From erflute with Apache License 2.0 5 votes vote down vote up
protected void initDragAndDrop(GraphicalViewer viewer) {
    final AbstractTransferDragSourceListener dragSourceListener =
            new ERDiagramTransferDragSourceListener(viewer, TemplateTransfer.getInstance());
    viewer.addDragSourceListener(dragSourceListener);
    final AbstractTransferDropTargetListener dropTargetListener =
            new ERDiagramTransferDropTargetListener(viewer, TemplateTransfer.getInstance());
    viewer.addDropTargetListener(dropTargetListener);
}
 
Example #29
Source File: ExportToHtmlAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public static Map<TableView, Location> getTableLocationMap(
		GraphicalViewer viewer, ERDiagram diagram) {
	Map<TableView, Location> tableLocationMap = new HashMap<TableView, Location>();

	ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer
			.getEditPartRegistry().get(LayerManager.ID);
	IFigure rootFigure = ((LayerManager) rootEditPart)
			.getLayer(LayerConstants.PRINTABLE_LAYERS);
	int translateX = ExportToImageAction
			.translateX(rootFigure.getBounds().x);
	int translateY = ExportToImageAction
			.translateY(rootFigure.getBounds().y);

	Category category = diagram.getCurrentCategory();

	for (Object child : rootEditPart.getContents().getChildren()) {
		NodeElementEditPart editPart = (NodeElementEditPart) child;
		NodeElement nodeElement = (NodeElement) editPart.getModel();
		if (!(nodeElement instanceof TableView)) {
			continue;
		}

		if (category == null || category.isVisible(nodeElement, diagram)) {
			IFigure figure = editPart.getFigure();
			Rectangle figureRectangle = figure.getBounds();

			Location location = new Location(
					figureRectangle.x + translateX, figureRectangle.y
							+ translateY, figureRectangle.width,
					figureRectangle.height);
			tableLocationMap.put((TableView) nodeElement, location);
		}
	}

	return tableLocationMap;
}
 
Example #30
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ReportPrintGraphicalViewerOperation( GraphicalViewer g,
		Drawable drawable, Device device, Rectangle region )
{
	this.device = device;
	this.region = region;
	this.drawable = drawable;
	this.viewer = g;

	LayerManager lm = (LayerManager) viewer.getEditPartRegistry( )
			.get( LayerManager.ID );
	IFigure f = lm.getLayer( LayerConstants.PRINTABLE_LAYERS );

	this.printSource = f;
}