use of org.whole.lang.codebase.StringPersistenceProvider in project whole by wholeplatform.
the class ActionFactory method createAddFragmentAction.
public IUpdatableAction createAddFragmentAction(String label, IEntity predicate, IEntity fragment) {
try {
Map<String, Object> parameters = new HashMap<String, Object>();
StringPersistenceProvider spp = new StringPersistenceProvider();
ReflectionFactory.getDefaultPersistenceKit().writeModel(fragment, spp);
parameters.put(FRAGMENT_XWL_PARAMETER_ID, spp.getStore());
spp = new StringPersistenceProvider();
ReflectionFactory.getDefaultPersistenceKit().writeModel(predicate, spp);
parameters.put(PREDICATE_XWL_PARAMETER_ID, spp.getStore());
return createE4ActionAdapter(label, ADD_ICON_URI, ADD_FRAGMENT_COMMAND_ID, parameters);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
use of org.whole.lang.codebase.StringPersistenceProvider in project whole by wholeplatform.
the class FragmentModelTransactionHandler method defineBindings.
protected void defineBindings(String fragmentXwl, String predicateXwl, IBindingManager bm) throws Exception {
IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
bm.wDef("fragmentEntity", persistenceKit.readModel(new StringPersistenceProvider(fragmentXwl)));
bm.wDef("predicateEntity", persistenceKit.readModel(new StringPersistenceProvider(predicateXwl)));
}
use of org.whole.lang.codebase.StringPersistenceProvider in project whole by wholeplatform.
the class ClipboardUtils method parseClipboardContents.
public static IEntity parseClipboardContents(IPersistenceKit persistenceKit, IBindingManager bm) throws Exception {
IEntity entity = Clipboard.instance().getEntityContents();
if (entity != null && ReflectionFactory.getDefaultPersistenceKit().equals(persistenceKit)) {
if (EntityUtils.isTuple(entity))
bm.wDef("syntheticRoot", entity);
return entity;
} else {
String text;
if (entity != null) {
StringBuilder sb = new StringBuilder(1024);
for (int i = 0; i < entity.wSize(); i++) sb.append(PrettyPrinterOperation.toPrettyPrintString(entity.wGet(i)));
text = sb.toString();
} else
text = Clipboard.instance().getTextContents();
if (text == null)
throw new IllegalStateException("no clipboard contents");
bm.wDefValue("parseFragments", true);
return persistenceKit.readModel(new StringPersistenceProvider(text, bm));
}
}
use of org.whole.lang.codebase.StringPersistenceProvider in project whole by wholeplatform.
the class JSONPersistencesTest method testParseAndGenerateWithBuilderOperation.
@Test
public void testParseAndGenerateWithBuilderOperation() throws Exception {
IEntity sampleModel = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
StringPersistenceProvider pp = new StringPersistenceProvider();
JsonGenerator generator = new JsonFactory().createGenerator(pp.getOutputStream());
generator.useDefaultPrettyPrinter();
JSONGeneratorBuilderOperation op = new JSONGeneratorBuilderOperation(generator);
new ModelTemplate(sampleModel).apply(op);
generator.close();
assertEquals(sampleString, pp.getStore());
}
use of org.whole.lang.codebase.StringPersistenceProvider in project whole by wholeplatform.
the class TextTransferDropTargetListener method getCommand.
@Override
protected Command getCommand() {
String text = (String) getCurrentEvent().data;
Shell shell = getViewer().getControl().getShell();
IImportAsModelDialog dialog = factory.createImplicitElementImportAsModelDialog(shell, "Drop As", false);
if (!dialog.show())
return null;
IPersistenceKit persistenceKit = dialog.getPersistenceKit();
EntityDescriptor<?> stage = dialog.getStage();
try {
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("parseFragments", true);
IEntity entity = persistenceKit.readModel(new StringPersistenceProvider(text, bm));
// FIXME workaround for selections with multiple entities
if (EntityUtils.isTuple(entity))
bm.wDef("syntheticRoot", entity);
boolean hasSyntheticRoot = bm.wIsSet("syntheticRoot");
IEntityIterator<IEntity> iterator;
boolean needsCompositeTarget = false;
if (hasSyntheticRoot) {
IEntity syntheticRoot = bm.wGet("syntheticRoot");
iterator = IteratorFactory.childIterator();
iterator.reset(syntheticRoot);
needsCompositeTarget = syntheticRoot.wSize() > 1;
} else {
iterator = IteratorFactory.selfIterator();
iterator.reset(entity);
}
List<IEntityPart> editParts = new ArrayList<IEntityPart>();
while (iterator.hasNext()) {
IEntity stageEntity = EntityUtils.clone(iterator.next());
stageEntity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, stageEntity, needsCompositeTarget);
editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), stageEntity));
}
ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
request.setEditParts(editParts);
return super.getCommand();
} catch (Exception e) {
return null;
}
}
Aggregations