Search in sources :

Example 1 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider 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 IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider 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 IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.

the class EntityLocationHyperlink method linkActivated.

public void linkActivated() {
    try {
        IEclipseContext context = (IEclipseContext) PlatformUI.getWorkbench().getService(IEclipseContext.class);
        EPartService partService = context.get(EPartService.class);
        Collection<MPart> parts = partService.getParts();
        for (MPart part : parts) {
            IEclipseContext partContext = part.getContext();
            if (partContext == null)
                continue;
            IModelInput modelInput = partContext.get(IModelInput.class);
            if (modelInput != null && ((IFilePersistenceProvider) modelInput.getPersistenceProvider()).getStore().equals(file)) {
                partService.activate(part, true);
                IEntityPartViewer viewer = partContext.get(IEntityPartViewer.class);
                IEntity entityContents = viewer.getEntityContents();
                final IEntity entity = EntityUtils.getEntity(entityContents, location);
                viewer.selectAndReveal(entity);
            }
        }
    } catch (Exception e) {
        E4CompatibilityPlugin.log(e);
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) IModelInput(org.whole.lang.ui.input.IModelInput) IEntity(org.whole.lang.model.IEntity) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 4 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.

the class ChooseModelsDialog method open.

@Override
public int open() {
    int status = super.open();
    if (status == Dialog.OK) {
        WorkflowsEntityFactory wef = WorkflowsEntityFactory.instance;
        Tuple tuple = QueriesEntityFactory.instance.createTuple(0);
        for (Object element : getResult()) try {
            IEntity model = getPersistenceKit().readModel(new IFilePersistenceProvider((IFile) element));
            tuple.wAdd(createStageUpFragment(QueriesEntityDescriptorEnum.Expression, model));
        } catch (Exception e) {
        }
        Variable variable = wef.createVariable("selectedModels");
        Expression fragment = createSameStageFragment(Expression, tuple);
        Assign assign = wef.createAssign(variable, fragment);
        assignments.wAdd(assign);
    }
    return status;
}
Also used : WorkflowsEntityFactory(org.whole.lang.workflows.factories.WorkflowsEntityFactory) Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) Expression(org.whole.lang.workflows.model.Expression) Expression(org.whole.lang.workflows.reflect.WorkflowsEntityDescriptorEnum.Expression) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) Assign(org.whole.lang.workflows.model.Assign) Tuple(org.whole.lang.queries.model.Tuple)

Example 5 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.

the class ModelInput method createPersistenceProvider.

public static IPersistenceProvider createPersistenceProvider(IEclipseContext context, String location) {
    final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("eclipse#eclipseContext", context);
    try {
        File file = new File(new URI(location));
        return new FilePersistenceProvider(file, bm);
    } catch (Exception e) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(location));
        return new IFilePersistenceProvider(file, bm);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) File(java.io.File) IFile(org.eclipse.core.resources.IFile) URI(java.net.URI)

Aggregations

IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)11 IEntity (org.whole.lang.model.IEntity)8 IFile (org.eclipse.core.resources.IFile)7 CoreException (org.eclipse.core.runtime.CoreException)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)4 File (java.io.File)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 FilePersistenceProvider (org.whole.lang.codebase.FilePersistenceProvider)3 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)3 Shell (org.eclipse.swt.widgets.Shell)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 ModelInput (org.whole.lang.e4.ui.input.ModelInput)2 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)2 IModelInput (org.whole.lang.ui.input.IModelInput)2 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1