/** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ILazyTreeContentProvider#updateElement(java.lang.Object, int) */ @Override public void updateElement(final Object parent, final int index) { getServerManager(); // make sure server manager has been set if (parent == this.serverManager) { final ModeShapeServer server = new ArrayList<ModeShapeServer>(this.serverManager.getServers()).get(index); this.viewer.replace(this.serverManager, index, server); this.viewer.setHasChildren(server, true); } else if (parent instanceof ModeShapeServer) { final ModeShapeServer server = (ModeShapeServer) parent; if (isOkToConnect(server)) { try { final ModeShapeRepository repository = new ArrayList<ModeShapeRepository>(this.serverManager.getRepositories(server)) .get(index); this.viewer.replace(server, index, repository); this.viewer.setHasChildren(repository, true); } catch (final Exception e) { addOfflineServer(server); } } } else if (parent instanceof ModeShapeRepository) { final ModeShapeRepository repository = (ModeShapeRepository) parent; if (isOkToConnect(repository.getServer())) { try { final ModeShapeWorkspace workspace = new ArrayList<ModeShapeWorkspace>(this.serverManager.getWorkspaces(repository)) .get(index); this.viewer.replace(repository, index, workspace); } catch (final Exception e) { addOfflineServer(repository.getServer()); } } } }
/** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ILazyTreeContentProvider#updateChildCount(java.lang.Object, int) */ @Override public void updateChildCount(final Object element, final int currentChildCount) { getServerManager(); // make sure server manager has been set if (element == this.serverManager) { final Collection<ModeShapeServer> servers = this.serverManager.getServers(); if (servers.size() != currentChildCount) { this.viewer.setChildCount(element, servers.size()); } if (_alreadyCalledByFramework) { updateElement(element, 0); } else { _alreadyCalledByFramework = true; } } else if (element instanceof ModeShapeServer) { final ModeShapeServer server = (ModeShapeServer) element; if (isOkToConnect(server)) { try { final ServerOperation op = new ServerOperation(server) { /** * {@inheritDoc} * * @see * org.jboss.tools.modeshape.rest.views.ModeShapeContentProvider.ServerOperation#doRun(org.eclipse.core.runtime.IProgressMonitor) */ @Override void doRun(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor.isCanceled()) { throw new InterruptedException(); } monitor.beginTask( RestClientI18n.runningRepositoriesQueryMsg, IProgressMonitor.UNKNOWN); final ModeShapeServer serverToQuery = ((getUpdatedServer() == null) ? server : getUpdatedServer()); try { final Collection<ModeShapeRepository> repositories = getServerManager().getRepositories(serverToQuery); if (repositories.size() != currentChildCount) { getViewer().setChildCount(serverToQuery, repositories.size()); } } catch (final Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } /** * {@inheritDoc} * * @see * org.jboss.tools.modeshape.rest.views.ModeShapeContentProvider.ServerOperation#getDisplay() */ @Override Display getDisplay() { return getViewer().getTree().getDisplay(); } }; run(op, true); } catch (final Exception e) { addOfflineServer(server); } } } else if (element instanceof ModeShapeRepository) { final ModeShapeRepository repository = (ModeShapeRepository) element; if (isOkToConnect(repository.getServer())) { try { final ServerOperation op = new ServerOperation(repository.getServer()) { /** * {@inheritDoc} * * @see * org.jboss.tools.modeshape.rest.views.ModeShapeContentProvider.ServerOperation#doRun(org.eclipse.core.runtime.IProgressMonitor) */ @Override void doRun(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor.isCanceled()) { throw new InterruptedException(); } monitor.beginTask( RestClientI18n.runningWorkspacesQueryMsg, IProgressMonitor.UNKNOWN); try { final Collection<ModeShapeWorkspace> workspaces = getServerManager().getWorkspaces(repository); if (workspaces.size() != currentChildCount) { getViewer().setChildCount(repository, workspaces.size()); } } catch (final Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } /** * {@inheritDoc} * * @see * org.jboss.tools.modeshape.rest.views.ModeShapeContentProvider.ServerOperation#getDisplay() */ @Override Display getDisplay() { return getViewer().getTree().getDisplay(); } }; run(op, true); } catch (final Exception e) { addOfflineServer(repository.getServer()); } } } }