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