Search in sources :

Example 21 with IPersistenceProvider

use of org.whole.lang.codebase.IPersistenceProvider 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;
}
Also used : IFile(org.eclipse.core.resources.IFile) Resolver(org.whole.lang.commons.model.Resolver) Content(org.whole.lang.artifacts.model.Content) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) CoreException(org.eclipse.core.runtime.CoreException)

Example 22 with IPersistenceProvider

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

the class FileTransferDropTargetListener method getCommand.

@Override
protected Command getCommand() {
    String[] filePaths = (String[]) getCurrentEvent().data;
    List<EditPart> editParts = new ArrayList<EditPart>();
    Shell shell = getViewer().getControl().getShell();
    IImportAsModelDialog dialog = factory.createElementListImportAsModelDialog(shell, "DnD Import", false);
    String[] fileNames = new String[filePaths.length];
    for (int i = 0; i < fileNames.length; i++) fileNames[i] = filePaths[i].substring(filePaths[i].lastIndexOf(File.separatorChar) + 1);
    dialog.setSelection(fileNames);
    if (!dialog.show())
        return null;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    boolean needsCompositeTarget = filePaths.length > 1;
    for (String filePath : filePaths) {
        try {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            File file = new File(filePath);
            IFile[] files = workspace.getRoot().findFilesForLocationURI(file.toURI());
            IPersistenceProvider persistenceProvider = (files.length == 1) ? new IFilePersistenceProvider(files[0]) : new FilePersistenceProvider(file);
            IEntity entity = persistenceKit.readModel(persistenceProvider);
            entity = ClipboardUtils.conditionalStageAdd(getTargetEditPart(), stage, entity, needsCompositeTarget);
            editParts.add(ClipboardUtils.createEditPart(getViewer().getEditPartFactory(), entity));
        } catch (Exception e) {
        // fail silently
        }
    }
    if (!editParts.isEmpty()) {
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        request.setEditParts(editParts);
    } else
        return null;
    return super.getCommand();
}
Also used : IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IWorkspace(org.eclipse.core.resources.IWorkspace) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)22 IEntity (org.whole.lang.model.IEntity)15 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Schema (javax.xml.validation.Schema)9 Validator (javax.xml.validation.Validator)9 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)9 Category (org.junit.experimental.categories.Category)8 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)7 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 Shell (org.eclipse.swt.widgets.Shell)2 IBindingManager (org.whole.lang.bindings.IBindingManager)2 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)2 ParseException (org.whole.lang.parsers.ParseException)2