Author: elvisisking
Date: 2009-08-24 13:01:51 -0400 (Mon, 24 Aug 2009)
New Revision: 1171
Added:
branches/eclipse/org.jboss.dna.publish.ui.swt/icons/views/published_overlay.gif
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/plugin.xml
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/IUiConstants.java
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.java
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.properties
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/Utils.java
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/views/ServerContentProvider.java
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishJob.java
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishPage.java
Log:
Added a file image overlay decorator indicating if the file has been published to one or
more DNA repositories. This overlay is removed by the decorator when the file is
unpublished from all the DNA repositories it was published to. The published state of a
file is persisted from session to session.
Added: branches/eclipse/org.jboss.dna.publish.ui.swt/icons/views/published_overlay.gif
===================================================================
(Binary files differ)
Property changes on:
branches/eclipse/org.jboss.dna.publish.ui.swt/icons/views/published_overlay.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: branches/eclipse/org.jboss.dna.publish.ui.swt/plugin.xml
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/plugin.xml 2009-08-21 22:08:39 UTC (rev
1170)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/plugin.xml 2009-08-24 17:01:51 UTC (rev
1171)
@@ -93,9 +93,14 @@
%decorator.description
</description>
<enablement>
+ <or>
<objectClass
name="org.jboss.dna.web.jcr.rest.client.domain.IDnaObject">
</objectClass>
+ <objectClass
+ name="org.eclipse.core.resources.IFile">
+ </objectClass>
+ </or>
</enablement>
</decorator>
</extension>
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/IUiConstants.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/IUiConstants.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/IUiConstants.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -78,6 +78,8 @@
String PUBLISH_IMAGE = VIEWS_ICON_FOLDER + "publish.png"; //$NON-NLS-1$
+ String PUBLISHED_OVERLAY_IMAGE = VIEWS_ICON_FOLDER +
"published_overlay.gif"; //$NON-NLS-1$
+
String REFRESH_IMAGE = VIEWS_ICON_FOLDER + "refresh.gif"; //$NON-NLS-1$
String UNPUBLISH_IMAGE = VIEWS_ICON_FOLDER + "unpublish.png";
//$NON-NLS-1$
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -55,6 +55,8 @@
public static I18n newServerActionText;
public static I18n newServerActionToolTip;
+ public static I18n publishedResourcePropertyErrorMsg;
+
public static I18n publishJobConsoleName;
public static I18n publishJobPublish;
public static I18n publishJobPublishCanceledMsg;
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.properties
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.properties 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/RestClientI18n.properties 2009-08-24
17:01:51 UTC (rev 1171)
@@ -44,6 +44,8 @@
newServerActionText = New Server
newServerActionToolTip = Create a new server
+publishedResourcePropertyErrorMsg = Error obtaining the "published" property
from the resource "{0}"
+
publishJobConsoleName = DNA
publishJobProblemCreatingHyperlinkMsg = Unexpected problem creating hyperlink in DNA
Console view
publishJobPublish = [{0}] Publishing {4} file(s) to server "{1}" (repository
"{2}", workspace "{3}") ...
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/Utils.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/Utils.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/Utils.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -23,15 +23,23 @@
*/
package org.jboss.dna.web.jcr.rest.client.swt;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.ISharedImages;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
/**
* @since 0.6
@@ -39,10 +47,71 @@
public final class Utils {
//
===========================================================================================================================
+ // Constants
+ //
===========================================================================================================================
+
+ /**
+ * Delimiter between a workspace's properties.
+ *
+ * @since 0.6
+ */
+ private static final String ID_DELIM = "$"; //$NON-NLS-1$
+
+ /**
+ * Delimiter between workspaces.
+ *
+ * @since 0.6
+ */
+ private static final String DELIM = "|"; //$NON-NLS-1$
+
+ /**
+ * The name of the persisted file property indicating if the resource has been
published. This property will only exist if the
+ * file has been published to at least one DNA repository. The value of the property
is a list of DNA repository workspaces
+ * where this file has been published.
+ *
+ * @since 0.6
+ */
+ private static QualifiedName PUBLISHED_RESOURCE_PROPERTY = new
QualifiedName(IUiConstants.PLUGIN_ID, "publishedIn"); //$NON-NLS-1$
+
+ //
===========================================================================================================================
// Class Methods
//
===========================================================================================================================
/**
+ * @param file the file that was just published
+ * @param workspace the workspace where the file was published
+ * @since 0.6
+ */
+ public static void addPublishedProperty( IFile file,
+ Workspace workspace ) {
+ CheckArg.isNotNull(file, "file"); //$NON-NLS-1$
+ CheckArg.isNotNull(workspace, "workspace"); //$NON-NLS-1$
+
+ String wsValue = createWorkspaceId(workspace);
+
+ try {
+ Set<String> workspaces = null;
+
+ // get current value
+ String value = file.getPersistentProperty(PUBLISHED_RESOURCE_PROPERTY);
+
+ if (value == null) {
+ workspaces = new HashSet<String>(1);
+ } else {
+ workspaces = parsePublishedPropertyValue(value);
+ }
+
+ workspaces.add(wsValue);
+
+ // set new value
+ value = createPublishedPropertyValue(workspaces);
+ file.setPersistentProperty(PUBLISHED_RESOURCE_PROPERTY, value);
+ } catch (CoreException e) {
+ Activator.getDefault().log(new Status(Severity.ERROR,
RestClientI18n.publishedResourcePropertyErrorMsg.text(file), e));
+ }
+ }
+
+ /**
* Sizes the shell to the minimum of it's current size or the width and height
display percentages.
*
* @param shell the shell being resized (if necessary) and located
@@ -80,10 +149,10 @@
/**
* Converts the non-Eclipse status severity to an Eclipse severity level. An {@link
Status.Severity#UNKNOWN unknown status} is
- * converted to {@link IStatus#CANCEL cancel}. A {@link Status.Severity} is
+ * converted to {@link IStatus#CANCEL cancel}.
*
* @param severity the eclipse status severity level
- * @return the converted severity level
+ * @return the converted severity level (never <code>null</code>)
* @see IStatus
* @since 0.6
*/
@@ -99,7 +168,7 @@
* Converts the Eclipse status severity level to a non-Eclipse severity.
*
* @param severity the eclipse status severity level
- * @return the converted severity level
+ * @return the converted severity level (never <code>null</code>)
* @see IStatus
* @since 0.6
*/
@@ -112,13 +181,43 @@
}
/**
+ * @param workspaces the workspaces used to create the property value
+ * @return the property value
+ * @since 0.6
+ */
+ private static String createPublishedPropertyValue( Set<String> workspaces ) {
+ StringBuilder value = new StringBuilder();
+
+ for (String workspace : workspaces) {
+ value.append(workspace).append(DELIM);
+ }
+
+ return value.toString();
+ }
+
+ /**
+ * @param workspace the workspace whose identifier is being created
+ * @return the ID
+ * @since 0.6
+ */
+ private static String createWorkspaceId( Workspace workspace ) {
+ StringBuilder result = new StringBuilder();
+
result.append(workspace.getServer().getUrl()).append(ID_DELIM).append(workspace.getServer().getUser()).append(ID_DELIM);
+ result.append(workspace.getRepository().getName()).append(ID_DELIM);
+ result.append(workspace.getName());
+
+ return result.toString();
+ }
+
+ /**
* The OK status does not have an image.
*
- * @param status the status whose image is being requested
+ * @param status the status whose image is being requested (never
<code>null</code>)
* @return the image or <code>null</code> if no associated image for the
status severity
* @since 0.6
*/
public static Image getImage( Status status ) {
+ CheckArg.isNotNull(status, "status"); //$NON-NLS-1$
String imageId = null;
if (status.isError()) {
@@ -139,11 +238,12 @@
/**
* The image can be used to decorate an existing image.
*
- * @param status the status whose image overlay is being requested
+ * @param status the status whose image overlay is being requested (never
<code>null</code>)
* @return the image descriptor or <code>null</code> if none found for
the status severity
* @since 0.6
*/
public static ImageDescriptor getOverlayImage( Status status ) {
+ CheckArg.isNotNull(status, "status"); //$NON-NLS-1$
String imageId = null;
if (status.isError()) {
@@ -157,6 +257,72 @@
return null;
}
+ /**
+ * @param file the file whose published status is being requested
+ * @return <code>true</code> if the file has been published to any DNA
repository
+ * @since 0.6
+ */
+ public static boolean isPublished( IFile file ) {
+ CheckArg.isNotNull(file, "file"); //$NON-NLS-1$
+
+ try {
+ return (file.getPersistentProperty(PUBLISHED_RESOURCE_PROPERTY) != null);
+ } catch (CoreException e) {
+ Activator.getDefault().log(new Status(Severity.ERROR,
RestClientI18n.publishedResourcePropertyErrorMsg.text(file), e));
+ }
+
+ return false;
+ }
+
+ /**
+ * @param value the property value being parsed
+ * @return a collection of workspace identifiers
+ * @since 0.6
+ */
+ private static Set<String> parsePublishedPropertyValue( String value ) {
+ StringTokenizer st = new StringTokenizer(value, DELIM);
+ Set<String> workspaces = new HashSet<String>(st.countTokens());
+
+ while (st.hasMoreTokens()) {
+ workspaces.add(st.nextToken());
+ }
+
+ return workspaces;
+ }
+
+ /**
+ * @param file the file that was just unpublished
+ * @param workspace the workspace where the file was unpublished
+ * @since 0.6
+ */
+ public static void removePublishedProperty( IFile file,
+ Workspace workspace ) {
+ CheckArg.isNotNull(file, "file"); //$NON-NLS-1$
+ CheckArg.isNotNull(workspace, "workspace"); //$NON-NLS-1$
+
+ String wsValue = createWorkspaceId(workspace);
+
+ try {
+ String value = file.getPersistentProperty(PUBLISHED_RESOURCE_PROPERTY);
+
+ if (value != null) {
+ Set<String> workspaces = parsePublishedPropertyValue(value);
+ workspaces.remove(wsValue);
+
+ if (workspaces.isEmpty()) {
+ // no other workspaces so remove property
+ file.setPersistentProperty(PUBLISHED_RESOURCE_PROPERTY, null);
+ } else {
+ // set new value
+ value = createPublishedPropertyValue(workspaces);
+ file.setPersistentProperty(PUBLISHED_RESOURCE_PROPERTY, value);
+ }
+ }
+ } catch (CoreException e) {
+ Activator.getDefault().log(new Status(Severity.ERROR,
RestClientI18n.publishedResourcePropertyErrorMsg.text(file), e));
+ }
+ }
+
//
===========================================================================================================================
// Constructors
//
===========================================================================================================================
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/views/ServerContentProvider.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/views/ServerContentProvider.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/views/ServerContentProvider.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -23,6 +23,8 @@
*/
package org.jboss.dna.web.jcr.rest.client.swt.views;
+import static
org.jboss.dna.web.jcr.rest.client.swt.IUiConstants.PUBLISHED_OVERLAY_IMAGE;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IDecoration;
@@ -97,6 +99,7 @@
@Override
public void decorate( final Object element,
IDecoration decoration ) {
+ ImageDescriptor overlay = null;
final Display display = Display.getDefault();
if (display.isDisposed()) {
@@ -106,25 +109,26 @@
// must be an IDnaObject
if (element instanceof Server) {
Status status =
Activator.getDefault().getServerManager().ping((Server)element);
+ overlay = Utils.getOverlayImage(status);
+ } else if (element instanceof IFile) {
+ if (Utils.isPublished((IFile)element)) {
+ overlay =
Activator.getDefault().getImageDescriptor(PUBLISHED_OVERLAY_IMAGE);
+ }
+ }
- if (status.isError()) {
- ImageDescriptor overlay = Utils.getOverlayImage(status);
+ if (overlay != null) {
+ decoration.addOverlay(overlay);
+ }
- if (overlay != null) {
- decoration.addOverlay(overlay);
+ display.asyncExec(new Runnable() {
+ @SuppressWarnings( "synthetic-access" )
+ @Override
+ public void run() {
+ if (!display.isDisposed()) {
+ fireLabelProviderChanged(new
LabelProviderChangedEvent(ServerContentProvider.this, element));
}
}
-
- display.asyncExec(new Runnable() {
- @SuppressWarnings( "synthetic-access" )
- @Override
- public void run() {
- if (!display.isDisposed()) {
- fireLabelProviderChanged(new
LabelProviderChangedEvent(ServerContentProvider.this, element));
- }
- }
- });
- }
+ });
}
/**
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishJob.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishJob.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishJob.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -52,6 +52,7 @@
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
import org.jboss.dna.web.jcr.rest.client.swt.Activator;
import org.jboss.dna.web.jcr.rest.client.swt.RestClientI18n;
+import org.jboss.dna.web.jcr.rest.client.swt.Utils;
/**
* The <code>PublishJob</code> publishes or unpublishes one or more files
using the {@link ServerManager}.
@@ -285,10 +286,20 @@
status =
Activator.getDefault().getServerManager().publish(this.workspace,
eclipseFile.getFullPath().toString(),
file);
+
+ // set persistent property on resource indicating it has been
published
+ if (!status.isError()) {
+ Utils.addPublishedProperty(eclipseFile, workspace);
+ }
} else {
status =
Activator.getDefault().getServerManager().unpublish(this.workspace,
eclipseFile.getFullPath().toString(),
file);
+
+ // clear persistent property on resource indicating it has been
unpublished
+ if (!status.isError()) {
+ Utils.removePublishedProperty(eclipseFile, workspace);
+ }
}
++numProcessed;
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishPage.java
===================================================================
---
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishPage.java 2009-08-21
22:08:39 UTC (rev 1170)
+++
branches/eclipse/org.jboss.dna.publish.ui.swt/src/org/jboss/dna/web/jcr/rest/client/swt/wizards/PublishPage.java 2009-08-24
17:01:51 UTC (rev 1171)
@@ -654,8 +654,13 @@
* @since 0.6
*/
void handleServerModified() {
- this.server = this.servers.get(this.cbxServer.getSelectionIndex());
+ int index = this.cbxServer.getSelectionIndex();
+ // make sure there is a selection
+ if (index != -1) {
+ this.server = this.servers.get(index);
+ }
+
// need to reload repositories since server changed
refreshRepositories();
@@ -799,6 +804,9 @@
this.server = null;
this.servers = new ArrayList<Server>(getServerManager().getServers());
+ // clear server combo
+ this.cbxServer.removeAll();
+
if (this.servers.size() == 0) {
// disable control if necessary
if (this.cbxServer.getEnabled()) {