Search in sources :

Example 36 with IEntityPartViewer

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

the class HandlersBehavior method copyAsImage.

public static void copyAsImage(IBindingManager bm) {
    E4Utils.syncExec(bm, () -> {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity focusEntity = bm.wGet("focusEntity");
        IEntityPart part = viewer.getEditPartRegistry().get(focusEntity);
        String fileName = bm.wIsSet("fileName") ? bm.wStringValue("fileName") : ClipboardUtils.DEFAULT_OUTPUT_FILENAME;
        Clipboard.instance().setImageContents(fileName, (IGraphicalEntityPart) part);
    });
}
Also used : IEntity(org.whole.lang.model.IEntity) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 37 with IEntityPartViewer

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

the class HandlersBehavior method importEntity.

public static void importEntity(IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    IEntity focusEntity = bm.wGet("focusEntity");
    RunnableWithResult<IImportAsModelDialog> runnable = RunnableWithResult.create(() -> {
        Shell shell = viewer.getControl().getShell();
        IEclipseContext eclipseContext = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
        IImportAsModelDialog dialog = eclipseContext.get(IImportAsModelDialogFactory.class).createImportAsModelDialog(shell, "Import model", EntityUtils.isComposite(focusEntity));
        dialog.show();
        return dialog;
    });
    E4Utils.syncExec(bm, runnable);
    IImportAsModelDialog dialog = runnable.get();
    if (!dialog.isConfirmed())
        return;
    Object[] files = dialog.getSelection();
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    boolean adding = dialog.isForceAdding() || files.length > 1;
    for (int i = files.length - 1; i >= 0; i--) {
        IPersistenceProvider pp = new IFilePersistenceProvider((IFile) files[i]);
        try {
            IEntity importedEntity = persistenceKit.readModel(pp);
            if (!adding) {
                if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isReplaceable(focusEntity, importedEntity))
                    importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
                IEntity parent = focusEntity.wGetParent();
                parent.wSet(focusEntity, importedEntity);
                break;
            } else {
                if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isAddable(focusEntity, importedEntity))
                    importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
                if (bm.wIsSet("hilightPosition"))
                    focusEntity.wAdd(bm.wIntValue("hilightPosition"), importedEntity);
                else
                    focusEntity.wAdd(importedEntity);
            }
        } catch (Exception e) {
        // fail silently
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 38 with IEntityPartViewer

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

the class ClearContentsAction method run.

@Override
public void run() {
    IEntityPartViewer viewer = getContext().get(IEntityPartViewer.class);
    viewer.setContents(null, createDefaultContents());
    update();
}
Also used : IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 39 with IEntityPartViewer

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

the class ClearContentsAction method update.

@Override
public void update() {
    IEntityPartViewer viewer = getContext().get(IEntityPartViewer.class);
    setEnabled(viewer.hasContents());
}
Also used : IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 40 with IEntityPartViewer

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

the class AbstractModelTextAction method calculateEnabled.

protected boolean calculateEnabled(IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    if (!Tools.TEXTUAL.isActive(viewer) || !(ModelObserver.getObserver(bm.wGet("focusEntity"), viewer.getEditPartRegistry()) instanceof ITextualEntityPart))
        return false;
    IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
    ISynchronizableRunnable runnable = new FunctionRunnable(context, bm, getText(), getEnablementUri());
    IEntity result = runnable.syncExec(3000).getResult();
    return result != null && result.wBooleanValue();
}
Also used : ISynchronizableRunnable(org.whole.lang.e4.ui.jobs.ISynchronizableRunnable) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) FunctionRunnable(org.whole.lang.e4.ui.jobs.FunctionRunnable) TextualFunctionRunnable(org.whole.lang.e4.ui.jobs.TextualFunctionRunnable) 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