Search in sources :

Example 1 with RepositoryElement

use of org.netxms.ui.eclipse.market.objects.RepositoryElement in project netxms by netxms.

the class RepositoryManager method markForInstallation.

/**
 * Mark selected elements for installation
 */
private void markForInstallation(boolean marked) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    for (Object o : selection.toList()) {
        if (o instanceof RepositoryElement)
            ((RepositoryElement) o).setMarked(marked);
    }
    viewer.refresh();
}
Also used : RepositoryElement(org.netxms.ui.eclipse.market.objects.RepositoryElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with RepositoryElement

use of org.netxms.ui.eclipse.market.objects.RepositoryElement in project netxms by netxms.

the class RepositoryManager method install.

/**
 * Install selected elements
 */
@SuppressWarnings("unchecked")
private void install() {
    final List<InstallData> installData = new ArrayList<InstallData>();
    ArrayList<RepositoryRuntimeInfo> repositories = (ArrayList<RepositoryRuntimeInfo>) viewer.getInput();
    for (RepositoryRuntimeInfo r : repositories) {
        List<RepositoryElement> markedElements = r.getMarkedElements();
        if (markedElements.isEmpty())
            continue;
        StringBuilder sb = new StringBuilder();
        for (RepositoryElement e : markedElements) {
            if (sb.length() == 0)
                sb.append("{ \"get-items\":[ ");
            else
                sb.append(", ");
            sb.append("{ \"guid\":\"");
            sb.append(e.getGuid().toString());
            sb.append("\", \"version\":");
            sb.append(e.getActualVersion());
            sb.append(" }");
        }
        sb.append(" ] }");
        installData.add(new InstallData(r, sb.toString()));
    }
    if (installData.isEmpty())
        return;
    actionInstall.setEnabled(false);
    new ConsoleJob("Install items from repository", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (final InstallData d : installData) {
                importFromRepository(d.repository, d.request);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        d.repository.setAllMarked(false);
                        viewer.refresh();
                    }
                });
            }
        }

        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    actionInstall.setEnabled(true);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Import failed";
        }
    }.start();
}
Also used : RepositoryElement(org.netxms.ui.eclipse.market.objects.RepositoryElement) ArrayList(java.util.ArrayList) RepositoryRuntimeInfo(org.netxms.ui.eclipse.market.objects.RepositoryRuntimeInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

RepositoryElement (org.netxms.ui.eclipse.market.objects.RepositoryElement)2 ArrayList (java.util.ArrayList)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 RepositoryRuntimeInfo (org.netxms.ui.eclipse.market.objects.RepositoryRuntimeInfo)1