Author: elvisisking
Date: 2009-08-21 18:08:39 -0400 (Fri, 21 Aug 2009)
New Revision: 1170
Modified:
branches/eclipse/org.jboss.dna.publish.ui.swt/META-INF/MANIFEST.MF
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/wizards/PublishJob.java
Log:
Added hyperlinks to the DNA Message Console view. Hyperlinks now exist for each file that
was published or unpublished. Clicking on the hyperlink opens the file in the default
editor.
Modified: branches/eclipse/org.jboss.dna.publish.ui.swt/META-INF/MANIFEST.MF
===================================================================
--- branches/eclipse/org.jboss.dna.publish.ui.swt/META-INF/MANIFEST.MF 2009-08-19 16:26:03
UTC (rev 1169)
+++ branches/eclipse/org.jboss.dna.publish.ui.swt/META-INF/MANIFEST.MF 2009-08-21 22:08:39
UTC (rev 1170)
@@ -10,7 +10,8 @@
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui.console,
- org.eclipse.jface.text
+ org.eclipse.jface.text,
+ org.eclipse.debug.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: dna-web-jcr-rest-client-0.6-SNAPSHOT-jar-with-dependencies.jar,
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-19
16:26:03 UTC (rev 1169)
+++
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)
@@ -35,6 +35,13 @@
*/
String PLUGIN_ID = "org.jboss.dna.web.jcr.rest.client.swt"; //$NON-NLS-1$
+ /**
+ * The identifier and type of the DNA Message Console. This is where publishing and
unpublishing operations are logged.
+ *
+ * @since 0.6
+ */
+ String DNA_CONSOLE_ID =
"org.jboss.dna.web.jcr.rest.client.swt.views.DnaConsole"; //$NON-NLS-1$
+
String ICON_FOLDER = "icons/"; //$NON-NLS-1$
//
@@ -82,19 +89,30 @@
String WIZARD_ICONS_FOLDER = ICON_FOLDER + "wizards/"; //$NON-NLS-1$
String DNA_WIZARD_BANNER_IMAGE = WIZARD_ICONS_FOLDER +
"dna_wizard_banner.gif"; //$NON-NLS-1$
-
+
//
// Help Contexts
//
-
+
String HELP_CONTEXT_PREFIX = PLUGIN_ID + '.';
-
+
String DNA_CONSOLE_HELP_CONTEXT = HELP_CONTEXT_PREFIX +
"dnaConsoleHelpContext"; //$NON-NLS-1$
-
+
String PUBLISH_DIALOG_HELP_CONTEXT = HELP_CONTEXT_PREFIX +
"publishDialogHelpContext"; //$NON-NLS-1$
-
+
String SERVER_DIALOG_HELP_CONTEXT = HELP_CONTEXT_PREFIX +
"serverDialogHelpContext"; //$NON-NLS-1$
-
+
String SERVER_VIEW_HELP_CONTEXT = HELP_CONTEXT_PREFIX +
"serverViewHelpContext"; //$NON-NLS-1$
+ //
+ // Jobs
+ //
+
+ /**
+ * The <code>Job</code> framework job family for the DNA publishing and
unpublishing operations.
+ *
+ * @since 0.6
+ */
+ String DNA_PUBLISHING_JOB_FAMILY = "dna.publishing.job.family";
//$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-19
16:26:03 UTC (rev 1169)
+++
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)
@@ -55,9 +55,10 @@
public static I18n newServerActionText;
public static I18n newServerActionToolTip;
- public static I18n publishJobPublishCanceledMsg;
public static I18n publishJobConsoleName;
public static I18n publishJobPublish;
+ public static I18n publishJobPublishCanceledMsg;
+ public static I18n publishJobProblemCreatingHyperlinkMsg;
public static I18n publishJobPublishFile;
public static I18n publishJobPublishFileFailed;
public static I18n publishJobPublishFileInfo;
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-19
16:26:03 UTC (rev 1169)
+++
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)
@@ -45,23 +45,24 @@
newServerActionToolTip = Create a new server
publishJobConsoleName = DNA
-publishJobPublish = Publishing {3} file(s) to server "{0}" (repository
"{1}", workspace "{2}") ...
-publishJobPublishCanceledMsg = i Publishing to server "{0}" (repository
"{1}", workspace "{2}") was canceled after {3} file(s) out of {4} were
processed.\n
-publishJobPublishFile = \t+ Published file "{0}" to location "{1}"
-publishJobPublishFileFailed = \t* ERROR publishing file "{0}" to location
"{1}"
-publishJobPublishFileInfo = \ti {0}
-publishJobPublishFileWarning = \tw {0}
-publishJobPublishFinishedMsg = Done publishing ({3} milliseconds) to server
"{0}" (repository "{1}", workspace "{2}").\n
-publishJobPublishName = DNA Publish
+publishJobProblemCreatingHyperlinkMsg = Unexpected problem creating hyperlink in DNA
Console view
+publishJobPublish = [{0}] Publishing {4} file(s) to server "{1}" (repository
"{2}", workspace "{3}") ...
+publishJobPublishCanceledMsg = [{0}] ! Publishing to server "{1}" (repository
"{2}", workspace "{3}") was canceled after {4} file(s) out of {5} were
processed.\n
+publishJobPublishFile = \t[{0}] + Published file "{1}"
+publishJobPublishFileFailed = \t[{0}] * Publishing file "{1}" generated an
ERROR message. See log.
+publishJobPublishFileInfo = \t[{0}] i Publishing file "{1}" generated an INFO
message. See log.
+publishJobPublishFileWarning = \t[{0}] w Publishing file "{1}" generated a
WARNING message. See log.
+publishJobPublishFinishedMsg = [{0}] Done publishing ({4} milliseconds) to server
"{1}" (repository "{2}", workspace "{3}").\n
+publishJobPublishName = DNA Publish
publishJobPublishTaskName = Publishing resources
publishJobUnexpectedErrorMsg = Unexpected error occurred. See log for more details.
-publishJobUnpublish = Unpublishing {3} file(s) from server "{0}" (repository
"{1}", workspace "{2}") ...
-publishJobUnpublishCanceledMsg = * Unpublishing from server "{0}" (repository
"{1}", workspace "{2}") was canceled after {3} file(s) out of {4} were
processed.\n
-publishJobUnpublishFile = \t- Unpublished file "{0}" from location
"{1}"
-publishJobUnpublishFileFailed = \t* ERROR unpublished file "{0}" from location
"{1}"
-publishJobUnpublishFileInfo = \ti {0}
-publishJobUnpublishFileWarning = \tw {0}
-publishJobUnpublishFinishedMsg = Done unpublishing ({3} milliseconds) from server
"{0}" (repository "{1}", workspace "{2}").\n
+publishJobUnpublish = [{0}] Unpublishing {4} file(s) from server "{1}"
(repository "{2}", workspace "{3}") ...
+publishJobUnpublishCanceledMsg = [{0}] ! Unpublishing from server "{1}"
(repository "{2}", workspace "{3}") was canceled after {4} file(s) out
of {5} were processed.\n
+publishJobUnpublishFile = \t[{0}] - Unpublished file "{1}"
+publishJobUnpublishFileFailed = \t[{0}] * Unpublishing file "{0}" generated an
ERROR message. See log.
+publishJobUnpublishFileInfo = \t[{0}] i Unpublishing file "{1}" generated an
INFO message. See log.
+publishJobUnpublishFileWarning = \t[{0}] w Unpublishing file "{1}" generated a
WARNING message. See log.
+publishJobUnpublishFinishedMsg = [{0}] Done unpublishing ({4} milliseconds) from server
"{1}" (repository "{2}", workspace "{3}").\n
publishJobUnpublishName = DNA Unpublish
publishJobUnpublishTaskName = Unpublishing resources
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-19
16:26:03 UTC (rev 1169)
+++
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)
@@ -23,13 +23,23 @@
*/
package org.jboss.dna.web.jcr.rest.client.swt.wizards;
+import static org.jboss.dna.web.jcr.rest.client.swt.IUiConstants.DNA_CONSOLE_ID;
+import static
org.jboss.dna.web.jcr.rest.client.swt.IUiConstants.DNA_PUBLISHING_JOB_FAMILY;
import static org.jboss.dna.web.jcr.rest.client.swt.IUiConstants.PLUGIN_ID;
import java.io.File;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.ui.console.FileLink;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
@@ -38,6 +48,7 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.web.jcr.rest.client.ServerManager;
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;
import org.jboss.dna.web.jcr.rest.client.swt.Activator;
import org.jboss.dna.web.jcr.rest.client.swt.RestClientI18n;
@@ -81,6 +92,13 @@
*/
static final String CONSOLE_NAME = RestClientI18n.publishJobConsoleName.text();
+ /**
+ * A unique job identifier given to each publishing/unpublishing job.
+ *
+ * @since 0.6
+ */
+ private static final AtomicInteger JOB_ID = new AtomicInteger(1);
+
//
===========================================================================================================================
// Class Methods
//
===========================================================================================================================
@@ -155,6 +173,45 @@
//
===========================================================================================================================
/**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
+ * @since 0.6
+ */
+ @Override
+ public boolean belongsTo( Object family ) {
+ return DNA_PUBLISHING_JOB_FAMILY.equals(family);
+ }
+
+ /**
+ * Note: The <code>DnaConsole</code> should
<strong>NOT</strong> be cached as the user can open/close/create instances.
+ *
+ * @return the DNA Message Console if available or a new one
+ * @since 0.6
+ */
+ private DnaConsole getDnaConsole() {
+ DnaConsole console = null;
+ IConsoleManager consoleMgr = ConsolePlugin.getDefault().getConsoleManager();
+ IConsole[] consoles = consoleMgr.getConsoles();
+
+ // see if DNA console already exists
+ for (int i = 0; i < consoles.length; ++i) {
+ if (CONSOLE_NAME.equals(consoles[i].getName())) {
+ console = (DnaConsole)consoles[i];
+ break;
+ }
+ }
+
+ // create DNA console if necessary
+ if (console == null) {
+ console = new DnaConsole();
+ consoleMgr.addConsoles(new IConsole[] {console});
+ }
+
+ return console;
+ }
+
+ /**
* @return <code>true</code> if a publishing job
* @since 0.6
*/
@@ -171,6 +228,7 @@
@Override
protected IStatus run( IProgressMonitor monitor ) {
assert (this.workspace != null);
+ int jobId = JOB_ID.getAndIncrement();
long startTime = System.currentTimeMillis();
try {
@@ -180,15 +238,17 @@
// write initial message to console
if (isPublishing()) {
-
writeToConsole(RestClientI18n.publishJobPublish.text(this.workspace.getServer().getUrl(),
-
this.workspace.getRepository().getName(),
-
this.workspace.getName(),
-
this.files.size()));
+ writeToConsole(getDnaConsole(),
RestClientI18n.publishJobPublish.text(jobId,
+
this.workspace.getServer().getUrl(),
+
this.workspace.getRepository().getName(),
+
this.workspace.getName(),
+
this.files.size()));
} else {
-
writeToConsole(RestClientI18n.publishJobUnpublish.text(this.workspace.getServer().getUrl(),
-
this.workspace.getRepository().getName(),
-
this.workspace.getName(),
-
this.files.size()));
+ writeToConsole(getDnaConsole(),
RestClientI18n.publishJobUnpublish.text(jobId,
+
this.workspace.getServer().getUrl(),
+
this.workspace.getRepository().getName(),
+
this.workspace.getName(),
+
this.files.size()));
}
// process the files
@@ -199,20 +259,22 @@
String msg = null;
if (isPublishing()) {
- msg =
RestClientI18n.publishJobPublishCanceledMsg.text(this.workspace.getServer().getUrl(),
+ msg = RestClientI18n.publishJobPublishCanceledMsg.text(jobId,
+
this.workspace.getServer().getUrl(),
this.workspace.getRepository().getName(),
this.workspace.getName(),
numProcessed,
this.files.size());
} else {
- msg =
RestClientI18n.publishJobUnpublishCanceledMsg.text(this.workspace.getServer().getUrl(),
+ msg = RestClientI18n.publishJobUnpublishCanceledMsg.text(jobId,
+
this.workspace.getServer().getUrl(),
this.workspace.getRepository().getName(),
this.workspace.getName(),
numProcessed,
this.files.size());
}
- writeToConsole(msg); // write cancel msg to console
+ writeToConsole(getDnaConsole(), msg); // write cancel msg to console
throw new InterruptedException(msg);
}
@@ -232,8 +294,8 @@
++numProcessed;
monitor.worked(1);
- // write success msg to console
- writeToConsole(file, eclipseFile.getParent().getFullPath().toString(),
status);
+ // write outcome msg to console
+ writeToConsole(jobId, eclipseFile, status);
}
return org.eclipse.core.runtime.Status.OK_STATUS;
@@ -249,17 +311,22 @@
return new org.eclipse.core.runtime.Status(IStatus.ERROR, PLUGIN_ID, msg,
e);
} finally {
monitor.done();
- // add done msg
+
+ // add operation done msg
// TODO need to format this duration better
long duration = System.currentTimeMillis() - startTime;
if (isPublishing()) {
-
writeToConsole(RestClientI18n.publishJobPublishFinishedMsg.text(this.workspace.getServer().getUrl(),
+ writeToConsole(getDnaConsole(),
+ RestClientI18n.publishJobPublishFinishedMsg.text(jobId,
+
this.workspace.getServer().getUrl(),
this.workspace.getRepository().getName(),
this.workspace.getName(),
duration));
} else {
-
writeToConsole(RestClientI18n.publishJobUnpublishFinishedMsg.text(this.workspace.getServer().getUrl(),
+ writeToConsole(getDnaConsole(),
+ RestClientI18n.publishJobUnpublishFinishedMsg.text(jobId,
+
this.workspace.getServer().getUrl(),
this.workspace.getRepository().getName(),
this.workspace.getName(),
duration));
@@ -268,69 +335,104 @@
}
/**
+ * @param jobId the job ID
* @param file the file involved in the publishing operation
- * @param workspacePath the path in the workspace where the file is located
* @param status the status of the publishing operation
* @since 0.6
*/
- private void writeToConsole( File file,
- String workspacePath,
+ private void writeToConsole( int jobId,
+ final IFile file,
Status status ) {
String msg = null;
if (status.isOk()) {
if (isPublishing()) {
- msg = RestClientI18n.publishJobPublishFile.text(file.getAbsolutePath(),
workspacePath);
+ msg = RestClientI18n.publishJobPublishFile.text(jobId,
file.getFullPath());
} else {
- msg = RestClientI18n.publishJobUnpublishFile.text(file.getAbsolutePath(),
workspacePath);
+ msg = RestClientI18n.publishJobUnpublishFile.text(jobId,
file.getFullPath());
}
} else if (status.isError()) {
if (isPublishing()) {
- msg =
RestClientI18n.publishJobPublishFileFailed.text(file.getAbsolutePath(), workspacePath);
+ msg = RestClientI18n.publishJobPublishFileFailed.text(jobId,
file.getFullPath());
} else {
- msg =
RestClientI18n.publishJobUnpublishFileFailed.text(file.getAbsolutePath(), workspacePath);
+ msg = RestClientI18n.publishJobUnpublishFileFailed.text(jobId,
file.getFullPath());
}
+
+ // log
+ Activator.getDefault().log(status);
} else if (status.isWarning()) {
if (isPublishing()) {
- msg =
RestClientI18n.publishJobPublishFileWarning.text(status.getMessage());
+ msg = RestClientI18n.publishJobPublishFileWarning.text(jobId,
file.getFullPath());
} else {
- msg =
RestClientI18n.publishJobUnpublishFileWarning.text(status.getMessage());
+ msg = RestClientI18n.publishJobUnpublishFileWarning.text(jobId,
file.getFullPath());
}
- } else if (status.isInfo()) {
+
+ // log
+ Activator.getDefault().log(status);
+ } else {
if (isPublishing()) {
- msg =
RestClientI18n.publishJobPublishFileInfo.text(status.getMessage());
+ msg = RestClientI18n.publishJobPublishFileInfo.text(jobId,
file.getFullPath());
} else {
- msg =
RestClientI18n.publishJobUnpublishFileInfo.text(status.getMessage());
+ msg = RestClientI18n.publishJobUnpublishFileInfo.text(jobId,
file.getFullPath());
}
+
+ // log
+ Activator.getDefault().log(status);
}
- // TODO create hyperlink in console for the file
- writeToConsole(msg);
+ // write to DNA Console
+ final DnaConsole dnaConsole = getDnaConsole();
+ final String consoleMsg = msg;
+ final IDocument doc = dnaConsole.getDocument();
+
+ // add listener that will add the hyperlink in the console for the file just
published/unpublished
+ doc.addDocumentListener(new IDocumentListener() {
+ @Override
+ public void documentAboutToBeChanged( DocumentEvent event ) {
+ // nothing to do
+ }
+
+ @Override
+ public void documentChanged( DocumentEvent event ) {
+ try {
+ // add hyperlink to console
+ int startIndex = consoleMsg.indexOf('"');
+
+ if (startIndex != -1) {
+ ++startIndex; // move after the '""
+ int lastIndex = consoleMsg.lastIndexOf('"');
+
+ if (lastIndex != -1) {
+ --lastIndex; // move before the '"'
+ FindReplaceDocumentAdapter finder = new
FindReplaceDocumentAdapter(doc);
+ IRegion region = finder.find(0, consoleMsg, true, true,
false, false);
+
+ if (region != null) {
+ dnaConsole.addHyperlink(new FileLink(file, null, -1, -1,
-1),
+ (region.getOffset() +
startIndex),
+ (lastIndex - startIndex + 1));
+ doc.removeDocumentListener(this);
+ }
+ }
+ }
+ } catch (BadLocationException e) {
+ Activator.getDefault().log(new Status(Severity.ERROR,
+
RestClientI18n.publishJobProblemCreatingHyperlinkMsg.text(), e));
+ doc.removeDocumentListener(this);
+ }
+ }
+ });
+
+ writeToConsole(dnaConsole, msg);
}
/**
- * @param message the message being written to the DNA console
+ * @param console the DNA console being written to
+ * @param message the message being written
* @since 0.6
*/
- private void writeToConsole( String message ) {
- MessageConsole console = null;
- IConsoleManager consoleMgr = ConsolePlugin.getDefault().getConsoleManager();
- IConsole[] consoles = consoleMgr.getConsoles();
-
- // see if DNA console already exists
- for (int i = 0; i < consoles.length; ++i) {
- if (CONSOLE_NAME.equals(consoles[i].getName())) {
- console = (MessageConsole)consoles[i];
- break;
- }
- }
-
- // create DNA console if necessary
- if (console == null) {
- console = new DnaConsole();
- consoleMgr.addConsoles(new IConsole[] {console});
- }
-
+ private void writeToConsole( MessageConsole console,
+ String message ) {
// show and focus console view
console.activate();
@@ -345,10 +447,23 @@
class DnaConsole extends MessageConsole {
+ /**
+ * @since 0.6
+ */
public DnaConsole() {
super(CONSOLE_NAME, null);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.console.AbstractConsole#getType()
+ * @since 0.6
+ */
+ @Override
+ public String getType() {
+ return DNA_CONSOLE_ID;
+ }
}
}