Search in sources :

Example 1 with IPersistenceKit

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

the class ReflectionFactory method updatePersistenceAndEditorKits.

public static void updatePersistenceAndEditorKits(ILanguageKit languageKit) {
    InternalILanguageKit internalILanguageKit = (InternalILanguageKit) languageKit;
    for (IPersistenceKit persistenceKit : getPersistenceKits()) if (persistenceKit.canApply(languageKit))
        internalILanguageKit.addPersistenceKit(persistenceKit);
    else
        internalILanguageKit.removePersistenceKit(persistenceKit);
    for (IEditorKit editorKit : getEditorKits()) if (editorKit.canApply(languageKit))
        internalILanguageKit.addEditorKit(editorKit);
    else
        internalILanguageKit.removeEditorKit(editorKit);
}
Also used : IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 2 with IPersistenceKit

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

the class TargetModelBlock method createContents.

@Override
protected void createContents(Composite composite) {
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    int widthHint = UIUtils.getButtonWidthHint(composite);
    browseChooser = new WholeModelBrowseChooser(composite, SWT.NONE, widthHint);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 300;
    browseChooser.setLayoutData(gd);
    browseChooser.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            IFile file = browseChooser.getFile();
            if (file != null)
                modelPath = file.getFullPath().toPortableString();
            IPersistenceKit persistenceKit = browseChooser.getPersistenceKit();
            if (persistenceKit != null)
                persistenceKitId = persistenceKit.getId();
            updateLaunchConfiguration();
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) IFile(org.eclipse.core.resources.IFile) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) WholeModelBrowseChooser(org.whole.lang.ui.controls.WholeModelBrowseChooser) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 3 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit 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 4 with IPersistenceKit

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

the class ModelMergeViewer method readSideModel.

protected void readSideModel(MergeSide side, Object input, String label) {
    IEntity sideModel = null;
    if (input != null)
        try {
            IStreamContentAccessor accessor = (IStreamContentAccessor) input;
            // TODO
            IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
            sideModel = persistenceKit.readModel(new StreamPersistenceProvider(accessor.getContents()));
        } catch (Exception e) {
            E4Utils.reportError(getContext(), "Model Merge Viewer", "Unable to read the model", e);
        // TODO ? sideModel = Status model instance with failure info
        }
    setSideModel(side, sideModel != null ? sideModel : CommonsEntityFactory.instance.createResolver(), label);
}
Also used : IEntity(org.whole.lang.model.IEntity) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 5 with IPersistenceKit

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

the class ModelMergeViewer method getSideModelBytes.

protected byte[] getSideModelBytes(MergeSide side) {
    try {
        // TODO
        IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        persistenceKit.writeModel(getSideModel(side), new StreamPersistenceProvider(baos));
        return baos.toByteArray();
    } catch (Exception e) {
        throw new IllegalStateException("cannot gather contents of " + side.name().toLowerCase() + " pane", e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Aggregations

IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)33 IEntity (org.whole.lang.model.IEntity)13 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)7 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)6 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 GridData (org.eclipse.swt.layout.GridData)4 Shell (org.eclipse.swt.widgets.Shell)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)4 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)4 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)4 ParseException (org.whole.lang.parsers.ParseException)4 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)4 MissingVariableException (org.whole.lang.visitors.MissingVariableException)4 VisitException (org.whole.lang.visitors.VisitException)4 ArrayList (java.util.ArrayList)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Label (org.eclipse.swt.widgets.Label)3