Search in sources :

Example 1 with Refreshable

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);
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ModelListener(org.bndtools.api.ModelListener) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Refreshable(aQute.bnd.service.Refreshable) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) CoreException(org.eclipse.core.runtime.CoreException) CancellationException(java.util.concurrent.CancellationException)

Example 2 with Refreshable

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;
    }
}
Also used : RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Method(java.lang.reflect.Method) Refreshable(aQute.bnd.service.Refreshable) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 3 with Refreshable

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);
            }
        }
    });
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IStatus(org.eclipse.core.runtime.IStatus) Matcher(java.util.regex.Matcher) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Actionable(aQute.bnd.service.Actionable) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) Entry(java.util.Map.Entry) GroupMarker(org.eclipse.jface.action.GroupMarker) Menu(org.eclipse.swt.widgets.Menu) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Refreshable(aQute.bnd.service.Refreshable) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

Refreshable (aQute.bnd.service.Refreshable)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 CoreException (org.eclipse.core.runtime.CoreException)3 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PartInitException (org.eclipse.ui.PartInitException)2 Project (aQute.bnd.build.Project)1 Actionable (aQute.bnd.service.Actionable)1 RepositoryEntry (bndtools.model.repo.RepositoryEntry)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 CancellationException (java.util.concurrent.CancellationException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1 Matcher (java.util.regex.Matcher)1