use of eu.esdihumboldt.hale.ui.service.project.RecentResources in project hale by halestudio.
the class FileSourceFileFieldEditor method setContentTypes.
@Override
public void setContentTypes(Set<IContentType> types) {
super.setContentTypes(types);
RecentResources rr = PlatformUI.getWorkbench().getService(RecentResources.class);
if (rr != null) {
final List<Pair<URI, IContentType>> files = rr.getRecent(types, true);
if (!files.isEmpty()) {
historyButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Menu filesMenu = new Menu(historyButton);
for (Pair<URI, IContentType> pair : files) {
final File file;
try {
file = new File(pair.getFirst());
if (file.exists()) {
// only offer existing files
MenuItem item = new MenuItem(filesMenu, SWT.PUSH);
item.setText(RecentProjectsMenu.shorten(file.toString(), 80, file.getName().length()));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = processFile(file);
if (text != null) {
getTextControl().setText(text);
getTextControl().setFocus();
valueChanged();
}
}
});
}
} 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.hale.ui.service.project.RecentResources 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);
}
}
}
Aggregations