Search in sources :

Example 1 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class PNGImageFileTransferDragSourceListener method createFile.

protected File createFile(IEntityPart entityPart) throws Exception {
    Image image = WholeNonResizableEditPolicy.createFeedbackImage((IGraphicalEntityPart) entityPart, 255, false, FitToMemoryStrategy.instance());
    ImageData imageData = image.getImageData();
    String fileName = ClipboardUtils.DEFAULT_OUTPUT_FILENAME;
    if (getViewer() instanceof IEntityPartViewer) {
        IBindingManager bm = ((IEntityPartViewer) getViewer()).getContextBindings();
        if (bm.wIsSet("fileName"))
            fileName = bm.wStringValue("fileName");
    }
    File file = ClipboardUtils.createTempImageFile(fileName, imageData, ClipboardUtils.DEFAULT_OUTPUT_DPI);
    image.dispose();
    return file;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) IBindingManager(org.whole.lang.bindings.IBindingManager) Image(org.eclipse.swt.graphics.Image) File(java.io.File) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 2 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class EditorPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
    getContext().set(IImportAsModelDialogFactory.class, factory);
    super.createPartControl(parent);
    getContext().get(MPart.class).setElementId("org.eclipse.e4.ui.compatibility.editor");
    setPartName(getEditorInput().getName());
    final IEntityPartViewer viewer = getComponent().getViewer();
    viewer.getCommandStack().addCommandStackEventListener(listener = new CommandStackEventListener() {

        @Override
        public void stackChanged(CommandStackEvent event) {
            if ((event.getDetail() & CommandStack.POST_MASK) != 0)
                setDirtyState(viewer.isDirty());
        }
    });
    undoAction = new UndoAction(getContext(), UNDO_LABEL);
    undoAction.update();
    redoAction = new RedoAction(getContext(), REDO_LABEL);
    redoAction.update();
    if (getEditorInput() instanceof IFileEditorInput) {
        IWorkspace workspace = ((IFileEditorInput) getEditorInput()).getFile().getWorkspace();
        workspace.addResourceChangeListener(resourceListener = new ResourceChangeListener());
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) RedoAction(org.whole.lang.e4.ui.actions.RedoAction) IWorkspace(org.eclipse.core.resources.IWorkspace) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) CommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener) CommandStackEvent(org.eclipse.gef.commands.CommandStackEvent) UndoAction(org.whole.lang.e4.ui.actions.UndoAction) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 3 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class ReplaceWithResourceAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntity focusEntity = bm.wGet("focusEntity");
    ResourceKind resourceKind = getResourceKind(focusEntity);
    Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
    boolean selectionPerformed = false;
    switch(resourceKind) {
        case WORKSPACE:
            selectionPerformed = performWorkspaceResourceSelection(shell, focusEntity);
            break;
        case CLASSPATH:
            selectionPerformed = performClasspathResourceSelection(shell, focusEntity);
            break;
        case FILE_SYSTEM:
        case URL:
            selectionPerformed = performFilesystemSelection(shell, focusEntity, resourceKind == ResourceKind.URL);
            break;
    }
    if (!selectionPerformed)
        return;
    IEntity replacement = GenericEntityFactory.instance.create(ed, path);
    ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
    try {
        mtc.setLabel("replace with class name");
        mtc.begin();
        performReplace(focusEntity, replacement);
        mtc.commit();
        if (mtc.canUndo()) {
            IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            commandStack.execute(mtc);
        }
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) CommandStack(org.eclipse.gef.commands.CommandStack) Shell(org.eclipse.swt.widgets.Shell) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 4 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class AbstractLinkableSelectionListener method isRelevant.

protected boolean isRelevant(Object selection) {
    if (!(selection instanceof IBindingManager))
        return false;
    IBindingManager actualSelection = (IBindingManager) selection;
    IEntityPartViewer selectedViewer = (IEntityPartViewer) actualSelection.wGetValue("viewer");
    if (viewer == selectedViewer)
        return false;
    lastSelection = actualSelection.clone();
    return linkType.isLinkedToActivePart() || (linkType.isLinkedToFixedPart() && selectedViewer == linkedViewer);
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 5 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class E4FindReplaceDialog method doReplaceAll.

protected void doReplaceAll() {
    IEntity self = selection.wGet("self");
    iterator.reset(self);
    if (!findNext(true))
        return;
    boolean state = enableSelectionTracking(false);
    IEntity replacement = replaceViewer.getEntityContents();
    IEntity lastReplaced = null;
    ModelTransactionCommand command = new ModelTransactionCommand();
    command.setModel(getFoundEntity());
    try {
        command.begin();
        do {
            lastReplaced = EntityUtils.clone(replacement);
            Matcher.substitute(lastReplaced, bindings, false);
            iterator.set(lastReplaced);
        } while (findNext(true));
        command.commit();
    } catch (Exception e) {
        command.rollbackIfNeeded();
    } finally {
        clearFoundEntity();
    }
    IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
    viewer.getCommandStack().execute(command);
    Control control = viewer.getControl();
    if (lastReplaced != null) {
        final IEntity revealEntity = lastReplaced;
        control.getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                boolean state = enableSelectionTracking(false);
                selectAndReveal(revealEntity);
                enableSelectionTracking(state);
            }
        });
    }
    enableSelectionTracking(state);
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) Control(org.eclipse.swt.widgets.Control) IEntity(org.whole.lang.model.IEntity) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Aggregations

IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)55 IEntity (org.whole.lang.model.IEntity)29 IBindingManager (org.whole.lang.bindings.IBindingManager)13 CommandStack (org.eclipse.gef.commands.CommandStack)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)11 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)8 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)8 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)7 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)6 Execute (org.eclipse.e4.core.di.annotations.Execute)6 Shell (org.eclipse.swt.widgets.Shell)5 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)5 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)2 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)2 Command (org.eclipse.gef.commands.Command)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Control (org.eclipse.swt.widgets.Control)2