Search in sources :

Example 1 with ModelInput

use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.

the class EditorPart method doSaveAs.

@Override
public void doSaveAs() {
    IEntity entityContents = getComponent().getViewer().getEntityContents();
    Set<IPersistenceKit> persistenceKits = new HashSet<IPersistenceKit>();
    for (IPersistenceKit persistenceKit : ReflectionFactory.getPersistenceKits()) if (persistenceKit.canApply(entityContents))
        persistenceKits.add(persistenceKit);
    SaveAsModelDialog dialog = new SaveAsModelDialog(getSite().getWorkbenchWindow().getShell(), getContext(), persistenceKits);
    if (dialog.open() == Dialog.CANCEL)
        return;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(dialog.getResult());
    try {
        // perform save to new file
        IFilePersistenceProvider pp = new IFilePersistenceProvider(file);
        persistenceKit.writeModel(entityContents, pp);
        // update default editor in package explorer
        IDE.setDefaultEditor(file, ReflectionFactory.getEditorIdFromPersistenceKit(persistenceKit));
        // update model input
        getContext().set(IModelInput.class, new ModelInput(getContext(), pp, persistenceKit.getId()));
        // update editor input
        setInputWithNotify(new FileEditorInput(file));
        // update editor's tab label
        setPartName(file.getName());
        // reset entity contents command stack and dirty state
        getComponent().getViewer().setEntityContents(entityContents);
    } catch (Exception e) {
        E4Utils.reportError(getContext(), "Write Model errors", StringUtils.errorMessage(e), e);
    }
}
Also used : ModelInput(org.whole.lang.e4.ui.input.ModelInput) IModelInput(org.whole.lang.ui.input.IModelInput) IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) CoreException(org.eclipse.core.runtime.CoreException) HashSet(java.util.HashSet)

Example 2 with ModelInput

use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.

the class ModelInputFunction method compute.

@Override
public Object compute(IEclipseContext context) {
    final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("eclipse#eclipseContext", context);
    final IEditorPart editorPart = context.get(IEditorPart.class);
    final IEditorInput input = context.get(IEditorInput.class);
    if (input instanceof IFileEditorInput) {
        IFile file = ((IFileEditorInput) input).getFile();
        IFilePersistenceProvider pp = new IFilePersistenceProvider(file, bm);
        ModelInput modelInput = new ModelInput(context, pp, calculateBasePersistenceKitId(file));
        if (editorPart != null) {
            String editorId = editorPart.getSite().getId();
            String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
            modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
        }
        return modelInput;
    } else if (input instanceof IURIEditorInput) {
        File file = new File(((IURIEditorInput) input).getURI());
        FilePersistenceProvider pp = new FilePersistenceProvider(file, bm);
        ModelInput modelInput = new ModelInput(context, pp, ReflectionFactory.getDefaultPersistenceKit().getId());
        if (editorPart != null) {
            String editorId = editorPart.getSite().getId();
            String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
            modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
        }
        return modelInput;
    } else
        return null;
}
Also used : ModelInput(org.whole.lang.e4.ui.input.ModelInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput)

Example 3 with ModelInput

use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.

the class AbstractE4Part method restoreState.

protected void restoreState() {
    if (part.getPersistedState().containsKey("basePersistenceKitId")) {
        String basePersistenceKitId = part.getPersistedState().get("basePersistenceKitId");
        IModelInput modelInput = new ModelInput(context, part.getPersistedState().get("filePath"), basePersistenceKitId);
        modelInput.setOverridePersistenceKitId(part.getPersistedState().get("overridePersistenceKitId"));
        updateModelInput(modelInput);
    }
}
Also used : ModelInput(org.whole.lang.e4.ui.input.ModelInput) IModelInput(org.whole.lang.ui.input.IModelInput) IModelInput(org.whole.lang.ui.input.IModelInput)

Example 4 with ModelInput

use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.

the class RevertHandler method execute.

@Execute
public void execute(EPartService partService, IModelInput modelInput, @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (E4Utils.isLegacyApplication()) {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        viewer.setContents((IModelInput) bm.wGetValue("modelInput"), null);
    } else {
        AbstractE4Part part = (AbstractE4Part) partService.getActivePart().getObject();
        part.getViewer().setContents(modelInput, null);
    }
}
Also used : AbstractE4Part(org.whole.lang.e4.ui.parts.AbstractE4Part) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with ModelInput

use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.

the class AbstractE4Part method createPartControl.

@PostConstruct
public void createPartControl(Composite parent) {
    restoreState();
    registerHandlers();
    parent.setLayout(new FillLayout());
    viewer = createEntityViewer(parent);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateSelection(E4Utils.createSelectionBindings(event, context));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

        @Override
        @SuppressWarnings("unchecked")
        public void focusGained(FocusEvent event) {
            context.set(IEntityPartViewer.class, viewer);
            context.set(ActionRegistry.class, actionRegistry);
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
        }
    });
    viewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    context.set(IEntityPartViewer.class, viewer);
    viewer.setKeyHandler(keyHandler);
    viewer.setContents(modelInput, createDefaultContents());
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    actionRegistry.registerKeyActions(viewer.getKeyHandler());
    context.set(ActionRegistry.class, actionRegistry);
    configureContextMenu();
    if (!E4Utils.isLegacyApplication())
        viewer.getCommandStack().addCommandStackEventListener(new CommandStackEventListener() {

            @Override
            public void stackChanged(CommandStackEvent event) {
                if ((event.getDetail() & CommandStack.POST_MASK) != 0)
                    part.setDirty(viewer.isDirty());
            }
        });
    reloader = new LazyConfirmationDialogReloader(viewer.getControl(), new Runnable() {

        @Override
        public void run() {
            viewer.setContents(modelInput, null);
        }
    });
}
Also used : LazyConfirmationDialogReloader(org.whole.lang.ui.dialogs.LazyConfirmationDialogReloader) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) CommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) CommandStackEvent(org.eclipse.gef.commands.CommandStackEvent) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ModelInput (org.whole.lang.e4.ui.input.ModelInput)3 IFile (org.eclipse.core.resources.IFile)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)2 IModelInput (org.whole.lang.ui.input.IModelInput)2 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)2 File (java.io.File)1 HashSet (java.util.HashSet)1 PostConstruct (javax.annotation.PostConstruct)1 CoreException (org.eclipse.core.runtime.CoreException)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 CommandStackEvent (org.eclipse.gef.commands.CommandStackEvent)1 CommandStackEventListener (org.eclipse.gef.commands.CommandStackEventListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1