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();
}
Aggregations