use of aQute.bnd.service.Refreshable in project bndtools by bndtools.
the class Central method refreshPlugins.
public static void refreshPlugins() throws Exception {
List<File> refreshedFiles = new ArrayList<File>();
List<Refreshable> rps = getWorkspace().getPlugins(Refreshable.class);
boolean changed = false;
boolean repoChanged = false;
for (Refreshable rp : rps) {
if (rp.refresh()) {
changed = true;
File root = rp.getRoot();
if (root != null)
refreshedFiles.add(root);
if (rp instanceof RepositoryPlugin) {
repoChanged = true;
}
}
}
if (changed) {
try {
for (File file : refreshedFiles) {
refreshFile(file);
}
for (Project p : Central.getWorkspace().getAllProjects()) {
p.setChanged();
for (ModelListener l : getInstance().listeners) l.modelChanged(p);
}
if (repoChanged) {
repositoriesViewRefresher.repositoriesRefreshed();
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
use of aQute.bnd.service.Refreshable in project bndtools by bndtools.
the class RepositoriesView method performDrop.
/**
* Try a drop on the target. A drop is allowed if the target implements a {@code dropTarget} method that returns a
* boolean.
*
* @param target the target being dropped upon
* @param data the data
* @param data2
* @return true if dropped and processed, false if not
*/
boolean performDrop(Object target, TransferData data, Object dropped) {
try {
Object java = toJava(data);
if (java == null) {
java = toJava(dropped);
if (java == null)
return false;
}
try {
Method m = target.getClass().getMethod(DROP_TARGET, java.getClass());
Boolean invoke = (Boolean) m.invoke(target, java);
if (!invoke)
return false;
} catch (NoSuchMethodException e) {
return false;
}
RepositoryPlugin repositoryPlugin = getRepositoryPlugin(target);
if (repositoryPlugin != null && repositoryPlugin instanceof Refreshable)
Central.refreshPlugin((Refreshable) repositoryPlugin);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of aQute.bnd.service.Refreshable in project bndtools by bndtools.
the class RepositoriesView method createContextMenu.
void createContextMenu() {
MenuManager mgr = new MenuManager();
Menu menu = mgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
getSite().registerContextMenu(mgr, viewer);
mgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
try {
manager.removeAll();
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (!selection.isEmpty()) {
final Object firstElement = selection.getFirstElement();
if (firstElement instanceof Actionable) {
final RepositoryPlugin rp = getRepositoryPlugin(firstElement);
//
// Use the Actionable interface to fill the menu
// Should extend this to allow other menu entries
// from the view, but currently there are none
//
final Actionable act = (Actionable) firstElement;
Map<String, Runnable> actions = act.actions();
if (actions != null) {
for (final Entry<String, Runnable> e : actions.entrySet()) {
String label = e.getKey();
boolean enabled = true;
boolean checked = false;
String description = null;
Matcher m = LABEL_PATTERN.matcher(label);
if (m.matches()) {
if (m.group(1) != null)
enabled = false;
if (m.group(2) != null)
checked = true;
label = m.group(3);
description = m.group(4);
}
Action a = new Action(label.replace("&", "&&")) {
@Override
public void run() {
Job backgroundJob = new Job("Repository Action '" + getText() + "'") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
e.getValue().run();
if (rp != null && rp instanceof Refreshable)
Central.refreshPlugin((Refreshable) rp);
} catch (final Exception e) {
IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error executing: " + getName(), e);
Plugin.getDefault().getLog().log(status);
}
monitor.done();
return Status.OK_STATUS;
}
};
backgroundJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
viewer.getTree().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.refresh();
}
});
}
}
});
backgroundJob.setUser(true);
backgroundJob.setPriority(Job.SHORT);
backgroundJob.schedule();
}
};
a.setEnabled(enabled);
if (description != null)
a.setDescription(description);
a.setChecked(checked);
manager.add(a);
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
Aggregations