Search in sources :

Example 31 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class TransformationView method update.

/**
 * Set the current alignment
 */
private void update() {
    final Display display = PlatformUI.getWorkbench().getDisplay();
    // TODO add configuration option if instances should be included?
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
            Collection<Instance> instances = iss.getReferenceInstances();
            if (instanceAction.isChecked()) {
                if (instances != null && !instances.isEmpty()) {
                    instances = new ArrayList<Instance>(instances);
                    // alignment paired with instances as input
                    getViewer().setInput(new Pair<Object, Object>(alignment, instances));
                } else {
                    getViewer().setInput(null);
                }
            } else {
                // only the alignment as input
                getViewer().setInput(alignment);
            }
            getViewer().applyLayout();
        }
    });
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display) Pair(eu.esdihumboldt.util.Pair)

Example 32 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class URLSourceURIFieldEditor method setContentTypes.

/**
 * Set the allowed content types and enable the history button if
 * applicable.
 *
 * @param types the supported content types
 */
public void setContentTypes(Set<IContentType> types) {
    RecentResources rr = PlatformUI.getWorkbench().getService(RecentResources.class);
    if (rr != null) {
        Predicate<URI> selectUris = new Predicate<URI>() {

            @Override
            public boolean apply(URI uri) {
                // exclude files
                return !"file".equals(uri.getScheme());
            }
        };
        if (filter != null) {
            selectUris = Predicates.and(selectUris, filter);
        }
        final List<Pair<URI, IContentType>> locations = rr.getRecent(types, selectUris);
        if (!locations.isEmpty()) {
            historyButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Menu filesMenu = new Menu(historyButton);
                    for (Pair<URI, IContentType> pair : locations) {
                        final URI location = pair.getFirst();
                        final IContentType contentType = pair.getSecond();
                        try {
                            MenuItem item = new MenuItem(filesMenu, SWT.PUSH);
                            item.setText(RecentProjectsMenu.shorten(location.toString(), 80, 20));
                            item.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    getTextControl().setText(location.toString());
                                    getTextControl().setFocus();
                                    valueChanged();
                                    onHistorySelected(location, contentType);
                                }
                            });
                        } catch (Exception e1) {
                        // ignore
                        }
                    }
                    Point histLoc = historyButton.getParent().toDisplay(historyButton.getLocation());
                    filesMenu.setLocation(histLoc.x, histLoc.y + historyButton.getSize().y);
                    filesMenu.setVisible(true);
                }
            });
            historyButton.setEnabled(true);
        }
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IContentType(org.eclipse.core.runtime.content.IContentType) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) URI(java.net.URI) Predicate(com.google.common.base.Predicate) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RecentProjectsMenu(eu.esdihumboldt.hale.ui.service.project.RecentProjectsMenu) Menu(org.eclipse.swt.widgets.Menu) RecentResources(eu.esdihumboldt.hale.ui.service.project.RecentResources) Pair(eu.esdihumboldt.util.Pair)

Example 33 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class AbstractResourceScavenger method reserveResource.

@Override
public Pair<String, File> reserveResource(String desiredId) throws ScavengerException {
    if (!allowAddResource()) {
        throw new ScavengerException("Adding a resource not allowed.");
    }
    // trigger a scan to be up-to-date
    triggerScan();
    synchronized (resources) {
        // normalize desired identifier
        if (desiredId != null) {
            // replace spaces by -
            desiredId = desiredId.replaceAll("\\s+", "-");
            // remove all non-word characters (except -)
            desiredId = desiredId.replaceAll("[^a-zA-Z0-9_\\-]", "");
            // might be run on windows
            desiredId = desiredId.toLowerCase();
            if (desiredId.isEmpty()) {
                // empty string not allowed
                desiredId = null;
            }
        }
        String id;
        if (desiredId != null && !resources.containsKey(desiredId) && !reserved.contains(desiredId)) {
            // desired ID is OK
            id = desiredId;
        } else {
            if (desiredId != null) {
                // try postfix
                int num = 2;
                String testId = desiredId + num;
                while (resources.containsKey(testId) || reserved.contains(testId)) {
                    testId = desiredId + (++num);
                }
                id = testId;
            } else {
                // try numeric identifiers
                int num = 1;
                String testId = String.valueOf(num);
                while (resources.containsKey(testId) || reserved.contains(testId)) {
                    testId = String.valueOf(++num);
                }
                id = testId;
            }
        }
        reserved.add(id);
        File projectFolder = new File(huntingGrounds, id);
        if (!projectFolder.exists()) {
            // try creating the directory
            try {
                projectFolder.mkdir();
            } catch (Exception e) {
                throw new ScavengerException("Could not create project directory", e);
            }
        }
        if (!projectFolder.exists()) {
            throw new ScavengerException("Could not create project directory");
        }
        return new Pair<String, File>(id, projectFolder);
    }
}
Also used : File(java.io.File) IOException(java.io.IOException) Pair(eu.esdihumboldt.util.Pair)

Aggregations

Pair (eu.esdihumboldt.util.Pair)33 ArrayList (java.util.ArrayList)11 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 List (java.util.List)7 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 Entity (eu.esdihumboldt.hale.common.align.model.Entity)4 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)4 Group (eu.esdihumboldt.hale.common.instance.model.Group)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Point (org.eclipse.swt.graphics.Point)4 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)3 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)3 IOException (java.io.IOException)3 URI (java.net.URI)3 Collection (java.util.Collection)3 QName (javax.xml.namespace.QName)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3