Search in sources :

Example 6 with FilePersistenceProvider

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());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 7 with FilePersistenceProvider

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

File (java.io.File)7 FilePersistenceProvider (org.whole.lang.codebase.FilePersistenceProvider)7 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IFile (org.eclipse.core.resources.IFile)3 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)3 IEntity (org.whole.lang.model.IEntity)3 Test (org.junit.Test)2 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 EditPart (org.eclipse.gef.EditPart)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1