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