Search in sources :

Example 16 with StringPersistenceProvider

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);
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) HashMap(java.util.HashMap)

Example 17 with StringPersistenceProvider

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)));
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 18 with StringPersistenceProvider

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));
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity)

Example 19 with StringPersistenceProvider

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());
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONGeneratorBuilderOperation(org.whole.lang.json.util.JSONGeneratorBuilderOperation) Test(org.junit.Test)

Example 20 with StringPersistenceProvider

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;
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Aggregations

StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)20 IEntity (org.whole.lang.model.IEntity)10 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 CoreException (org.eclipse.core.runtime.CoreException)2 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)2 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ArrayList (java.util.ArrayList)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 Shell (org.eclipse.swt.widgets.Shell)1 IBindingScope (org.whole.lang.bindings.IBindingScope)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 JSONGeneratorBuilderOperation (org.whole.lang.json.util.JSONGeneratorBuilderOperation)1 Model (org.whole.lang.models.model.Model)1 PathExpression (org.whole.lang.queries.model.PathExpression)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1