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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations