use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.
the class WorkspaceArtifactsGeneratorVisitor method visitFileArtifact.
public void visitFileArtifact(FileArtifact entity) {
env().wEnterScope();
entity.getName().accept(this);
if (!env().wIsSet("name"))
throw new VisitException("No File name");
String fileNameWithExtension = env().wStringValue("name");
if (!ResourcesPlugin.getWorkspace().validateName(fileNameWithExtension, IResource.FILE).isOK())
throw new VisitException("Invalid File name");
env().wDefValue("fileNameWithExtension", fileNameWithExtension);
env().wDefValue("fileName", StringUtils.stripFileExtension(fileNameWithExtension));
env().wDefValue("fileExtension", StringUtils.getFileExtension(fileNameWithExtension));
entity.getMetadata().accept(this);
IFile file;
if (env().wIsSet("folder")) {
IFolder folder = (IFolder) env().wGetValue("folder");
file = folder.getFile(fileNameWithExtension);
} else {
IProject project = (IProject) env().wGetValue("project");
file = project.getFile(fileNameWithExtension);
}
env().wDefValue("persistenceProvider", new IFilePersistenceProvider(file, env()));
IEntity result = InterpreterOperation.interpret(entity.getContent(), env()).getResult();
try {
if (result != null)
writeContents(result);
} catch (Exception e) {
throw new VisitException(e);
}
env().wExitScope();
}
use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.
the class WholeOperationLaunchConfigurationDelegate method launch.
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (!"run".equals(mode))
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "Only 'run' mode supported by this launcher", null));
String operationId = configuration.getAttribute(OPERATION_ID, (String) null);
if (operationId == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No operation selected", null));
String targetModelPath = configuration.getAttribute(TARGET_MODEL_PATH, (String) null);
if (targetModelPath == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No target model selected", null));
String targetModelPersistence = configuration.getAttribute(TARGET_MODEL_PERSISTENCE, (String) null);
if (targetModelPersistence == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No persistence selected", null));
try {
monitor.beginTask("Executing " + operationId + " operation...", 100);
if (monitor.isCanceled())
return;
IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
IFile targetModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(targetModelPath));
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
ResourceUtils.defineResourceBindings(bindings, targetModelFile);
IBindingScope scope = LaunchConfigurationUtils.loadBindingScope(configuration);
bindings.wEnterScope(scope, true);
IPersistenceKit persistenceKit = ReflectionFactory.getPersistenceKit(targetModelPersistence);
IEntity model = persistenceKit.readModel(new IFilePersistenceProvider(targetModelFile));
IOperationLauncher operationLauncher = OperationLauncherRegistry.instance.getOperationLauncher(operationId);
InputStream is = System.in;
OutputStream os = System.out;
if (configuration.getAttribute(CONSOLE_VIEW, false)) {
IOConsole ioConsole = WholeConsoleFactory.getIOConsole();
is = ioConsole.getInputStream();
os = ioConsole.newOutputStream();
}
operationLauncher.launch(model, bindings, is, os, operationProgressMonitor);
if (configuration.getAttribute(PERSIST_CHANGES, false))
persistenceKit.writeModel(model, new IFilePersistenceProvider(targetModelFile));
} catch (Throwable t) {
WholePlugin.log(t);
} finally {
monitor.done();
}
}
use of org.whole.lang.codebase.IFilePersistenceProvider 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
}
}
}
use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.
the class ArtifactsWorkspaceUtils method getContents.
public static IEntity getContents(FileArtifact fileArtifact, String persistenceKitId) {
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
bindPath(fileArtifact, bindings, false);
IFile file = (IFile) bindings.wGetValue("file");
final IPersistenceProvider pp = new IFilePersistenceProvider(file);
final Resolver resolver = CommonsEntityFactory.instance.createResolver();
final Content fragment = CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, resolver);
try {
fragment.wSet(0, ReflectionFactory.getPersistenceKit(persistenceKitId).readModel(pp));
} catch (Exception e) {
}
return fragment;
}
use of org.whole.lang.codebase.IFilePersistenceProvider in project whole by wholeplatform.
the class AbstractWizardWholeModelImportPage method createNewFile.
protected boolean createNewFile(IFile fileHandle) {
IEntity model = buildModel();
persistenceKit = getPersistenceKit(presistenceTypes);
try {
persistenceKit.writeModel(model, new IFilePersistenceProvider(fileHandle));
return true;
} catch (Exception e) {
IEclipseContext context = (IEclipseContext) PlatformUI.getWorkbench().getService(IEclipseContext.class);
E4Utils.reportError(context, "Write Model errors", StringUtils.errorMessage(e), e);
return false;
}
}
Aggregations