use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class XsdLanguageTest method testXsdPersistence.
@Category(SlowTests.class)
@Test
public void testXsdPersistence() {
File file = null;
try {
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
File folder = new File("test/org/whole/lang/xsd/util");
bm.wDefValue("folderLocation", folder.getAbsolutePath());
bm.wDefValue("packageName", "");
FilenameFilter xsdFilenameFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".xsd");
}
};
for (File f : folder.listFiles(xsdFilenameFilter)) XsdPersistenceKit.instance().readModel(new FilePersistenceProvider(file = f, bm));
folder = new File("test/org/whole/lang/xsd/util/xsd");
bm.wDefValue("folderLocation", folder.getAbsolutePath());
bm.wDefValue("packageName", "");
for (File f : folder.listFiles(xsdFilenameFilter)) XsdPersistenceKit.instance().readModel(new FilePersistenceProvider(file = f, bm));
} catch (Exception e) {
Assert.fail("Cannot load " + file + " cause:\n" + e.getMessage());
}
}
use of org.whole.lang.codebase.FilePersistenceProvider 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