Author: elvisisking
Date: 2012-05-08 10:28:08 -0400 (Tue, 08 May 2012)
New Revision: 40847
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/plugin.xml
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.properties
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/actions/ReconnectToServerAction.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/domain/ModeShapeServer.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/jobs/ReconnectJob.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ModeShapeContentProvider.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ServerView.java
Log:
JBIDE-7928 Prompt for Password Dialog. Converted to lazy loading tree in ModeShape Server
view. Until user expands tree no call to server is done. Also noticing if empty password
and asking user if they want to enter one.
Modified: trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/plugin.xml
===================================================================
--- trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/plugin.xml 2012-05-08 11:17:39
UTC (rev 40846)
+++ trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/plugin.xml 2012-05-08 14:28:08
UTC (rev 40847)
@@ -189,6 +189,9 @@
<enablement>
<or>
<objectClass
+
name="org.jboss.tools.modeshape.rest.domain.ModeShapeServer">
+ </objectClass>
+ <objectClass
name="org.modeshape.web.jcr.rest.client.domain.IModeShapeObject">
</objectClass>
<objectClass
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -44,6 +44,9 @@
public static String ignoredResourcesPreferencePageTitle;
public static String missingImage;
+
+ public static String missingServerPasswordDialogMsg;
+ public static String missingServerPasswordDialogTitle;
public static String newIgnoredResourceDialogLabel;
public static String newIgnoredResourceDialogTitle;
@@ -148,6 +151,15 @@
public static String reconnectJobTaskName;
+ public static String requestDialogTitle;
+ public static String runningRepositoriesQueryMsg;
+ public static String runningServerRequestErrorMsg;
+ public static String runningServerRequestErrorDialogMsg;
+ public static String runningServerRequestErrorDialogTitle;
+ public static String runningServerRequestNewPasswordDialogMsg;
+ public static String runningServerRequestNewPasswordDialogTitle;
+ public static String runningWorkspacesQueryMsg;
+
public static String serverEmptyUrlMsg;
public static String serverEmptyUserMsg;
public static String serverExistsMsg;
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.properties
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.properties 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/RestClientI18n.properties 2012-05-08
14:28:08 UTC (rev 40847)
@@ -37,6 +37,9 @@
missingImage = The following image cannot be found "{0}"
+missingServerPasswordDialogMsg = The server you are trying to connect to does not have a
password set. Would you like to set one?
+missingServerPasswordDialogTitle = Empty ModeShape Server Password
+
newIgnoredResourceDialogLabel = Enter a file name or folder name (* = any string, ? = and
character):
newIgnoredResourceDialogTitle = New Ignore Pattern
@@ -140,6 +143,15 @@
reconnectJobTaskName = Connecting to server "{0}"
+requestDialogTitle = ModeShape Server Request
+runningRepositoriesQueryMsg = Running repositories query ...
+runningServerRequestErrorMsg = Unable to connect to ModeShape server
+runningServerRequestErrorDialogMsg = ModeShape server cannot be reached. Make sure server
properties are correct.
+runningServerRequestErrorDialogTitle = ModeShape Server Connection Error
+runningServerRequestNewPasswordDialogMsg = Enter a new, non-empty server password
+runningServerRequestNewPasswordDialogTitle = Server Password Change
+runningWorkspacesQueryMsg = Running workspaces query ...
+
serverEmptyUserMsg = The user cannot be empty
serverEmptyUrlMsg = A server URL cannot be empty
serverExistsMsg = {0} already exists so it cannot be added
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/actions/ReconnectToServerAction.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/actions/ReconnectToServerAction.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/actions/ReconnectToServerAction.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -102,7 +102,7 @@
// run job in own thread not in the UI thread
Thread t = new Thread();
- t.start();
+ t.run();
job.setThread(t);
job.schedule();
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/domain/ModeShapeServer.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/domain/ModeShapeServer.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/domain/ModeShapeServer.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -58,18 +58,10 @@
*/
@Override
public boolean equals( Object obj ) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null) {
+ if ((obj == null) || !getClass().equals(obj.getClass())) {
return false;
}
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
-
ModeShapeServer that = (ModeShapeServer)obj;
if (this.delegate.equals(that.delegate)) {
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/jobs/ReconnectJob.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/jobs/ReconnectJob.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/jobs/ReconnectJob.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -22,7 +22,6 @@
import org.jboss.tools.modeshape.rest.Activator;
import org.jboss.tools.modeshape.rest.RestClientI18n;
import org.jboss.tools.modeshape.rest.ServerManager;
-import org.jboss.tools.modeshape.rest.Utils;
import org.jboss.tools.modeshape.rest.domain.ModeShapeServer;
import org.modeshape.web.jcr.rest.client.Status;
@@ -61,7 +60,6 @@
*/
@Override
protected IStatus run( IProgressMonitor monitor ) {
- IStatus result = null;
ServerManager serverManager = Activator.getDefault().getServerManager();
try {
@@ -69,18 +67,21 @@
monitor.beginTask(taskName, 1);
monitor.setTaskName(taskName);
Status status = serverManager.ping(this.server);
- result = Utils.convert(status);
+
+ if (status.isError()) {
+ Activator.getDefault().log(status);
+ }
} catch (Exception e) {
- result = new org.eclipse.core.runtime.Status(IStatus.ERROR,
+ Activator.getDefault().getLog().log(new
org.eclipse.core.runtime.Status(IStatus.ERROR,
PLUGIN_ID,
RestClientI18n.publishJobUnexpectedErrorMsg,
- e);
+ e));
} finally {
monitor.done();
- done(result);
}
- return result;
+ // if an error status is returned a dialog is displayed by the UI event loop so
we don't want that
+ return org.eclipse.core.runtime.Status.OK_STATUS;
}
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ModeShapeContentProvider.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ModeShapeContentProvider.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ModeShapeContentProvider.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -13,6 +13,9 @@
import static org.jboss.tools.modeshape.rest.IUiConstants.PUBLISHED_OVERLAY_IMAGE;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
@@ -21,37 +24,54 @@
import net.jcip.annotations.GuardedBy;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.jface.viewers.ILazyTreeContentProvider;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
-import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IDecoratorManager;
import org.jboss.tools.modeshape.rest.Activator;
import org.jboss.tools.modeshape.rest.IServerRegistryListener;
+import org.jboss.tools.modeshape.rest.IUiConstants;
import org.jboss.tools.modeshape.rest.PublishedResourceHelper;
import org.jboss.tools.modeshape.rest.RestClientI18n;
import org.jboss.tools.modeshape.rest.ServerManager;
import org.jboss.tools.modeshape.rest.ServerRegistryEvent;
-import org.jboss.tools.modeshape.rest.Utils;
import org.jboss.tools.modeshape.rest.domain.ModeShapeDomainObject;
import org.jboss.tools.modeshape.rest.domain.ModeShapeRepository;
import org.jboss.tools.modeshape.rest.domain.ModeShapeServer;
import org.jboss.tools.modeshape.rest.domain.ModeShapeWorkspace;
-import org.modeshape.web.jcr.rest.client.Status;
-import org.modeshape.web.jcr.rest.client.Status.Severity;
/**
* The <code>ModeShapeContentProvider</code> is a content and label provider
for the repositories. This class <strong>MUST</strong>
* be registered, and then unregistered, to receive server registry events.
*/
public final class ModeShapeContentProvider extends ColumnLabelProvider implements
ILightweightLabelDecorator,
- IServerRegistryListener, ITreeContentProvider {
+ IServerRegistryListener, ILazyTreeContentProvider {
/**
* The decorator ID.
@@ -61,47 +81,60 @@
/**
* If a server connection cannot be established, wait this amount of time before
trying again.
*/
- private static final long RETRY_DURATION = 2000;
+ private static final long RETRY_DURATION = 5000;
/**
- * @return the decorator
+ * Indicates if the Eclipse lazy content provider has already called this provider.
This occurs when the associated viewer of
+ * this provider has been shown once or if the Eclipse window loses focus.
*/
- public static ModeShapeContentProvider getDecorator() {
- IDecoratorManager decoratorMgr =
Activator.getDefault().getWorkbench().getDecoratorManager();
+ private static boolean _alreadyCalledByFramework;
- if (decoratorMgr.getEnabled(ID)) {
- return (ModeShapeContentProvider)decoratorMgr.getBaseLabelProvider(ID);
- }
-
- return null;
- }
-
/**
* Servers that a connection can't be established. Value is the last time a
establishing a connection was tried.
*/
@GuardedBy("offlineServersLock")
- private final Map<ModeShapeServer, Long> offlineServerMap = new
HashMap<ModeShapeServer, Long>();
+ private final static Map<ModeShapeServer, Long> _offlineServerMap = new
HashMap<ModeShapeServer, Long>();
/**
* Lock used for when accessing the offline server map. The map will be accessed in
different threads as the decorator runs in
* its own thread (not the UI thread).
*/
- private final ReadWriteLock offlineServersLock = new ReentrantReadWriteLock();
+ private final static ReadWriteLock _offlineServersLock = new
ReentrantReadWriteLock();
/**
+ * @return the decorator
+ */
+ public static ModeShapeContentProvider getDecorator() {
+ final IDecoratorManager decoratorMgr =
Activator.getDefault().getWorkbench().getDecoratorManager();
+
+ if (decoratorMgr.getEnabled(ID)) {
+ return (ModeShapeContentProvider)decoratorMgr.getBaseLabelProvider(ID);
+ }
+
+ return null;
+ }
+
+ /**
* The server manager where the server registry is managed.
*/
private ServerManager serverManager;
+ private TreeViewer viewer;
+
/**
* @param server the server that is offline
*/
- private void addOfflineServer( ModeShapeServer server ) {
+ void addOfflineServer( final ModeShapeServer server ) {
+ if (this.viewer != null) {
+ this.viewer.setHasChildren(server, false); // get rid of the expansion
button
+ }
+
try {
- this.offlineServersLock.writeLock().lock();
- this.offlineServerMap.put(server, System.currentTimeMillis());
+ _offlineServersLock.writeLock().lock();
+ _offlineServerMap.put(server, System.currentTimeMillis());
+ refresh(server);
} finally {
- this.offlineServersLock.writeLock().unlock();
+ _offlineServersLock.writeLock().unlock();
}
}
@@ -112,7 +145,7 @@
*/
@Override
public void decorate( final Object element,
- IDecoration decoration ) {
+ final IDecoration decoration ) {
ImageDescriptor overlay = null;
final Display display = Display.getDefault();
@@ -120,31 +153,30 @@
return;
}
- if (getServerManager() != null) {
- if (element instanceof ModeShapeServer) {
- ModeShapeServer server = (ModeShapeServer)element;
+ if (element instanceof ModeShapeServer) {
+ final ModeShapeServer server = (ModeShapeServer)element;
- if (isOkToConnect(server)) {
- Status status = getServerManager().ping(server);
- overlay = Utils.getOverlayImage(status);
+ // if server is offline then decorate with error overlay
+ try {
+ _offlineServersLock.readLock().lock();
- if (status.isError()) {
- addOfflineServer(server);
- }
+ if (_offlineServerMap.containsKey(server)) {
+ overlay =
Activator.getDefault().getImageDescriptor(IUiConstants.ERROR_OVERLAY_IMAGE);
}
- } else if (element instanceof IFile) {
- IFile file = (IFile)element;
-
- if (file.exists() && !file.isHidden()
- && new
PublishedResourceHelper(getServerManager()).isPublished((IFile)element)) {
- overlay =
Activator.getDefault().getImageDescriptor(PUBLISHED_OVERLAY_IMAGE);
- }
+ } finally {
+ _offlineServersLock.readLock().unlock();
}
+ } else if (element instanceof IFile) {
+ final IFile file = (IFile)element;
- if (overlay != null) {
- decoration.addOverlay(overlay);
+ if (file.exists() && !file.isHidden() && new
PublishedResourceHelper(getServerManager()).isPublished((IFile)element)) {
+ overlay =
Activator.getDefault().getImageDescriptor(PUBLISHED_OVERLAY_IMAGE);
}
}
+
+ if (overlay != null) {
+ decoration.addOverlay(overlay);
+ }
}
/**
@@ -160,70 +192,20 @@
/**
* {@inheritDoc}
*
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
- @Override
- public Object[] getChildren( Object parentElement ) {
- assert (parentElement instanceof ModeShapeDomainObject);
-
- if (getServerManager() != null) {
- if (parentElement instanceof ModeShapeServer) {
- ModeShapeServer server = (ModeShapeServer)parentElement;
-
- if (isOkToConnect(server)) {
- try {
- return getServerManager().getRepositories(server).toArray();
- } catch (Exception e) {
- addOfflineServer(server);
- String msg =
NLS.bind(RestClientI18n.serverManagerGetRepositoriesExceptionMsg,
server.getShortDescription());
- Activator.getDefault().log(new Status(Severity.ERROR, msg, e));
- }
- }
- } else if (parentElement instanceof ModeShapeRepository) {
- ModeShapeRepository repository = (ModeShapeRepository)parentElement;
-
- if (isOkToConnect(repository.getServer())) {
- try {
- return getServerManager().getWorkspaces(repository).toArray();
- } catch (Exception e) {
- addOfflineServer(repository.getServer());
- String msg =
NLS.bind(RestClientI18n.serverManagerGetWorkspacesExceptionMsg,
repository.getShortDescription());
- Activator.getDefault().log(new Status(Severity.ERROR, msg, e));
- }
- }
- }
- }
-
- return new Object[0];
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- @Override
- public Object[] getElements( Object inputElement ) {
- return ((getServerManager() == null) ? new Object[0] :
getServerManager().getServers().toArray());
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
@Override
- public Image getImage( Object element ) {
+ public Image getImage( final Object element ) {
return Activator.getDefault().getImage(element);
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ * @see
org.eclipse.jface.viewers.ILazyTreeContentProvider#getParent(java.lang.Object)
*/
@Override
- public Object getParent( Object element ) {
+ public Object getParent( final Object element ) {
assert (element instanceof ModeShapeDomainObject);
if (element instanceof ModeShapeWorkspace) {
@@ -234,14 +216,15 @@
return ((ModeShapeRepository)element).getServer();
}
- // server
+ if (element instanceof ModeShapeServer) {
+ return getServerManager();
+ }
+
+ assert false : "unknown ModeShapeDomainObject=" + element.getClass();
//$NON-NLS-1$
return null;
}
- /**
- * @return the server manager (never <code>null</code>)
- */
- private ServerManager getServerManager() {
+ ServerManager getServerManager() {
if (this.serverManager == null) {
this.serverManager = Activator.getDefault().getServerManager();
}
@@ -249,13 +232,17 @@
return this.serverManager;
}
+ Shell getShell() {
+ return this.viewer.getTree().getShell();
+ }
+
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
@Override
- public String getText( Object element ) {
+ public String getText( final Object element ) {
assert (element instanceof ModeShapeDomainObject);
return ((ModeShapeDomainObject)element).getName();
}
@@ -266,7 +253,7 @@
* @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipImage(java.lang.Object)
*/
@Override
- public Image getToolTipImage( Object object ) {
+ public Image getToolTipImage( final Object object ) {
return getImage(object);
}
@@ -276,7 +263,7 @@
* @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
*/
@Override
- public String getToolTipText( Object element ) {
+ public String getToolTipText( final Object element ) {
if (element instanceof ModeShapeDomainObject) {
return ((ModeShapeDomainObject)element).getShortDescription();
}
@@ -290,18 +277,12 @@
* @see
org.eclipse.jface.viewers.CellLabelProvider#getToolTipTimeDisplayed(java.lang.Object)
*/
@Override
- public int getToolTipTimeDisplayed( Object object ) {
+ public int getToolTipTimeDisplayed( final Object object ) {
return 3000;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
- @Override
- public boolean hasChildren( Object element ) {
- return getChildren(element).length > 0;
+ TreeViewer getViewer() {
+ return this.viewer;
}
/**
@@ -311,59 +292,39 @@
* java.lang.Object)
*/
@Override
- public void inputChanged( Viewer viewer,
- Object oldInput,
- Object newInput ) {
+ public void inputChanged( final Viewer viewer,
+ final Object oldInput,
+ final Object newInput ) {
// nothing to do
}
- public void refresh( final Object element ) {
- final Display display = Display.getDefault();
-
- if (display.isDisposed()) {
- return;
- }
-
- display.asyncExec(new Runnable() {
- /**
- * {@inheritDoc}
- *
- * @see java.lang.Runnable#run()
- */
- @SuppressWarnings("synthetic-access")
- @Override
- public void run() {
- fireLabelProviderChanged(new
LabelProviderChangedEvent(ModeShapeContentProvider.this, element));
- }
- });
- }
-
/**
* Determines if a try to connect to a server should be done based on the last time a
try was done and failed.
*
* @param server the server being checked
* @return <code>true</code> if it is OK to try and connect
*/
- private boolean isOkToConnect( ModeShapeServer server ) {
+ private boolean isOkToConnect( final ModeShapeServer server ) {
boolean check = false; // check map for time
try {
- this.offlineServersLock.readLock().lock();
- check = this.offlineServerMap.containsKey(server);
+ _offlineServersLock.readLock().lock();
+ check = _offlineServerMap.containsKey(server);
} finally {
- this.offlineServersLock.readLock().unlock();
+ _offlineServersLock.readLock().unlock();
}
if (check) {
try {
- this.offlineServersLock.writeLock().lock();
+ _offlineServersLock.writeLock().lock();
- if (this.offlineServerMap.containsKey(server)) {
- long checkTime = this.offlineServerMap.get(server);
+ if (_offlineServerMap.containsKey(server)) {
+ final long checkTime = _offlineServerMap.get(server);
// OK to try and connect if last failed attempt was too long ago
if ((System.currentTimeMillis() - checkTime) > RETRY_DURATION) {
- this.offlineServerMap.remove(server);
+ _offlineServerMap.remove(server);
+ refresh(server);
return true;
}
@@ -371,7 +332,7 @@
return false;
}
} finally {
- this.offlineServersLock.writeLock().unlock();
+ _offlineServersLock.writeLock().unlock();
}
}
@@ -379,28 +340,425 @@
return true;
}
+ public void refresh( final Object element ) {
+ final Display display = Display.getDefault();
+
+ if (display.isDisposed()) {
+ return;
+ }
+
+ display.asyncExec(new Runnable() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public void run() {
+ fireLabelProviderChanged(new
LabelProviderChangedEvent(ModeShapeContentProvider.this, element));
+ }
+ });
+ }
+
+ private void run( final ServerOperation op,
+ final boolean enforceNonEmptyPassword ) {
+ try {
+ final ModeShapeServer server = op.getServer();
+
+ if (enforceNonEmptyPassword && ((server.getPassword() == null) ||
server.getPassword().isEmpty())) {
+ if (MessageDialog.openQuestion(getShell(),
RestClientI18n.missingServerPasswordDialogTitle,
+
RestClientI18n.missingServerPasswordDialogMsg)) {
+ final NewPasswordDialog dialog = new NewPasswordDialog(getShell());
+
+ if (dialog.open() == Window.OK) {
+ getServerManager().updateServer(server,
+ new
ModeShapeServer(server.getUrl(),
+
server.getUser(),
+
dialog.getNewPassword(),
+
server.isPasswordBeingPersisted()));
+
+ // need to obtain changed server from server manager as servers
are not mutable
+ for (final ModeShapeServer registeredServer :
getServerManager().getServers()) {
+ if (registeredServer.hasSameKey(server)) {
+ op.setUpdatedServer(registeredServer);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.dialogs.ProgressMonitorDialog#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ @Override
+ protected void configureShell( final Shell shell ) {
+ super.configureShell(shell);
+ shell.setText(RestClientI18n.requestDialogTitle);
+ }
+ };
+
+ dialog.run(true, false, op);
+ } catch (final InvocationTargetException e) {
+ // should not happen as ServerOperation handles this but just in case
+ if (op.getUpdatedServer() == null) {
+ addOfflineServer(op.getServer());
+ } else {
+ addOfflineServer(op.getUpdatedServer());
+ }
+
+ final org.eclipse.core.runtime.Status error = new
org.eclipse.core.runtime.Status(IStatus.ERROR,
+
IUiConstants.PLUGIN_ID,
+
RestClientI18n.runningServerRequestErrorMsg,
+
e.getCause());
+ ErrorDialog.openError(getShell(),
RestClientI18n.runningServerRequestErrorDialogTitle,
+ RestClientI18n.runningServerRequestErrorDialogMsg,
error);
+ } catch (final InterruptedException e) {
+ // won't happen as runnable is not cancelable
+ }
+ }
+
/**
* {@inheritDoc}
*
* @see
org.jboss.tools.modeshape.rest.IServerRegistryListener#serverRegistryChanged(org.jboss.tools.modeshape.rest.ServerRegistryEvent)
*/
@Override
- public Exception[] serverRegistryChanged( ServerRegistryEvent event ) {
+ public Exception[] serverRegistryChanged( final ServerRegistryEvent event ) {
Exception[] errors = null;
// only care about servers being removed or updated
if (event.isRemove() || event.isUpdate()) {
try {
- this.offlineServersLock.writeLock().lock();
- this.offlineServerMap.remove(event.getServer());
- } catch (Exception e) {
+ _offlineServersLock.writeLock().lock();
+ _offlineServerMap.remove(event.getServer());
+ } catch (final Exception e) {
errors = new Exception[] { e };
} finally {
- this.offlineServersLock.writeLock().unlock();
+ _offlineServersLock.writeLock().unlock();
}
}
return errors;
}
+ void setViewer( final TreeViewer viewer ) {
+ this.viewer = viewer;
+ }
+
+ /**
+ * {@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());
+ }
+ }
+ }
+ }
+
+ /**
+ * {@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());
+ }
+ }
+ }
+ }
+
+ class NewPasswordDialog extends MessageDialog {
+
+ private Button btnOk;
+ private String newPassword = ""; //$NON-NLS-1$
+
+ public NewPasswordDialog( final Shell parentShell ) {
+ super(parentShell, RestClientI18n.runningServerRequestNewPasswordDialogTitle,
null,
+ RestClientI18n.runningServerRequestNewPasswordDialogMsg,
MessageDialog.NONE, new String[] {
+ IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL },
0);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.dialogs.MessageDialog#createButton(org.eclipse.swt.widgets.Composite,
int, java.lang.String,
+ * boolean)
+ */
+ @Override
+ protected Button createButton( final Composite parent,
+ final int id,
+ final String label,
+ final boolean defaultButton ) {
+ final Button btn = super.createButton(parent, id, label, defaultButton);
+
+ if (id == IDialogConstants.OK_ID) {
+ // disable OK button initially
+ this.btnOk = btn;
+ btn.setEnabled(false);
+ }
+
+ return btn;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createCustomArea( final Composite parent ) {
+ final Composite panel = new Composite(parent, SWT.NONE);
+ panel.setLayout(new GridLayout(2, false));
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ final Label lbl = new Label(panel, SWT.NONE);
+ lbl.setText(RestClientI18n.serverPagePasswordLabel);
+
+ final Text txt = new Text(panel, SWT.BORDER);
+ txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ txt.setToolTipText(RestClientI18n.serverPagePasswordToolTip);
+ txt.addModifyListener(new ModifyListener() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ @Override
+ public void modifyText( final ModifyEvent e ) {
+ handlePasswordChanged(((Text)e.widget).getText());
+ }
+ });
+
+ return super.createCustomArea(parent);
+ }
+
+ public String getNewPassword() {
+ return this.newPassword;
+ }
+
+ void handlePasswordChanged( final String newPassword ) {
+ this.newPassword = newPassword;
+
+ // update OK button enablement
+ final boolean enable = ((this.newPassword != null) &&
!this.newPassword.isEmpty());
+
+ if (this.btnOk.getEnabled() != enable) {
+ this.btnOk.setEnabled(enable);
+ }
+ }
+ }
+
+ abstract class ServerOperation implements IRunnableWithProgress {
+ private ModeShapeServer updatedServer;
+ private final ModeShapeServer server;
+
+ public ServerOperation( final ModeShapeServer server ) {
+ this.server = server;
+ }
+
+ abstract void doRun( IProgressMonitor monitor ) throws InvocationTargetException,
InterruptedException;
+
+ abstract Display getDisplay();
+
+ ModeShapeServer getServer() {
+ return this.server;
+ }
+
+ ModeShapeServer getUpdatedServer() {
+ return this.updatedServer;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public final void run( final IProgressMonitor monitor ) {
+ getDisplay().asyncExec(new Runnable() {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ try {
+ doRun(monitor);
+ } catch (final InvocationTargetException e) {
+ if (getUpdatedServer() == null) {
+ addOfflineServer(getServer());
+ } else {
+ addOfflineServer(getUpdatedServer());
+ }
+
+ final org.eclipse.core.runtime.Status error = new
org.eclipse.core.runtime.Status(IStatus.ERROR,
+
IUiConstants.PLUGIN_ID,
+
RestClientI18n.runningServerRequestErrorMsg,
+
e.getCause());
+ ErrorDialog.openError(getShell(),
RestClientI18n.runningServerRequestErrorDialogTitle,
+
RestClientI18n.runningServerRequestErrorDialogMsg, error);
+ } catch (final InterruptedException e) {
+ // should not happen has monitor is not cancelable
+ }
+ }
+ });
+ }
+
+ void setUpdatedServer( final ModeShapeServer updatedServer ) {
+ this.updatedServer = updatedServer;
+ }
+ }
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ServerView.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ServerView.java 2012-05-08
11:17:39 UTC (rev 40846)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.rest/src/org/jboss/tools/modeshape/rest/views/ServerView.java 2012-05-08
14:28:08 UTC (rev 40847)
@@ -147,8 +147,10 @@
* @param parent the viewer's parent
*/
private void constructTreeViewer( Composite parent ) {
+ this.viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI |
SWT.VIRTUAL);
+ this.viewer.setUseHashlookup(true);
this.provider = new ModeShapeContentProvider();
- this.viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
+ this.provider.setViewer(this.viewer);
this.viewer.setContentProvider(this.provider);
ILabelDecorator decorator =
Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator();
@@ -178,8 +180,8 @@
}
});
- // need to call this (doesn't matter what the param is) to bootstrap the
provider.
- this.viewer.setInput(this);
+ // need to call this to populate tree
+ this.viewer.setInput(getServerManager());
// need to do this so that properties page will work
getSite().setSelectionProvider(this.viewer);