Search in sources :

Example 11 with IFilePersistenceProvider

use of org.whole.lang.codebase.IFilePersistenceProvider 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

IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)11 IEntity (org.whole.lang.model.IEntity)8 IFile (org.eclipse.core.resources.IFile)7 CoreException (org.eclipse.core.runtime.CoreException)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)4 File (java.io.File)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 FilePersistenceProvider (org.whole.lang.codebase.FilePersistenceProvider)3 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)3 Shell (org.eclipse.swt.widgets.Shell)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 ModelInput (org.whole.lang.e4.ui.input.ModelInput)2 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)2 IModelInput (org.whole.lang.ui.input.IModelInput)2 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1