You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
(46) |
Oct
(102) |
Nov
(10) |
Dec
(21) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(1) |
Feb
(3) |
Mar
(14) |
Apr
(9) |
May
(12) |
Jun
(4) |
Jul
(40) |
Aug
(60) |
Sep
(38) |
Oct
(2) |
Nov
(1) |
Dec
(42) |
| 2008 |
Jan
(23) |
Feb
(29) |
Mar
(107) |
Apr
(27) |
May
(3) |
Jun
(1) |
Jul
(15) |
Aug
(7) |
Sep
(19) |
Oct
|
Nov
(2) |
Dec
|
| 2009 |
Jan
(36) |
Feb
(4) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(15) |
Jul
(30) |
Aug
(32) |
Sep
(11) |
Oct
(21) |
Nov
(12) |
Dec
(15) |
| 2010 |
Jan
(29) |
Feb
(9) |
Mar
(25) |
Apr
|
May
(7) |
Jun
(5) |
Jul
(21) |
Aug
(32) |
Sep
(10) |
Oct
(8) |
Nov
(29) |
Dec
(8) |
| 2011 |
Jan
(9) |
Feb
(35) |
Mar
(11) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(30) |
| 2012 |
Jan
(5) |
Feb
(7) |
Mar
(10) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <pat...@us...> - 2010-08-03 17:01:00
|
Revision: 1102
http://cishell.svn.sourceforge.net/cishell/?rev=1102&view=rev
Author: pataphil
Date: 2010-08-03 17:00:54 +0000 (Tue, 03 Aug 2010)
Log Message:
-----------
Initial import of org.cishell.utilities.swt.
Added Paths:
-----------
trunk/core/org.cishell.utilities.swt/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-08-02 20:27:00
|
Revision: 1101
http://cishell.svn.sourceforge.net/cishell/?rev=1101&view=rev
Author: pataphil
Date: 2010-08-02 20:26:54 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
* Moved ObjectContainer to org.cishell.utilities.datastructure.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
Removed Paths:
-------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java
Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-02 20:26:26 UTC (rev 1100)
+++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-02 20:26:54 UTC (rev 1101)
@@ -12,6 +12,7 @@
org.cishell.framework.data,
org.cishell.reference.service.metatype,
org.cishell.service.database,
+ org.cishell.utilities.datastructure,
org.joda.time,
org.joda.time.base,
org.joda.time.chrono,
Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java 2010-08-02 20:26:26 UTC (rev 1100)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java 2010-08-02 20:26:54 UTC (rev 1101)
@@ -1,12 +0,0 @@
-package org.cishell.utilities;
-
-public class ObjectContainer<T> {
- public T object;
-
- public ObjectContainer() {
- }
-
- public ObjectContainer(T object) {
- this.object = object;
- }
-};
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-02 20:26:26 UTC (rev 1100)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-02 20:26:54 UTC (rev 1101)
@@ -1,6 +1,6 @@
package org.cishell.utilities.swt;
-import org.cishell.utilities.ObjectContainer;
+import org.cishell.utilities.datastructure.ObjectContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-08-02 20:26:32
|
Revision: 1100
http://cishell.svn.sourceforge.net/cishell/?rev=1100&view=rev
Author: pataphil
Date: 2010-08-02 20:26:26 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
* Initial commit of org.cishell.utilities.datastructure.
* Contains ObjectContainer as well.
Added Paths:
-----------
trunk/core/org.cishell.utilities.datastructure/.classpath
trunk/core/org.cishell.utilities.datastructure/.project
trunk/core/org.cishell.utilities.datastructure/.settings/
trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.jdt.core.prefs
trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.pde.core.prefs
trunk/core/org.cishell.utilities.datastructure/META-INF/
trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF
trunk/core/org.cishell.utilities.datastructure/build.properties
trunk/core/org.cishell.utilities.datastructure/src/
trunk/core/org.cishell.utilities.datastructure/src/org/
trunk/core/org.cishell.utilities.datastructure/src/org/cishell/
trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/
trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/
trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java
Added: trunk/core/org.cishell.utilities.datastructure/.classpath
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/.classpath (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/.classpath 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/core/org.cishell.utilities.datastructure/.project
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/.project (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/.project 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.cishell.utilities.datastructure</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.jdt.core.prefs 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,7 @@
+#Mon Aug 02 13:13:19 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.pde.core.prefs
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.pde.core.prefs (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/.settings/org.eclipse.pde.core.prefs 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,5 @@
+#Mon Aug 02 13:13:19 EDT 2010
+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
+resolve.requirebundle=false
Added: trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Datastructure Plug-in
+Bundle-SymbolicName: org.cishell.utilities.datastructure
+Bundle-Version: 1.0.0
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.cishell.utilities.datastructure
Added: trunk/core/org.cishell.utilities.datastructure/build.properties
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/build.properties (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/build.properties 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Copied: trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java)
===================================================================
--- trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java (rev 0)
+++ trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java 2010-08-02 20:26:26 UTC (rev 1100)
@@ -0,0 +1,12 @@
+package org.cishell.utilities.datastructure;
+
+public class ObjectContainer<T> {
+ public T object;
+
+ public ObjectContainer() {
+ }
+
+ public ObjectContainer(T object) {
+ this.object = object;
+ }
+};
\ No newline at end of file
Property changes on: trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java
___________________________________________________________________
Added: svn:mergeinfo
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-08-02 19:04:29
|
Revision: 1099
http://cishell.svn.sourceforge.net/cishell/?rev=1099&view=rev
Author: pataphil
Date: 2010-08-02 19:04:23 +0000 (Mon, 02 Aug 2010)
Log Message:
-----------
Initial import of org.cishell.utilities.datastructure.
Added Paths:
-----------
trunk/core/org.cishell.utilities.datastructure/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-30 17:47:34
|
Revision: 1098
http://cishell.svn.sourceforge.net/cishell/?rev=1098&view=rev
Author: pataphil
Date: 2010-07-30 17:47:28 +0000 (Fri, 30 Jul 2010)
Log Message:
-----------
* Fixed bug in FileSaveAs where new files could not be created.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-07-29 19:30:31 UTC (rev 1097)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-07-30 17:47:28 UTC (rev 1098)
@@ -43,6 +43,8 @@
String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) {
return selectedFilePath;
}
+ } else {
+ return selectedFilePath;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-29 19:30:37
|
Revision: 1097
http://cishell.svn.sourceforge.net/cishell/?rev=1097&view=rev
Author: pataphil
Date: 2010-07-29 19:30:31 +0000 (Thu, 29 Jul 2010)
Log Message:
-----------
* Very minor clean-up.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-07-28 13:07:21 UTC (rev 1096)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-07-29 19:30:31 UTC (rev 1097)
@@ -43,15 +43,6 @@
String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) {
return selectedFilePath;
}
-//
-// MessageDialog confirmationDialog = new MessageDialog(
-// saveDialog.getParent(),
-// saveDialog.getText(),
-// null,
-// String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath),
-// 0,
-// BUTTON_LABELS,
-// 0);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-28 13:07:27
|
Revision: 1096
http://cishell.svn.sourceforge.net/cishell/?rev=1096&view=rev
Author: pataphil
Date: 2010-07-28 13:07:21 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
* Bug fixing.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2010-07-27 19:35:28 UTC (rev 1095)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2010-07-28 13:07:21 UTC (rev 1096)
@@ -378,7 +378,7 @@
}
}
- return parseDate(objectAsString, dateFormat, fixYear);
+ return parseDate(objectAsString.trim(), dateFormat, fixYear);
}
private static Date fixDateYear(Date date) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-27 19:35:34
|
Revision: 1095
http://cishell.svn.sourceforge.net/cishell/?rev=1095&view=rev
Author: pataphil
Date: 2010-07-27 19:35:28 +0000 (Tue, 27 Jul 2010)
Log Message:
-----------
* Added FileSaveAs to SWT utilities.
* Not reviewed.
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-07-27 19:35:28 UTC (rev 1095)
@@ -0,0 +1,59 @@
+package org.cishell.utilities.swt;
+
+import java.io.File;
+
+import org.cishell.utilities.StringUtilities;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+
+public class FileSaveAs {
+ public static final String DEFAULT_WINDOW_TITLE = "Save As";
+ public static final String CONFIRMATION_DIALOG_FORMAT =
+ "%s already exists.\nDo you want to replace it?";
+// public static final String YES_BUTTON_LABEL = "Yes";
+// public static final String NO_BUTTON_LABEL = "No";
+// public static final String[] BUTTON_LABELS = { YES_BUTTON_LABEL, NO_BUTTON_LABEL };
+
+ public static String saveFileAs(Shell parent) {
+ FileDialog saveDialog = new FileDialog(parent);
+ saveDialog.setText(DEFAULT_WINDOW_TITLE);
+
+ return saveFileAs(saveDialog);
+ }
+
+ public static String saveFileAs(Shell parent, int style) {
+ FileDialog saveDialog = new FileDialog(parent, style);
+ saveDialog.setText(DEFAULT_WINDOW_TITLE);
+
+ return saveFileAs(saveDialog);
+ }
+
+ public static String saveFileAs(FileDialog saveDialog) {
+ while (true) {
+ String selectedFilePath = saveDialog.open();
+
+ if (StringUtilities.isNull_Empty_OrWhitespace(selectedFilePath)) {
+ return null;
+ } else {
+ if (new File(selectedFilePath).exists()) {
+ if (MessageDialog.openConfirm(
+ saveDialog.getParent(),
+ saveDialog.getText(),
+ String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) {
+ return selectedFilePath;
+ }
+//
+// MessageDialog confirmationDialog = new MessageDialog(
+// saveDialog.getParent(),
+// saveDialog.getText(),
+// null,
+// String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath),
+// 0,
+// BUTTON_LABELS,
+// 0);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-26 22:47:43
|
Revision: 1094
http://cishell.svn.sourceforge.net/cishell/?rev=1094&view=rev
Author: pataphil
Date: 2010-07-26 22:47:37 +0000 (Mon, 26 Jul 2010)
Log Message:
-----------
* Added StringUtilities.stripSurroundingQuotes().
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-21 03:50:35 UTC (rev 1093)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-26 22:47:37 UTC (rev 1094)
@@ -333,6 +333,7 @@
}
}
+ // TODO: Use StreamTokenizer?
public static String[] tokenizeByWhitespace(String originalString) {
StringTokenizer tokenizer = new StringTokenizer(originalString);
int tokenCount = tokenizer.countTokens();
@@ -345,6 +346,18 @@
return tokens;
}
+ public static String stripSurroundingQuotes(String quoted) {
+ if (quoted.startsWith("\"")) {
+ if (quoted.endsWith("\"")) {
+ return quoted.substring(1, quoted.length() - 1);
+ } else {
+ return quoted.substring(1);
+ }
+ } else {
+ return quoted;
+ }
+ }
+
// TODO
// public static String escape(String unescaped) {
// return unescaped.replaceAll("\"", "\\\""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-21 03:50:43
|
Revision: 1093
http://cishell.svn.sourceforge.net/cishell/?rev=1093&view=rev
Author: pataphil
Date: 2010-07-21 03:50:35 +0000 (Wed, 21 Jul 2010)
Log Message:
-----------
* Added GUIBuilderUtilities.setCancelable().
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ObjectContainer.java 2010-07-21 03:50:35 UTC (rev 1093)
@@ -0,0 +1,12 @@
+package org.cishell.utilities;
+
+public class ObjectContainer<T> {
+ public T object;
+
+ public ObjectContainer() {
+ }
+
+ public ObjectContainer(T object) {
+ this.object = object;
+ }
+};
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-07-21 03:49:14 UTC (rev 1092)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-07-21 03:50:35 UTC (rev 1093)
@@ -1,9 +1,14 @@
package org.cishell.utilities.swt;
+import org.cishell.utilities.ObjectContainer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class GUIBuilderUtilities {
@@ -75,4 +80,45 @@
public static void clearSpacing(GridLayout layout) {
layout.horizontalSpacing = layout.verticalSpacing = 0;
}
+
+ public static void setCancelable(
+ final Shell shell, final ObjectContainer<GUICanceledException> exceptionThrown) {
+ shell.addListener(SWT.Traverse, new Listener() {
+ public void handleEvent(Event event) {
+ switch (event.detail) {
+ case SWT.TRAVERSE_ESCAPE:
+ shell.close();
+ event.detail = SWT.TRAVERSE_NONE;
+ event.doit = false;
+
+// if (exceptionThrown != null) {
+// String exceptionMessage = "Canceled by user.";
+// exceptionThrown.object = new GUICanceledException(exceptionMessage);
+// }
+
+ break;
+ }
+ }
+ });
+ shell.addShellListener(new ShellListener() {
+ public void shellActivated(ShellEvent event) {
+ }
+
+ public void shellClosed(ShellEvent event) {
+ if (exceptionThrown != null) {
+ String exceptionMessage = "Canceled by user.";
+ exceptionThrown.object = new GUICanceledException(exceptionMessage);
+ }
+ }
+
+ public void shellDeactivated(ShellEvent event) {
+ }
+
+ public void shellDeiconified(ShellEvent event) {
+ }
+
+ public void shellIconified(ShellEvent event) {
+ }
+ });
+ }
}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java 2010-07-21 03:50:35 UTC (rev 1093)
@@ -0,0 +1,21 @@
+package org.cishell.utilities.swt;
+
+public class GUICanceledException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public GUICanceledException() {
+ super();
+ }
+
+ public GUICanceledException(String arg0) {
+ super(arg0);
+ }
+
+ public GUICanceledException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public GUICanceledException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-21 03:49:20
|
Revision: 1092
http://cishell.svn.sourceforge.net/cishell/?rev=1092&view=rev
Author: pataphil
Date: 2010-07-21 03:49:14 +0000 (Wed, 21 Jul 2010)
Log Message:
-----------
* Added AlgorithmCreationCanceledException and AlgorithmCreationFailedException with the intent of eventually modifying AlgorithmFactory/etc.
* Marked up AlgorithmFactory with intentions.
Modified Paths:
--------------
trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmExecutionException.java
trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java
Added Paths:
-----------
trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java
trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java
Added: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java (rev 0)
+++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java 2010-07-21 03:49:14 UTC (rev 1092)
@@ -0,0 +1,22 @@
+package org.cishell.framework.algorithm;
+
+// TODO: Make this a regular Exception (not RuntimeException).
+public class AlgorithmCreationCanceledException extends RuntimeException {
+ private static final long serialVersionUID = 9017277008277139930L;
+
+ public AlgorithmCreationCanceledException(String message, Throwable exception) {
+ super(message, exception);
+ }
+
+ public AlgorithmCreationCanceledException(Throwable exception) {
+ super(exception);
+ }
+
+ public AlgorithmCreationCanceledException(String message) {
+ super(message);
+ }
+
+ public AlgorithmCreationCanceledException() {
+ this("Algorithm canceled by user.");
+ }
+}
Added: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java (rev 0)
+++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java 2010-07-21 03:49:14 UTC (rev 1092)
@@ -0,0 +1,22 @@
+package org.cishell.framework.algorithm;
+
+// TODO: Make this a regular Exception (not RuntimeException).
+public class AlgorithmCreationFailedException extends RuntimeException {
+ private static final long serialVersionUID = 9017277008277139930L;
+
+ public AlgorithmCreationFailedException(String message, Throwable exception) {
+ super(message, exception);
+ }
+
+ public AlgorithmCreationFailedException(Throwable exception) {
+ super(exception);
+ }
+
+ public AlgorithmCreationFailedException(String message) {
+ super(message);
+ }
+
+ public AlgorithmCreationFailedException() {
+ this("Algorithm canceled by user.");
+ }
+}
Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmExecutionException.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmExecutionException.java 2010-07-21 00:47:14 UTC (rev 1091)
+++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmExecutionException.java 2010-07-21 03:49:14 UTC (rev 1092)
@@ -16,8 +16,7 @@
/**
* An exception which is thrown when an error occurs in the process of executing
* an {@link Algorithm}
- *
- * @author Bruce Herr (bh...@bh...)
+ *
*/
public class AlgorithmExecutionException extends Exception {
private static final long serialVersionUID = 9017277008277139930L;
Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java
===================================================================
--- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java 2010-07-21 00:47:14 UTC (rev 1091)
+++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java 2010-07-21 03:49:14 UTC (rev 1092)
@@ -51,6 +51,9 @@
* standard CIShell services
* @return An <code>Algorithm</code> primed for execution
*/
+ /* TODO: Add AlgorithmCreationCanceledException and AlgorithmCreationFailedException to
+ * the signature, and update the entire code base to conform to it.
+ */
public Algorithm createAlgorithm(
Data[] data, Dictionary<String, Object> parameters, CIShellContext context);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-21 00:47:21
|
Revision: 1091
http://cishell.svn.sourceforge.net/cishell/?rev=1091&view=rev
Author: pataphil
Date: 2010-07-21 00:47:14 +0000 (Wed, 21 Jul 2010)
Log Message:
-----------
* Added MapUtilities.valuesByKeys().
* Fixed some SWT GUIModel bugs.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-16 02:11:57 UTC (rev 1090)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-21 00:47:14 UTC (rev 1091)
@@ -63,4 +63,18 @@
return valuesByIndex;
}
+
+ public static<K, V> void valuesByKeys(
+ Map<K, V> items, Collection<K> keys, Collection<V> target) {
+ for (K key : keys) {
+ target.add(items.get(key));
+ }
+ }
+
+ public static<K, V> Collection<V> valuesByKeys(Map<K, V> items, Collection<K> keys) {
+ List<V> values = new ArrayList<V>();
+ valuesByKeys(items, keys, values);
+
+ return values;
+ }
}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-07-16 02:11:57 UTC (rev 1090)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-07-21 00:47:14 UTC (rev 1091)
@@ -50,6 +50,8 @@
public<T> void removeField(
GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- this.inputFieldsByName.remove(field);
+ if (this.inputFieldsByName.containsValue(field)) {
+ this.inputFieldsByName.remove(field.getName());
+ }
}
}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java 2010-07-16 02:11:57 UTC (rev 1090)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java 2010-07-21 00:47:14 UTC (rev 1091)
@@ -13,7 +13,7 @@
}
public int swtUpdateListenerCode() {
- return SWT.Selection;
+ return SWT.Modify;
}
public String value() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-16 02:12:03
|
Revision: 1090
http://cishell.svn.sourceforge.net/cishell/?rev=1090&view=rev
Author: pataphil
Date: 2010-07-16 02:11:57 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
* Fixed up GUIModel a tiny bit.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-15 08:30:27 UTC (rev 1089)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-16 02:11:57 UTC (rev 1090)
@@ -19,40 +19,44 @@
import org.eclipse.swt.widgets.Widget;
public class GUIModel {
- private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>
- inputFieldsByName = new HashMap<
- String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>();
+ private Map<String, GUIModelGroup> groups = new HashMap<String, GUIModelGroup>();
public GUIModel() {
}
- public Collection<String> getFieldNames() {
- return this.inputFieldsByName.keySet();
+ public Collection<String> getGroupNames() {
+ return this.groups.keySet();
}
- public Collection<
- GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() {
- return this.inputFieldsByName.values();
+ public Collection<GUIModelGroup> getGroups() {
+ return this.groups.values();
}
- public GUIModelField<
- ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) {
- return this.inputFieldsByName.get(name);
+ public GUIModelGroup getGroup(String name) {
+ if (!this.groups.containsKey(name)) {
+ GUIModelGroup newGroup = new GUIModelGroup(name);
+ this.groups.put(name, newGroup);
+
+ return newGroup;
+ } else {
+ return this.groups.get(name);
+ }
}
public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox(
- String name, boolean on, Composite parent, int style) {
+ String groupName, String name, boolean on, Composite parent, int style) {
Button checkBox = new Button(parent, style | SWT.CHECK);
CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on);
GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field =
new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>(
name, on, checkBox, dataSynchronizer);
- addField(field);
+ addField(groupName, field);
return field;
}
public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown(
+ String groupName,
String name,
int selectedIndex,
Collection<String> unorderedOptionLabels,
@@ -69,7 +73,7 @@
optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)),
dropDown,
dataSynchronizer);
- addField(field);
+ addField(groupName, field);
return field;
}
@@ -119,6 +123,7 @@
// TODO: Test this out.
public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList(
+ String groupName,
String name,
int selectedIndex,
Collection<String> unorderedOptionLabels,
@@ -133,7 +138,7 @@
GUIModelField<String, List, SingleListSelectionDataSynchronizer> field =
new GUIModelField<String, List, SingleListSelectionDataSynchronizer>(
name, list.getItem(selectedIndex), list, dataSynchronizer);
- addField(field);
+ addField(groupName, field);
return field;
}
@@ -147,6 +152,7 @@
// TODO: addStyledText
public GUIModelField<String, Text, TextDataSynchronizer> addText(
+ String groupName,
String name,
String value,
boolean isMultiLined,
@@ -163,21 +169,22 @@
GUIModelField<String, Text, TextDataSynchronizer> field =
new GUIModelField<String, Text, TextDataSynchronizer>(
name, value, text, dataSynchronizer);
- addField(field);
+ addField(groupName, field);
return field;
}
public<T> void addField(
+ String groupName,
GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
- String fieldName = field.getName();
+ GUIModelGroup group = getGroup(groupName);
+ group.addField(field);
+ }
- if (this.inputFieldsByName.containsKey(fieldName)) {
- String exceptionMessage =
- "A field with the name \"" + fieldName + "\" already exists. Unable to continue.";
- throw new ModelFieldException(exceptionMessage);
+ public<T> void removeField(
+ GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
+ for (GUIModelGroup group : this.groups.values()) {
+ group.removeField(field);
}
-
- this.inputFieldsByName.put(fieldName, field);
}
}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-07-16 02:11:57 UTC (rev 1090)
@@ -0,0 +1,55 @@
+package org.cishell.utilities.swt.model;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer;
+import org.eclipse.swt.widgets.Widget;
+
+public class GUIModelGroup {
+ private String name;
+ private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>
+ inputFieldsByName = new HashMap<
+ String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>();
+
+ public GUIModelGroup(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Collection<String> getFieldNames() {
+ return this.inputFieldsByName.keySet();
+ }
+
+ public Collection<
+ GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() {
+ return this.inputFieldsByName.values();
+ }
+
+ public GUIModelField<
+ ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) {
+ return this.inputFieldsByName.get(name);
+ }
+
+ public<T> void addField(
+ GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
+ String fieldName = field.getName();
+
+ if (this.inputFieldsByName.containsKey(fieldName)) {
+ String exceptionMessage =
+ "A field with the name \"" + fieldName + "\" already exists. Unable to continue.";
+ throw new ModelFieldException(exceptionMessage);
+ }
+
+ this.inputFieldsByName.put(fieldName, field);
+ }
+
+ public<T> void removeField(
+ GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
+ this.inputFieldsByName.remove(field);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-15 08:30:33
|
Revision: 1089
http://cishell.svn.sourceforge.net/cishell/?rev=1089&view=rev
Author: pataphil
Date: 2010-07-15 08:30:27 +0000 (Thu, 15 Jul 2010)
Log Message:
-----------
* Added ArrayListUtilities.copyAndSort().
* Fixed some GUIModel stuff.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -2,10 +2,18 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class ArrayListUtilities {
+ public static<T extends Comparable<T>> List<T> copyAndSort(Collection<T> items) {
+ List<T> copy = new ArrayList<T>(items);
+ Collections.sort(copy);
+
+ return copy;
+ }
+
// TODO: Move this to CollectionUtilities.
public static<T> Collection<T> unionCollections(
Collection<T> items1,
@@ -36,7 +44,25 @@
Collection<T> items1,
Collection<T> items2,
Collection<T> keysToSkip) {
- return new ArrayList<T>(unionCollections(items1, items2, keysToSkip));
+ List<T> union = new ArrayList<T>();
+
+ if (keysToSkip == null) {
+ keysToSkip = new ArrayList<T>();
+ }
+
+ for (T element : items1) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
+ union.add(element);
+ }
+ }
+
+ for (T element : items2) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
+ union.add(element);
+ }
+ }
+
+ return union;
}
/* Implodes list to a String with the String.valueOf the elements separated
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -2,7 +2,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -61,13 +60,15 @@
Composite parent,
int style) {
java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
- Collections.sort(orderedOptionLabels);
Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
GUIModelField<String, Combo, DropDownDataSynchronizer> field =
new GUIModelField<String, Combo, DropDownDataSynchronizer>(
- name, orderedOptionLabels.get(selectedIndex), dropDown, dataSynchronizer);
+ name,
+ optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)),
+ dropDown,
+ dataSynchronizer);
addField(field);
return field;
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -8,6 +8,7 @@
public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> {
private String name;
private T defaultValue;
+ private T previousValue;
private T value;
private U widget;
private V dataSynchronizer;
@@ -26,9 +27,9 @@
this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() {
public void handleEvent(Event event) {
if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
+ GUIModelField.this.previousValue = GUIModelField.this.value;
GUIModelField.this.value =
GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
- System.err.println(GUIModelField.this.value);
}
}
});
@@ -38,6 +39,10 @@
return this.name;
}
+ public T getPreviousValue() {
+ return this.previousValue;
+ }
+
public T getValue() {
return this.value;
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-07-13 21:30:22 UTC (rev 1088)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-07-15 08:30:27 UTC (rev 1089)
@@ -14,7 +14,7 @@
public class DropDownDataSynchronizer implements ModelDataSynchronizer<String> {
private Combo dropDown;
private BiMap<Integer, String> optionLabels;
- private Map<String, String> optionValuesByLabels;
+ private BiMap<String, String> optionValuesByLabels;
public DropDownDataSynchronizer(
Combo dropDown,
@@ -22,10 +22,8 @@
List<String> optionLabels,
Map<String, String> optionValuesByLabels) {
this.dropDown = dropDown;
- this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
- this.optionValuesByLabels = optionValuesByLabels;
- this.dropDown.setItems(optionLabels.toArray(new String[0]));
+ setOptions(optionLabels, optionValuesByLabels);
this.dropDown.select(selectedIndex);
}
@@ -39,11 +37,12 @@
}
public String synchronizeFromGUI() {
- return this.optionLabels.get(this.dropDown.getSelectionIndex());
+ return value();
}
public String synchronizeToGUI(String value) {
- this.dropDown.select(this.optionLabels.inverse().get(value));
+ String label = this.optionValuesByLabels.inverse().get(value);
+ this.dropDown.select(this.optionLabels.inverse().get(label));
return value();
}
@@ -51,4 +50,12 @@
public String reset(String defaultValue) {
return synchronizeToGUI(defaultValue);
}
+
+ public void setOptions(List<String> optionLabels, Map<String, String> optionValuesByLabels) {
+ this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
+ this.optionValuesByLabels = HashBiMap.create(optionValuesByLabels);
+
+ this.dropDown.setItems(optionLabels.toArray(new String[0]));
+ this.dropDown.select(0);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-13 21:30:28
|
Revision: 1088
http://cishell.svn.sourceforge.net/cishell/?rev=1088&view=rev
Author: pataphil
Date: 2010-07-13 21:30:22 +0000 (Tue, 13 Jul 2010)
Log Message:
-----------
* Added ArrayListUtilities.unionCollectionsAsList()
* Added CollectionUtilities.get()
* Added SWTUtilities.printURL()
* Mild, mild cleanup.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-13 18:06:07 UTC (rev 1087)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-13 21:30:22 UTC (rev 1088)
@@ -31,6 +31,13 @@
return union;
}
+
+ public static<T> List<T> unionCollectionsAsList(
+ Collection<T> items1,
+ Collection<T> items2,
+ Collection<T> keysToSkip) {
+ return new ArrayList<T>(unionCollections(items1, items2, keysToSkip));
+ }
/* Implodes list to a String with the String.valueOf the elements separated
* by separator and where all elements except the first prefixSize and
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-07-13 18:06:07 UTC (rev 1087)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-07-13 21:30:22 UTC (rev 1088)
@@ -28,4 +28,8 @@
return selectedElements;
}
+ @SuppressWarnings("unchecked")
+ public static<T> T get(Collection<T> values, int index) {
+ return (T) values.toArray()[index];
+ }
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java 2010-07-13 18:06:07 UTC (rev 1087)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java 2010-07-13 21:30:22 UTC (rev 1088)
@@ -4,6 +4,7 @@
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
public class SWTUtilities {
@@ -95,4 +96,28 @@
textField.setTopIndex(textField.getLineCount());
}
}
+
+ public static void printURL(
+ Composite parent,
+ StyledText textField,
+ String url,
+ String displayURL,
+ Color color,
+ int style) {
+ URLClickedListener urlClickedListener = new URLClickedListener(textField);
+ URLMouseCursorListener urlCursorListener =
+ new URLMouseCursorListener(parent, textField);
+ textField.addMouseListener(urlClickedListener);
+ textField.addMouseMoveListener(urlCursorListener);
+
+ urlClickedListener.addURL(
+ textField.getText().length(), url, displayURL);
+ urlCursorListener.addURL(
+ textField.getText().length(), url, displayURL);
+ SWTUtilities.styledPrint(
+ textField,
+ displayURL,
+ color,
+ style);
+ }
}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java 2010-07-13 18:06:07 UTC (rev 1087)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java 2010-07-13 21:30:22 UTC (rev 1088)
@@ -10,7 +10,7 @@
import org.eclipse.swt.program.Program;
/*
- * Listens for clicks on urls and launches a browser appropriately.
+ * Listens for clicks on urls and launches a browser.
*/
public class URLClickedListener extends MouseAdapter {
private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>();
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 18:06:07 UTC (rev 1087)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 21:30:22 UTC (rev 1088)
@@ -53,7 +53,7 @@
return field;
}
- public GUIModelField<String, Combo, DropDownDataSynchronizer> addSingleSelectionDropDown(
+ public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown(
String name,
int selectedIndex,
Collection<String> unorderedOptionLabels,
@@ -117,7 +117,7 @@
// TODO: addCalendar
// TODO: Test this out.
- public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addSingleSelectionList(
+ public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList(
String name,
int selectedIndex,
Collection<String> unorderedOptionLabels,
@@ -145,7 +145,7 @@
// TODO: addSpinner
// TODO: addStyledText
- public GUIModelField<String, Text, TextDataSynchronizer> addUnstyledText(
+ public GUIModelField<String, Text, TextDataSynchronizer> addText(
String name,
String value,
boolean isMultiLined,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-13 18:06:13
|
Revision: 1087
http://cishell.svn.sourceforge.net/cishell/?rev=1087&view=rev
Author: pataphil
Date: 2010-07-13 18:06:07 +0000 (Tue, 13 Jul 2010)
Log Message:
-----------
* Fixing build again. Hopefully.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-13 15:13:45 UTC (rev 1086)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-13 18:06:07 UTC (rev 1087)
@@ -23,6 +23,7 @@
return workingKeys;
}
+ /* Maps items to themselves in a Map. */
public static<T> Map<T, T> mirror(Collection<T> items) {
Map<T, T> mirroredItems = new HashMap<T, T>();
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-07-13 15:13:45 UTC (rev 1086)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-07-13 18:06:07 UTC (rev 1087)
@@ -78,8 +78,6 @@
this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount);
this.uniqueComponentCount++;
-// Control componentControlHack = (Control) component;
-// componentControlHack.setLayoutData(createComponentLayoutData());
fixSize();
this.components.add(component);
@@ -88,7 +86,6 @@
}
public void removeComponent(int index) {
-// this.components.get(index).dispose();
this.scrolledAreaGrid.removeRow(index);
this.components.remove(index);
fixSize();
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 15:13:45 UTC (rev 1086)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 18:06:07 UTC (rev 1087)
@@ -7,12 +7,10 @@
import java.util.Map;
import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer;
-import org.cishell.utilities.swt.model.datasynchronizer.DateDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.TextDataSynchronizer;
-import org.cishell.utilities.swt.model.datasynchronizer.TimeDataSynchronizer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
@@ -78,43 +76,44 @@
// TODO: addMultiSelectionDropDown
// TODO: Test this out.
- public GUIModelField<
- org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer>
- addDate(String name, org.joda.time.DateTime date, Composite parent, int style) {
- org.eclipse.swt.widgets.DateTime dateSelector =
- new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE);
- DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date);
- GUIModelField<
- org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field =
- new GUIModelField<
- org.joda.time.DateTime,
- org.eclipse.swt.widgets.DateTime,
- DateDataSynchronizer>(
- name, date, dateSelector, dataSynchronizer);
- addField(field);
+ // TODO: Make it so the build works with this stuff.
+// public GUIModelField<
+// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer>
+// addDate(String name, org.joda.time.DateTime date, Composite parent, int style) {
+// org.eclipse.swt.widgets.DateTime dateSelector =
+// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE);
+// DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date);
+// GUIModelField<
+// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field =
+// new GUIModelField<
+// org.joda.time.DateTime,
+// org.eclipse.swt.widgets.DateTime,
+// DateDataSynchronizer>(
+// name, date, dateSelector, dataSynchronizer);
+// addField(field);
+//
+// return field;
+// }
- return field;
- }
-
// TODO: Test this out.
- public GUIModelField<
- org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer>
- addTime(String name, org.joda.time.DateTime time, Composite parent, int style) {
- org.eclipse.swt.widgets.DateTime timeSelector =
- new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME);
- TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time);
- GUIModelField<
- org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field =
- new GUIModelField<
- org.joda.time.DateTime,
- org.eclipse.swt.widgets.DateTime,
- TimeDataSynchronizer>(
- name, time, timeSelector, dataSynchronizer);
- addField(field);
+// public GUIModelField<
+// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer>
+// addTime(String name, org.joda.time.DateTime time, Composite parent, int style) {
+// org.eclipse.swt.widgets.DateTime timeSelector =
+// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME);
+// TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time);
+// GUIModelField<
+// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field =
+// new GUIModelField<
+// org.joda.time.DateTime,
+// org.eclipse.swt.widgets.DateTime,
+// TimeDataSynchronizer>(
+// name, time, timeSelector, dataSynchronizer);
+// addField(field);
+//
+// return field;
+// }
- return field;
- }
-
// TODO: addCalendar
// TODO: Test this out.
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-07-13 15:13:45 UTC (rev 1086)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-07-13 18:06:07 UTC (rev 1087)
@@ -1,42 +1,42 @@
-package org.cishell.utilities.swt.model.datasynchronizer;
-
-import org.eclipse.swt.SWT;
-
-public class DateDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
- private org.eclipse.swt.widgets.DateTime dateSelector;
-
- public DateDataSynchronizer(
- org.eclipse.swt.widgets.DateTime dateSelector, org.joda.time.DateTime date) {
- this.dateSelector = dateSelector;
- synchronizeToGUI(date);
- }
-
- public int swtUpdateListenerCode() {
- return SWT.Selection;
- }
-
- public org.joda.time.DateTime value() {
- return new org.joda.time.DateTime(
- this.dateSelector.getYear(),
- this.dateSelector.getMonth(),
- this.dateSelector.getDay(),
- 0,
- 0,
- 0,
- 0);
- }
-
- public org.joda.time.DateTime synchronizeFromGUI() {
- return value();
- }
-
- public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime date) {
- this.dateSelector.setDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
-
- return value();
- }
-
- public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
- return synchronizeToGUI(defaultValue);
- }
-}
\ No newline at end of file
+//package org.cishell.utilities.swt.model.datasynchronizer;
+//
+//import org.eclipse.swt.SWT;
+//
+//public class DateDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
+// private org.eclipse.swt.widgets.DateTime dateSelector;
+//
+// public DateDataSynchronizer(
+// org.eclipse.swt.widgets.DateTime dateSelector, org.joda.time.DateTime date) {
+// this.dateSelector = dateSelector;
+// synchronizeToGUI(date);
+// }
+//
+// public int swtUpdateListenerCode() {
+// return SWT.Selection;
+// }
+//
+// public org.joda.time.DateTime value() {
+// return new org.joda.time.DateTime(
+// this.dateSelector.getYear(),
+// this.dateSelector.getMonth(),
+// this.dateSelector.getDay(),
+// 0,
+// 0,
+// 0,
+// 0);
+// }
+//
+// public org.joda.time.DateTime synchronizeFromGUI() {
+// return value();
+// }
+//
+// public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime date) {
+// this.dateSelector.setDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
+//
+// return value();
+// }
+//
+// public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
+// return synchronizeToGUI(defaultValue);
+// }
+//}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java 2010-07-13 15:13:45 UTC (rev 1086)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java 2010-07-13 18:06:07 UTC (rev 1087)
@@ -1,43 +1,43 @@
-package org.cishell.utilities.swt.model.datasynchronizer;
-
-import org.eclipse.swt.SWT;
-
-public class TimeDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
- private org.eclipse.swt.widgets.DateTime timeSelector;
-
- public TimeDataSynchronizer(
- org.eclipse.swt.widgets.DateTime timeSelector, org.joda.time.DateTime time) {
- this.timeSelector = timeSelector;
- synchronizeToGUI(time);
- }
-
- public int swtUpdateListenerCode() {
- return SWT.Selection;
- }
-
- public org.joda.time.DateTime value() {
- return new org.joda.time.DateTime(
- 0,
- 0,
- 0,
- this.timeSelector.getHours(),
- this.timeSelector.getMinutes(),
- this.timeSelector.getSeconds(),
- 0);
- }
-
- public org.joda.time.DateTime synchronizeFromGUI() {
- return value();
- }
-
- public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime time) {
- this.timeSelector.setTime(
- time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute());
-
- return value();
- }
-
- public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
- return synchronizeToGUI(defaultValue);
- }
-}
\ No newline at end of file
+//package org.cishell.utilities.swt.model.datasynchronizer;
+//
+//import org.eclipse.swt.SWT;
+//
+//public class TimeDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
+// private org.eclipse.swt.widgets.DateTime timeSelector;
+//
+// public TimeDataSynchronizer(
+// org.eclipse.swt.widgets.DateTime timeSelector, org.joda.time.DateTime time) {
+// this.timeSelector = timeSelector;
+// synchronizeToGUI(time);
+// }
+//
+// public int swtUpdateListenerCode() {
+// return SWT.Selection;
+// }
+//
+// public org.joda.time.DateTime value() {
+// return new org.joda.time.DateTime(
+// 0,
+// 0,
+// 0,
+// this.timeSelector.getHours(),
+// this.timeSelector.getMinutes(),
+// this.timeSelector.getSeconds(),
+// 0);
+// }
+//
+// public org.joda.time.DateTime synchronizeFromGUI() {
+// return value();
+// }
+//
+// public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime time) {
+// this.timeSelector.setTime(
+// time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute());
+//
+// return value();
+// }
+//
+// public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
+// return synchronizeToGUI(defaultValue);
+// }
+//}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-13 15:13:52
|
Revision: 1086
http://cishell.svn.sourceforge.net/cishell/?rev=1086&view=rev
Author: pataphil
Date: 2010-07-13 15:13:45 +0000 (Tue, 13 Jul 2010)
Log Message:
-----------
* Fixing build. Hopefully.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-12 21:25:00 UTC (rev 1085)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-13 15:13:45 UTC (rev 1086)
@@ -17,7 +17,6 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
@@ -79,26 +78,38 @@
// TODO: addMultiSelectionDropDown
// TODO: Test this out.
- public GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer> addDate(
- String name, org.joda.time.DateTime date, Composite parent, int style) {
- DateTime dateSelector = new DateTime(parent, style | SWT.DATE);
+ public GUIModelField<
+ org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer>
+ addDate(String name, org.joda.time.DateTime date, Composite parent, int style) {
+ org.eclipse.swt.widgets.DateTime dateSelector =
+ new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE);
DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date);
- GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer> field =
- new GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer>(
- name, date, dateSelector, dataSynchronizer);
+ GUIModelField<
+ org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field =
+ new GUIModelField<
+ org.joda.time.DateTime,
+ org.eclipse.swt.widgets.DateTime,
+ DateDataSynchronizer>(
+ name, date, dateSelector, dataSynchronizer);
addField(field);
return field;
}
// TODO: Test this out.
- public GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer> addTime(
- String name, org.joda.time.DateTime time, Composite parent, int style) {
- DateTime timeSelector = new DateTime(parent, style | SWT.TIME);
+ public GUIModelField<
+ org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer>
+ addTime(String name, org.joda.time.DateTime time, Composite parent, int style) {
+ org.eclipse.swt.widgets.DateTime timeSelector =
+ new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME);
TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time);
- GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer> field =
- new GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer>(
- name, time, timeSelector, dataSynchronizer);
+ GUIModelField<
+ org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field =
+ new GUIModelField<
+ org.joda.time.DateTime,
+ org.eclipse.swt.widgets.DateTime,
+ TimeDataSynchronizer>(
+ name, time, timeSelector, dataSynchronizer);
addField(field);
return field;
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-07-12 21:25:00 UTC (rev 1085)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-07-13 15:13:45 UTC (rev 1086)
@@ -1,12 +1,12 @@
package org.cishell.utilities.swt.model.datasynchronizer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.DateTime;
public class DateDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
- private DateTime dateSelector;
+ private org.eclipse.swt.widgets.DateTime dateSelector;
- public DateDataSynchronizer(DateTime dateSelector, org.joda.time.DateTime date) {
+ public DateDataSynchronizer(
+ org.eclipse.swt.widgets.DateTime dateSelector, org.joda.time.DateTime date) {
this.dateSelector = dateSelector;
synchronizeToGUI(date);
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java 2010-07-12 21:25:00 UTC (rev 1085)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java 2010-07-13 15:13:45 UTC (rev 1086)
@@ -1,12 +1,12 @@
package org.cishell.utilities.swt.model.datasynchronizer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.DateTime;
public class TimeDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
- private DateTime timeSelector;
+ private org.eclipse.swt.widgets.DateTime timeSelector;
- public TimeDataSynchronizer(DateTime timeSelector, org.joda.time.DateTime time) {
+ public TimeDataSynchronizer(
+ org.eclipse.swt.widgets.DateTime timeSelector, org.joda.time.DateTime time) {
this.timeSelector = timeSelector;
synchronizeToGUI(time);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-12 21:25:06
|
Revision: 1085
http://cishell.svn.sourceforge.net/cishell/?rev=1085&view=rev
Author: pataphil
Date: 2010-07-12 21:25:00 +0000 (Mon, 12 Jul 2010)
Log Message:
-----------
* Minor, minor code cleanup.
Modified Paths:
--------------
trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/widgets/ChooseRelatedFilesWidget.java
Modified: trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/widgets/ChooseRelatedFilesWidget.java
===================================================================
--- trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/widgets/ChooseRelatedFilesWidget.java 2010-07-12 21:24:14 UTC (rev 1084)
+++ trunk/templates/org.cishell.templates.wizards/src/org/cishell/templates/wizards/widgets/ChooseRelatedFilesWidget.java 2010-07-12 21:25:00 UTC (rev 1085)
@@ -12,7 +12,7 @@
import org.eclipse.swt.widgets.Layout;
/*
- * This widget the user to choose and remove one or more files related to the
+ * This widget lets the user to choose and remove one or more files related to the
* executable file for the provided platform (name and path).
* As soon as the last file selector is filled with a file path, this widget
* provides an additional file selector for the user to continue providing
@@ -20,15 +20,15 @@
* All related file selectors besides the first one can be removed in this
* widget.
*/
+// TODO: Delete this and just use ExpandableScrolledComposite.
public class ChooseRelatedFilesWidget extends ResizeCompositeHackWidget {
- public static final String CHOOSE_RELATED_FILES_LABEL_TEXT =
- "Choose Related Files";
- public static final String CHOOSE_COMMON_FILES_LABEL_TEXT =
- "Choose Common Files";
+ public static final String CHOOSE_RELATED_FILES_LABEL_TEXT = "Choose Related Files";
+ public static final String CHOOSE_COMMON_FILES_LABEL_TEXT = "Choose Common Files";
private int parentWidth;
private ChooseFileWidget firstFileSelector;
- private ArrayList remainingFileSelectors = new ArrayList();
+ private ArrayList<ChooseFileWidget> remainingFileSelectors =
+ new ArrayList<ChooseFileWidget>();
private String platformName;
private String platformPath;
private PlatformOptionProvider platformOptionProvider;
@@ -58,7 +58,7 @@
return this.firstFileSelector;
}
- public ArrayList getRemainingFileSelectors() {
+ public ArrayList<ChooseFileWidget> getRemainingFileSelectors() {
return this.remainingFileSelectors;
}
@@ -68,10 +68,8 @@
if (remainingFileSelectorCount > 0) {
int lastFileSelectorIndex = remainingFileSelectorCount - 1;
- return (ChooseFileWidget)this.remainingFileSelectors.get(
- lastFileSelectorIndex);
- }
- else {
+ return this.remainingFileSelectors.get(lastFileSelectorIndex);
+ } else {
return this.firstFileSelector;
}
}
@@ -87,8 +85,7 @@
fileSelector.unsetFileChosenListener();
fileSelector.unsetRemoveElementListener();
this.remainingFileSelectors.remove(fileSelector);
- this.platformOptionProvider.removeRelatedFileOption(
- fileSelector.getPlatformOption());
+ this.platformOptionProvider.removeRelatedFileOption(fileSelector.getPlatformOption());
fileSelector.dispose();
setSize(computeSize(SWT.DEFAULT, SWT.DEFAULT));
@@ -109,8 +106,7 @@
if (filesAreRelated) {
labelText = CHOOSE_RELATED_FILES_LABEL_TEXT + ": ";
- }
- else {
+ } else {
labelText = CHOOSE_COMMON_FILES_LABEL_TEXT + ": ";
}
@@ -122,19 +118,16 @@
private ChooseFileWidget createAndSetupFileSelector(
boolean hasRemoveButton) {
ChooseFileWidget lastFileSelector = getLastFileSelector();
+
if (lastFileSelector != null) {
lastFileSelector.unsetFileChosenListener();
}
- PlatformOption relatedFileOption =
- this.platformOptionProvider.createRelatedFileOption(
- this.platformName, this.platformPath);
+ PlatformOption relatedFileOption = this.platformOptionProvider.createRelatedFileOption(
+ this.platformName, this.platformPath);
ChooseFileWidget fileSelector = new ChooseFileWidget(
- this, SWT.NONE,
- hasRemoveButton,
- this.parentWidth,
- relatedFileOption);
+ this, SWT.NONE, hasRemoveButton, this.parentWidth, relatedFileOption);
fileSelector.setFileChosenListener(this);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-12 21:24:20
|
Revision: 1084
http://cishell.svn.sourceforge.net/cishell/?rev=1084&view=rev
Author: pataphil
Date: 2010-07-12 21:24:14 +0000 (Mon, 12 Jul 2010)
Log Message:
-----------
* Continued developing on SWT Utilities.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -1,347 +1,352 @@
-package org.cishell.utilities;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
-public class StringUtilities {
- // TODO: Make this wrap implodeItems.
- public static String implodeStringArray(String[] stringArray, String separator) {
- final int stringArrayLength = stringArray.length;
- StringBuffer workingResultString = new StringBuffer();
-
- for (int ii = 0; ii < stringArrayLength; ii++) {
- workingResultString.append(stringArray[ii]);
- if (ii != stringArrayLength - 1) {
- workingResultString.append(separator);
- }
- }
-
- return workingResultString.toString();
- }
-
- /* TODO: This is a wrapper for implodeItems. All new/updated code should refer to implodeItems
- * from now on.
- */
- @SuppressWarnings("unchecked") // Raw List.
- public static String implodeList(List list, String separator) {
- return implodeItems(list, separator);
- }
-
- public static<T> String implodeItems(Collection<T> items, String separator) {
- StringBuffer workingResultString = new StringBuffer();
-
- for (Iterator<T> it = items.iterator(); it.hasNext(); ) {
-// for (int ii = 0; ii < listLength; ii++) {
-// workingResultString.append(list.get(ii));
- workingResultString.append(it.next());
-
-// boolean isLastElement = (ii == listLength - 1);
- boolean isLastElement = !it.hasNext();
- if (!isLastElement) {
- workingResultString.append(separator);
- }
- }
-
- return workingResultString.toString();
- }
-
- public static String[] filterStringsByPattern(String[] stringsToFilter, String pattern) {
- ArrayList<String> filteredStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < stringsToFilter.length; ii++) {
- if (!stringsToFilter[ii].matches(pattern)) {
- filteredStrings.add(stringsToFilter[ii]);
- }
- }
-
- return (String[])filteredStrings.toArray(new String[0]);
- }
-
- public static String[] filterEmptyStrings(String[] stringsToFilter) {
- // TODO: This maybe should use filterStringsByPattern?
- ArrayList<String> filteredStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < stringsToFilter.length; ii++) {
- if (!"".equals(stringsToFilter[ii])) {
- filteredStrings.add(stringsToFilter[ii]);
- }
- }
-
- return (String[])filteredStrings.toArray(new String[0]);
- }
-
- /*
- * This method is really meant to simplify working with Prefuse tables.
- * Prefuse table columns are typed. If a column contains a null cell,
- * Prefuse types that column as an array type, and it then represents
- * null values with arrays of length 0.
- * To handle this, this method returns:
- * null if the object is actually null or array of length 0;
- * just the first element of the array; or
- * the result of the object's toString method.
- */
- // TODO: Rename to interpretAsString.
- // TODO: Move these things to TableUtilities.
- // TODO: Handle all cases, including all primitive array types and
- // perhaps primitive box types (i.e. Integer).
- public static String interpretObjectAsString(Object object) {
- if (object == null) {
- return null;
- } else if (object instanceof String[]) {
- String[] objectAsStringArray = (String[]) object;
-
- if (objectAsStringArray.length == 0) {
- return null;
- } else {
- return objectAsStringArray[0];
- }
- } else {
- return object.toString();
- }
- }
-
- // TODO Think about instead using a Pattern, "\s*". Don't have to though.
- public static boolean isEmptyOrWhitespace(String string) {
- String trimmed = string.trim();
-
- return (trimmed.length() == 0);
- }
-
- public static boolean allAreEmptyOrWhitespace(String... strings) {
- for (String string : strings) {
- if (!isEmptyOrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean allAreNeitherEmptyNorWhitespace(String... strings) {
- for (String string : strings) {
- if (isEmptyOrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean isNull_Empty_OrWhitespace(String string) {
- if (string == null) {
- return true;
- }
-
- return isEmptyOrWhitespace(string);
- }
-
- public static boolean allAreNull_Empty_OrWhitespace(String... strings) {
- for (String string : strings) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean allAreNeitherNullNorEmptyNorWhitespace(String... strings) {
- for (String string : strings) {
- if (isNull_Empty_OrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static int countOccurrencesOfChar(CharSequence characters, char target) {
- int count = 0;
-
- for (int ii = 0; ii < characters.length(); ii++) {
- if (characters.charAt(ii) == target) {
- count++;
- }
- }
-
- return count;
- }
-
- public static String multiply(String target, int count) {
- if (count < 1) {
- return "";
- } else {
- StringBuffer stringInProgress = new StringBuffer();
-
- for (int ii = 0; ii < count; ii ++) {
- stringInProgress.append(target);
- }
-
- return stringInProgress.toString();
- }
- }
-
- public static String multiplyWithSeparator(String target, String separator, int count) {
- String multipliedWithExtraSeparator = multiply(target + separator, count);
-
- return multipliedWithExtraSeparator.substring(
- 0, multipliedWithExtraSeparator.length() - separator.length());
- }
-
- public static String emptyStringIfNull(Object object) {
- if (object == null) {
- return "";
- } else {
- return object.toString();
- }
- }
-
- public static String simpleClean(String string) {
- String guaranteedToNotBeNull = emptyStringIfNull(string);
-
- return guaranteedToNotBeNull.trim();
- }
-
- public static final String[] simpleCleanStrings(String[] strings) {
- List<String> cleanedStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < strings.length; ii ++) {
- cleanedStrings.add(StringUtilities.simpleClean(strings[ii]));
- }
-
- return (String[])cleanedStrings.toArray(new String[0]);
- }
-
- public static String trimIfNotNull(String string) {
- if (string == null) {
- return null;
- }
-
- return string.trim();
- }
-
- public static String toSentenceCase(String word) {
- String cleanedWord = simpleClean(word);
-
- if (cleanedWord.length() == 0) {
- return "";
- } else {
- return
- Character.toUpperCase(cleanedWord.charAt(0)) +
- cleanedWord.substring(1).toLowerCase();
- }
- }
-
- public static int prefixIndex(String target, String[] prefixes) {
- /*
- * Look for the prefixes in reverse order (so a longer one will win out over a shorter one
- * if they both have a beginning in common).
- */
- for (int ii = (prefixes.length - 1); ii >= 0; ii--) {
- if (target.startsWith(prefixes[ii])) {
- return ii;
- }
- }
-
- return -1;
- }
-
- /* TODO Perhaps make a "hasContent" method in here and apply that terminology throughout. */
- public static boolean areValidAndEqual(String string1, String string2) {
- return (
- !isNull_Empty_OrWhitespace(string1) &&
- !isNull_Empty_OrWhitespace(string2) &&
- (string1.equals(string2)));
- }
-
- public static boolean bothAreEqualOrNull(String string1, String string2) {
- if (string1 != null) {
- return string1.equals(string2);
- } else {
- return (string2 == null);
- }
- }
-
- public static boolean areValidAndEqualIgnoreCase(String string1, String string2) {
- return (
- !isNull_Empty_OrWhitespace(string1) &&
- !isNull_Empty_OrWhitespace(string2) &&
- string1.equalsIgnoreCase(string2));
- }
-
- // TODO: New Name.
- public static String simpleMerge(String string1, String string2) {
- if (!isNull_Empty_OrWhitespace(string1)) {
- if (!isNull_Empty_OrWhitespace(string2)) {
- if (string1.length() >= string2.length()) {
- return string1;
- } else {
- return string2;
- }
- } else {
- return string1;
- }
- }
- else if (!isNull_Empty_OrWhitespace(string2)) {
- return string2;
- }
-
- return string1;
- }
-
- //TODO: Make this not exist (a check for 'Null Empty or Whitespace' can stay. Use ! for negated cases)
- public static Object alternativeIfNotNull_Empty_OrWhitespace(
- String string, Object alternative) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return string;
- } else {
- return alternative;
- }
- }
-
- public static Object alternativeIfNotNull_Empty_OrWhitespace_IgnoreCase(
- String string, Object alternative) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return string.toLowerCase();
- } else {
- return alternative;
- }
- }
-
- public static String getNthToken(
- String originalString, String separator, int index, boolean trim) {
- return getAllTokens(originalString, separator, trim)[index];
- }
-
- public static String[] getAllTokens(
- String originalString, String separator, boolean trim) {
- String[] tokens = originalString.split(separator);
-
- if (trim) {
- String[] trimmedTokens = new String[tokens.length];
-
- for (int ii = 0; ii < tokens.length; ii++) {
- trimmedTokens[ii] = tokens[ii].trim();
- }
-
- return trimmedTokens;
- } else {
- return tokens;
- }
- }
-
- public static String[] tokenizeByWhitespace(String originalString) {
- StringTokenizer tokenizer = new StringTokenizer(originalString);
- int tokenCount = tokenizer.countTokens();
- String[] tokens = new String[tokenCount];
-
- for (int ii = 0; ii < tokenCount; ii++) {
- tokens[ii] = tokenizer.nextToken();
- }
-
- return tokens;
- }
-}
+package org.cishell.utilities;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class StringUtilities {
+ // TODO: Make this wrap implodeItems.
+ public static String implodeStringArray(String[] stringArray, String separator) {
+ final int stringArrayLength = stringArray.length;
+ StringBuffer workingResultString = new StringBuffer();
+
+ for (int ii = 0; ii < stringArrayLength; ii++) {
+ workingResultString.append(stringArray[ii]);
+ if (ii != stringArrayLength - 1) {
+ workingResultString.append(separator);
+ }
+ }
+
+ return workingResultString.toString();
+ }
+
+ /* TODO: This is a wrapper for implodeItems. All new/updated code should refer to implodeItems
+ * from now on.
+ */
+ @SuppressWarnings("unchecked") // Raw List.
+ public static String implodeList(List list, String separator) {
+ return implodeItems(list, separator);
+ }
+
+ public static<T> String implodeItems(Collection<T> items, String separator) {
+ StringBuffer workingResultString = new StringBuffer();
+
+ for (Iterator<T> it = items.iterator(); it.hasNext(); ) {
+// for (int ii = 0; ii < listLength; ii++) {
+// workingResultString.append(list.get(ii));
+ workingResultString.append(it.next());
+
+// boolean isLastElement = (ii == listLength - 1);
+ boolean isLastElement = !it.hasNext();
+ if (!isLastElement) {
+ workingResultString.append(separator);
+ }
+ }
+
+ return workingResultString.toString();
+ }
+
+ public static String[] filterStringsByPattern(String[] stringsToFilter, String pattern) {
+ ArrayList<String> filteredStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < stringsToFilter.length; ii++) {
+ if (!stringsToFilter[ii].matches(pattern)) {
+ filteredStrings.add(stringsToFilter[ii]);
+ }
+ }
+
+ return (String[])filteredStrings.toArray(new String[0]);
+ }
+
+ public static String[] filterEmptyStrings(String[] stringsToFilter) {
+ // TODO: This maybe should use filterStringsByPattern?
+ ArrayList<String> filteredStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < stringsToFilter.length; ii++) {
+ if (!"".equals(stringsToFilter[ii])) {
+ filteredStrings.add(stringsToFilter[ii]);
+ }
+ }
+
+ return (String[])filteredStrings.toArray(new String[0]);
+ }
+
+ /*
+ * This method is really meant to simplify working with Prefuse tables.
+ * Prefuse table columns are typed. If a column contains a null cell,
+ * Prefuse types that column as an array type, and it then represents
+ * null values with arrays of length 0.
+ * To handle this, this method returns:
+ * null if the object is actually null or array of length 0;
+ * just the first element of the array; or
+ * the result of the object's toString method.
+ */
+ // TODO: Rename to interpretAsString.
+ // TODO: Move these things to TableUtilities.
+ // TODO: Handle all cases, including all primitive array types and
+ // perhaps primitive box types (i.e. Integer).
+ public static String interpretObjectAsString(Object object) {
+ if (object == null) {
+ return null;
+ } else if (object instanceof String[]) {
+ String[] objectAsStringArray = (String[]) object;
+
+ if (objectAsStringArray.length == 0) {
+ return null;
+ } else {
+ return objectAsStringArray[0];
+ }
+ } else {
+ return object.toString();
+ }
+ }
+
+ // TODO Think about instead using a Pattern, "\s*". Don't have to though.
+ public static boolean isEmptyOrWhitespace(String string) {
+ String trimmed = string.trim();
+
+ return (trimmed.length() == 0);
+ }
+
+ public static boolean allAreEmptyOrWhitespace(String... strings) {
+ for (String string : strings) {
+ if (!isEmptyOrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean allAreNeitherEmptyNorWhitespace(String... strings) {
+ for (String string : strings) {
+ if (isEmptyOrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean isNull_Empty_OrWhitespace(String string) {
+ if (string == null) {
+ return true;
+ }
+
+ return isEmptyOrWhitespace(string);
+ }
+
+ public static boolean allAreNull_Empty_OrWhitespace(String... strings) {
+ for (String string : strings) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean allAreNeitherNullNorEmptyNorWhitespace(String... strings) {
+ for (String string : strings) {
+ if (isNull_Empty_OrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static int countOccurrencesOfChar(CharSequence characters, char target) {
+ int count = 0;
+
+ for (int ii = 0; ii < characters.length(); ii++) {
+ if (characters.charAt(ii) == target) {
+ count++;
+ }
+ }
+
+ return count;
+ }
+
+ public static String multiply(String target, int count) {
+ if (count < 1) {
+ return "";
+ } else {
+ StringBuffer stringInProgress = new StringBuffer();
+
+ for (int ii = 0; ii < count; ii ++) {
+ stringInProgress.append(target);
+ }
+
+ return stringInProgress.toString();
+ }
+ }
+
+ public static String multiplyWithSeparator(String target, String separator, int count) {
+ String multipliedWithExtraSeparator = multiply(target + separator, count);
+
+ return multipliedWithExtraSeparator.substring(
+ 0, multipliedWithExtraSeparator.length() - separator.length());
+ }
+
+ public static String emptyStringIfNull(Object object) {
+ if (object == null) {
+ return "";
+ } else {
+ return object.toString();
+ }
+ }
+
+ public static String simpleClean(String string) {
+ String guaranteedToNotBeNull = emptyStringIfNull(string);
+
+ return guaranteedToNotBeNull.trim();
+ }
+
+ public static final String[] simpleCleanStrings(String[] strings) {
+ List<String> cleanedStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < strings.length; ii ++) {
+ cleanedStrings.add(StringUtilities.simpleClean(strings[ii]));
+ }
+
+ return (String[])cleanedStrings.toArray(new String[0]);
+ }
+
+ public static String trimIfNotNull(String string) {
+ if (string == null) {
+ return null;
+ }
+
+ return string.trim();
+ }
+
+ public static String toSentenceCase(String word) {
+ String cleanedWord = simpleClean(word);
+
+ if (cleanedWord.length() == 0) {
+ return "";
+ } else {
+ return
+ Character.toUpperCase(cleanedWord.charAt(0)) +
+ cleanedWord.substring(1).toLowerCase();
+ }
+ }
+
+ public static int prefixIndex(String target, String[] prefixes) {
+ /*
+ * Look for the prefixes in reverse order (so a longer one will win out over a shorter one
+ * if they both have a beginning in common).
+ */
+ for (int ii = (prefixes.length - 1); ii >= 0; ii--) {
+ if (target.startsWith(prefixes[ii])) {
+ return ii;
+ }
+ }
+
+ return -1;
+ }
+
+ /* TODO Perhaps make a "hasContent" method in here and apply that terminology throughout. */
+ public static boolean areValidAndEqual(String string1, String string2) {
+ return (
+ !isNull_Empty_OrWhitespace(string1) &&
+ !isNull_Empty_OrWhitespace(string2) &&
+ (string1.equals(string2)));
+ }
+
+ public static boolean bothAreEqualOrNull(String string1, String string2) {
+ if (string1 != null) {
+ return string1.equals(string2);
+ } else {
+ return (string2 == null);
+ }
+ }
+
+ public static boolean areValidAndEqualIgnoreCase(String string1, String string2) {
+ return (
+ !isNull_Empty_OrWhitespace(string1) &&
+ !isNull_Empty_OrWhitespace(string2) &&
+ string1.equalsIgnoreCase(string2));
+ }
+
+ // TODO: New Name.
+ public static String simpleMerge(String string1, String string2) {
+ if (!isNull_Empty_OrWhitespace(string1)) {
+ if (!isNull_Empty_OrWhitespace(string2)) {
+ if (string1.length() >= string2.length()) {
+ return string1;
+ } else {
+ return string2;
+ }
+ } else {
+ return string1;
+ }
+ }
+ else if (!isNull_Empty_OrWhitespace(string2)) {
+ return string2;
+ }
+
+ return string1;
+ }
+
+ //TODO: Make this not exist (a check for 'Null Empty or Whitespace' can stay. Use ! for negated cases)
+ public static Object alternativeIfNotNull_Empty_OrWhitespace(
+ String string, Object alternative) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return string;
+ } else {
+ return alternative;
+ }
+ }
+
+ public static Object alternativeIfNotNull_Empty_OrWhitespace_IgnoreCase(
+ String string, Object alternative) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return string.toLowerCase();
+ } else {
+ return alternative;
+ }
+ }
+
+ public static String getNthToken(
+ String originalString, String separator, int index, boolean trim) {
+ return getAllTokens(originalString, separator, trim)[index];
+ }
+
+ public static String[] getAllTokens(
+ String originalString, String separator, boolean trim) {
+ String[] tokens = originalString.split(separator);
+
+ if (trim) {
+ String[] trimmedTokens = new String[tokens.length];
+
+ for (int ii = 0; ii < tokens.length; ii++) {
+ trimmedTokens[ii] = tokens[ii].trim();
+ }
+
+ return trimmedTokens;
+ } else {
+ return tokens;
+ }
+ }
+
+ public static String[] tokenizeByWhitespace(String originalString) {
+ StringTokenizer tokenizer = new StringTokenizer(originalString);
+ int tokenCount = tokenizer.countTokens();
+ String[] tokens = new String[tokenCount];
+
+ for (int ii = 0; ii < tokenCount; ii++) {
+ tokens[ii] = tokenizer.nextToken();
+ }
+
+ return tokens;
+ }
+
+ // TODO
+// public static String escape(String unescaped) {
+// return unescaped.replaceAll("\"", "\\\""
+// }
+}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,246 @@
+package org.cishell.utilities.swt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * This is meant to be subclassed.
+ */
+public class ExpandableComponentWidget<T> extends Composite {
+ public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1;
+ public static final int VERTICAL_SCROLL_INCREMENT = 50;
+
+ private ScrolledComponentFactory<T> componentFactory;
+ private Composite headerArea;
+ private ScrolledComposite scrollingArea;
+ private GridContainer scrolledAreaGrid;
+ private Composite footerArea;
+ private List<T> components = new ArrayList<T>();
+ private int uniqueComponentCount = 0;
+ private Collection<Label> columnLabels;
+
+ public ExpandableComponentWidget(
+ Composite parent, ScrolledComponentFactory<T> componentFactory) {
+ super(parent, SWT.NONE);
+ this.componentFactory = componentFactory;
+
+ setLayout(createLayout());
+ this.headerArea = createHeaderArea();
+ this.scrollingArea = createScrollingArea();
+ this.footerArea = createFooterArea();
+ this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea);
+
+ this.scrollingArea.setExpandHorizontal(true);
+ this.scrollingArea.setExpandVertical(true);
+ this.scrollingArea.setAlwaysShowScrollBars(true);
+ fixSize();
+ this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent());
+ this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT);
+ this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE);
+ }
+
+ public Composite getHeaderArea() {
+ return this.headerArea;
+ }
+
+ public Composite getFooterArea() {
+ return this.footerArea;
+ }
+
+ public List<T> getComponents() {
+ return Collections.unmodifiableList(this.components);
+ }
+
+ public int getColumnCount() {
+ return 1;
+ }
+
+ public T addComponent(int style, Map<String, Object> arguments) {
+ // TODO: Fix this terrible hack?
+ if (this.components.size() == 0) {
+ for (Label columnLabel : this.columnLabels) {
+ columnLabel.setVisible(true);
+ }
+ }
+
+ final int componentCount = this.components.size();
+ T component = this.componentFactory.constructWidget(
+ this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount);
+ this.uniqueComponentCount++;
+
+// Control componentControlHack = (Control) component;
+// componentControlHack.setLayoutData(createComponentLayoutData());
+ fixSize();
+
+ this.components.add(component);
+
+ return component;
+ }
+
+ public void removeComponent(int index) {
+// this.components.get(index).dispose();
+ this.scrolledAreaGrid.removeRow(index);
+ this.components.remove(index);
+ fixSize();
+
+ for (int ii = 0; ii < this.components.size(); ii++) {
+ this.componentFactory.reindexComponent(this.components.get(ii), ii);
+ }
+
+ // TODO: Fix this terrible hack?
+ if (this.components.size() == 0) {
+ for (Label columnLabel : this.columnLabels) {
+ columnLabel.setVisible(false);
+ }
+ }
+ }
+
+ public Collection<Label> createColumnLabels(Composite parent, int style) {
+ List<Label> columnLabels = new ArrayList<Label>();
+
+ for (String columnLabelText : createColumnLabelTexts()) {
+ Label columnLabel = new Label(parent, style);
+ columnLabel.setLayoutData(createColumnLabelLayoutData());
+ columnLabel.setText(columnLabelText);
+ columnLabels.add(columnLabel);
+ }
+
+ return columnLabels;
+ }
+
+ public Collection<String> createColumnLabelTexts() {
+ List<String> columnLabelTexts = new ArrayList<String>();
+
+ for (int ii = 0; ii < getColumnCount(); ii++) {
+ columnLabelTexts.add("Column " + ii);
+ }
+
+ return columnLabelTexts;
+ }
+
+ private void fixSize() {
+ Composite scrolledArea = this.scrolledAreaGrid.getActualParent();
+ this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ scrolledArea.pack();
+ }
+
+ protected Composite createHeaderArea() {
+ Composite headerArea = new Composite(this, SWT.NONE);
+ headerArea.setLayoutData(createHeaderAreaLayoutData());
+ headerArea.setLayout(createHeaderLayout());
+
+ return headerArea;
+ }
+
+ protected GridData createHeaderAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ protected GridLayout createHeaderLayout() {
+ GridLayout layout = new GridLayout(1, false);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected ScrolledComposite createScrollingArea() {
+ ScrolledComposite scrollingArea =
+ new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
+ scrollingArea.setLayoutData(createScrollingAreaLayoutData());
+ scrollingArea.setLayout(createScrollingLayout());
+
+ return scrollingArea;
+ }
+
+ protected GridData createScrollingAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ return layoutData;
+ }
+
+ private GridLayout createScrollingLayout() {
+ GridLayout layout = new GridLayout(1, true);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected Composite createFooterArea() {
+ Composite footerArea = new Composite(this, SWT.BORDER);
+ footerArea.setLayoutData(createFooterAreaLayoutData());
+ footerArea.setLayout(createFooterLayout());
+
+ return footerArea;
+ }
+
+ protected GridData createFooterAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ protected GridLayout createFooterLayout() {
+ GridLayout layout = new GridLayout(1, false);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ private GridContainer createScrolledAreaGrid(Composite parent) {
+ Composite columnArea = new Composite(parent, SWT.NONE);
+ columnArea.setLayoutData(createScrolledAreaLayoutData());
+ final int columnCount = getColumnCount();
+ columnArea.setLayout(createScrolledAreaLayout(columnCount));
+
+ return new GridContainer(columnArea, columnCount);
+ }
+
+ protected GridData createScrolledAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ return layoutData;
+ }
+
+ protected GridLayout createScrolledAreaLayout(int columnCount) {
+ GridLayout layout = new GridLayout(columnCount, false);
+// GUIBuilderUtilities.clearMargins(layout);
+// GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected GridData createColumnLabelLayoutData() {
+ GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+
+ return layoutData;
+ }
+
+ protected GridData createComponentLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ private static GridLayout createLayout() {
+ GridLayout layout = new GridLayout(1, true);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,78 @@
+package org.cishell.utilities.swt;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class GUIBuilderUtilities {
+ public static Display createDisplay() {
+ return new Display();
+ }
+
+ public static Shell createShell(
+ Display display,
+ String windowTitle,
+ int windowWidth,
+ int windowHeight,
+ int columnCount,
+ boolean clearSpacing) {
+ Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE);
+ shell.setText(windowTitle);
+ shell.setSize(windowWidth, windowHeight);
+ shell.setLayout(createShellLayout(columnCount, clearSpacing));
+
+ return shell;
+ }
+
+ public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) {
+ GridLayout layout = new GridLayout(columnCount, true);
+
+ if (clearSpacing) {
+ clearSpacing(layout);
+ }
+
+ return layout;
+ }
+
+ public static void openShell(
+ Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) {
+// if (useWindowHeightToSizeShell) {
+// /* (So far, we've created the shell at the maximum possible size we'll allow
+// * (according to windowHeight). This line shrinks the shell to be a more fitting size
+// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum
+// * size we set.)
+// */
+// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y));
+// }
+
+ shell.pack();
+ shell.open();
+
+ if (useWindowHeightToSizeShell) {
+ Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y));
+ }
+ }
+
+ public static void swtLoop(Display display, Shell shell) {
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+
+ public static void clearMargins(GridLayout layout) {
+ layout.marginTop = layout.marginBottom = layout.marginHeight = 0;
+ layout.marginLeft = layout.marginRight = layout.marginWidth = 0;
+ }
+
+ public static void clearSpacing(GridLayout layout) {
+ layout.horizontalSpacing = layout.verticalSpacing = 0;
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,92 @@
+package org.cishell.utilities.swt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Widget;
+
+public class GridContainer {
+ private Composite actualParent;
+ private int columnCount;
+ private List<GridRow> rows = new ArrayList<GridRow>();
+
+ public GridContainer(Composite actualParent, int columnCount) {
+ this.actualParent = actualParent;
+ this.columnCount = columnCount;
+ }
+
+ public Composite getActualParent() {
+ return this.actualParent;
+ }
+
+ public int getColumnCount() {
+ return this.columnCount;
+ }
+
+ public int getRowCount() {
+ return this.rows.size();
+ }
+
+ public GridRow addComponent(Widget component) {
+ GridRow lastRow = getOrCreateLastUsableRow();
+ lastRow.addComponent(component);
+
+ return lastRow;
+ }
+
+ public void removeRow(int rowIndex) {
+ this.rows.get(rowIndex).dispose();
+ this.rows.remove(rowIndex);
+ }
+
+ private GridRow getOrCreateLastUsableRow() {
+ final int rowCount = getRowCount();
+
+ if (rowCount == 0) {
+ return addNewRow();
+ } else {
+ GridRow lastRow = this.rows.get(rowCount - 1);
+
+ if (lastRow.componentCount < getColumnCount()) {
+ return lastRow;
+ } else {
+ return addNewRow();
+ }
+ }
+ }
+
+ private GridRow addNewRow() {
+ GridRow row = new GridRow(getRowCount());
+ this.rows.add(row);
+
+ return row;
+ }
+
+ public class GridRow {
+ private int rowIndex;
+ private int componentCount = 0;
+ private Collection<Widget> components =
+ new ArrayList<Widget>(GridContainer.this.columnCount);
+
+ private GridRow(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ public int getRowIndex() {
+ return this.rowIndex;
+ }
+
+ private void addComponent(Widget component) {
+ this.components.add(component);
+ this.componentCount++;
+ }
+
+ private void dispose() {
+ for (Widget component : this.components) {
+ component.dispose();
+ }
+ }
+ }
+}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,15 @@
+package org.cishell.utilities.swt;
+
+import java.util.Map;
+
+public interface ScrolledComponentFactory<T> {
+ public T constructWidget(
+ ExpandableComponentWidget<T> componentWidget,
+ GridContainer scrolledAreaGrid,
+ int style,
+ Map<String, Object> arguments,
+ int index,
+ int uniqueIndex);
+
+ public void reindexComponent(T component, int newIndex);
+}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -63,6 +64,7 @@
Composite parent,
int style) {
java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
+ Collections.sort(orderedOptionLabels);
Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -28,6 +28,7 @@
if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
GUIModelField.this.value =
GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
+ System.err.println(GUIModelField.this.value);
}
}
});
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-09 20:55:25
|
Revision: 1083
http://cishell.svn.sourceforge.net/cishell/?rev=1083&view=rev
Author: pataphil
Date: 2010-07-09 20:55:18 +0000 (Fri, 09 Jul 2010)
Log Message:
-----------
* Added additional ModelDataSynchronizer types + field-adding-support to GUIModel/SWT utilities.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-08 17:37:42 UTC (rev 1082)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-09 20:55:18 UTC (rev 1083)
@@ -3,23 +3,28 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.DateDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.TextDataSynchronizer;
import org.cishell.utilities.swt.model.datasynchronizer.TimeDataSynchronizer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
public class GUIModel {
- private Map<String, GUIModelField<?>> inputFieldsByName =
- new HashMap<String, GUIModelField<?>>();
+ private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>
+ inputFieldsByName = new HashMap<
+ String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>();
public GUIModel() {
}
@@ -28,75 +33,130 @@
return this.inputFieldsByName.keySet();
}
- public Collection<GUIModelField<?>> getFields() {
+ public Collection<
+ GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() {
return this.inputFieldsByName.values();
}
- public GUIModelField<?> getField(String name) {
+ public GUIModelField<
+ ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) {
return this.inputFieldsByName.get(name);
}
- public Button addCheckBox(String name, boolean on, Composite parent, int style) {
+ public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox(
+ String name, boolean on, Composite parent, int style) {
Button checkBox = new Button(parent, style | SWT.CHECK);
- ModelDataSynchronizer<Boolean> dataSynchronizer =
- new CheckBoxDataSynchronizer(checkBox, on);
- GUIModelField<Boolean> field =
- new GUIModelField<Boolean>(name, on, checkBox, dataSynchronizer);
+ CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on);
+ GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field =
+ new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>(
+ name, on, checkBox, dataSynchronizer);
addField(field);
- return checkBox;
+ return field;
}
- public Combo addDropDown(
+ public GUIModelField<String, Combo, DropDownDataSynchronizer> addSingleSelectionDropDown(
String name,
int selectedIndex,
Collection<String> unorderedOptionLabels,
Map<String, String> optionValuesByLabels,
Composite parent,
int style) {
- List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
+ java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
- ModelDataSynchronizer<String> dataSynchronizer = new DropDownDataSynchronizer(
+ DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
- GUIModelField<String> field = new GUIModelField<String>(
- name, orderedOptionLabels.get(selectedIndex), dropDown, dataSynchronizer);
+ GUIModelField<String, Combo, DropDownDataSynchronizer> field =
+ new GUIModelField<String, Combo, DropDownDataSynchronizer>(
+ name, orderedOptionLabels.get(selectedIndex), dropDown, dataSynchronizer);
addField(field);
- return dropDown;
+ return field;
}
+ // TODO: addMultiSelectionDropDown
+
// TODO: Test this out.
- public DateTime addDate(
+ public GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer> addDate(
String name, org.joda.time.DateTime date, Composite parent, int style) {
DateTime dateSelector = new DateTime(parent, style | SWT.DATE);
- ModelDataSynchronizer<org.joda.time.DateTime> dataSynchronizer =
- new DateDataSynchronizer(dateSelector, date);
- GUIModelField<org.joda.time.DateTime> field = new GUIModelField<org.joda.time.DateTime>(
- name, date, dateSelector, dataSynchronizer);
+ DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date);
+ GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer> field =
+ new GUIModelField<org.joda.time.DateTime, DateTime, DateDataSynchronizer>(
+ name, date, dateSelector, dataSynchronizer);
addField(field);
- return dateSelector;
+ return field;
}
// TODO: Test this out.
- public DateTime addTime(
+ public GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer> addTime(
String name, org.joda.time.DateTime time, Composite parent, int style) {
DateTime timeSelector = new DateTime(parent, style | SWT.TIME);
- ModelDataSynchronizer<org.joda.time.DateTime> dataSynchronizer =
- new TimeDataSynchronizer(timeSelector, time);
- GUIModelField<org.joda.time.DateTime> field = new GUIModelField<org.joda.time.DateTime>(
- name, time, timeSelector, dataSynchronizer);
+ TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time);
+ GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer> field =
+ new GUIModelField<org.joda.time.DateTime, DateTime, TimeDataSynchronizer>(
+ name, time, timeSelector, dataSynchronizer);
addField(field);
- return timeSelector;
+ return field;
}
// TODO: addCalendar
-// public List addSingleSelectionList(
-// String name,
+ // TODO: Test this out.
+ public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addSingleSelectionList(
+ String name,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, String> optionValuesByLabels,
+ Composite parent,
+ int style) {
+ java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
+ List list = new List(parent, style | SWT.SINGLE);
+ SingleListSelectionDataSynchronizer dataSynchronizer =
+ new SingleListSelectionDataSynchronizer(
+ list, selectedIndex, orderedOptionLabels, optionValuesByLabels);
+ GUIModelField<String, List, SingleListSelectionDataSynchronizer> field =
+ new GUIModelField<String, List, SingleListSelectionDataSynchronizer>(
+ name, list.getItem(selectedIndex), list, dataSynchronizer);
+ addField(field);
- public<T> void addField(GUIModelField<T> field) {
+ return field;
+ }
+
+ // TODO: addMultiSelectionList
+ // TODO: addProgressBar
+ // TODO: addSash?
+ // TODO: addSlider
+ // TODO: addScale
+ // TODO: addSpinner
+ // TODO: addStyledText
+
+ public GUIModelField<String, Text, TextDataSynchronizer> addUnstyledText(
+ String name,
+ String value,
+ boolean isMultiLined,
+ Composite parent,
+ int style) {
+ if (isMultiLined) {
+ style = style | SWT.MULTI;
+ } else {
+ style = style | SWT.SINGLE;
+ }
+
+ Text text = new Text(parent, style);
+ TextDataSynchronizer dataSynchronizer = new TextDataSynchronizer(text, value);
+ GUIModelField<String, Text, TextDataSynchronizer> field =
+ new GUIModelField<String, Text, TextDataSynchronizer>(
+ name, value, text, dataSynchronizer);
+ addField(field);
+
+ return field;
+ }
+
+ public<T> void addField(
+ GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) {
String fieldName = field.getName();
if (this.inputFieldsByName.containsKey(fieldName)) {
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-08 17:37:42 UTC (rev 1082)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-09 20:55:18 UTC (rev 1083)
@@ -5,18 +5,18 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Widget;
-public class GUIModelField<T> {
+public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> {
private String name;
private T defaultValue;
private T value;
- private Widget widget;
- private ModelDataSynchronizer<T> dataSynchronizer;
+ private U widget;
+ private V dataSynchronizer;
public GUIModelField(
String name,
T defaultValue,
- Widget widget,
- ModelDataSynchronizer<T> dataSynchronizer) {
+ U widget,
+ V dataSynchronizer) {
this.name = name;
this.defaultValue = defaultValue;
this.value = this.defaultValue;
@@ -41,6 +41,14 @@
return this.value;
}
+ public U getWidget() {
+ return this.widget;
+ }
+
+ public V getDataSynchronizer() {
+ return this.dataSynchronizer;
+ }
+
public void setValue(T value) {
this.value = this.dataSynchronizer.synchronizeToGUI(value);
}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java 2010-07-09 20:55:18 UTC (rev 1083)
@@ -0,0 +1,53 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import java.util.Map;
+
+import org.cishell.utilities.MapUtilities;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.List;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+
+// TODO: Make this so options can change on it.
+public class SingleListSelectionDataSynchronizer implements ModelDataSynchronizer<String> {
+ private List singleSelectionList;
+ private BiMap<Integer, String> optionLabels;
+ private Map<String, String> optionValuesByLabels;
+
+ public SingleListSelectionDataSynchronizer(
+ List singleSelectionList,
+ int selectedIndex,
+ java.util.List<String> optionLabels,
+ Map<String, String> optionValuesByLabels) {
+ this.singleSelectionList = singleSelectionList;
+ this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
+ this.optionValuesByLabels = optionValuesByLabels;
+
+ this.singleSelectionList.setItems(optionLabels.toArray(new String[0]));
+ this.singleSelectionList.select(selectedIndex);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public String value() {
+ return this.optionValuesByLabels.get(
+ this.optionLabels.get(this.singleSelectionList.getSelectionIndex()));
+ }
+
+ public String synchronizeFromGUI() {
+ return this.optionLabels.get(this.singleSelectionList.getSelectionIndex());
+ }
+
+ public String synchronizeToGUI(String value) {
+ this.singleSelectionList.select(this.optionLabels.inverse().get(value));
+
+ return value();
+ }
+
+ public String reset(String defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java 2010-07-09 20:55:18 UTC (rev 1083)
@@ -0,0 +1,36 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Text;
+
+public class TextDataSynchronizer implements ModelDataSynchronizer<String> {
+ private Text text;
+
+ public TextDataSynchronizer(Text text, String value) {
+ this.text = text;
+
+ this.text.setText(value);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public String value() {
+ return this.text.getText();
+ }
+
+ public String synchronizeFromGUI() {
+ return value();
+ }
+
+ public String synchronizeToGUI(String value) {
+ this.text.setText(value);
+
+ return value();
+ }
+
+ public String reset(String defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-08 17:37:48
|
Revision: 1082
http://cishell.svn.sourceforge.net/cishell/?rev=1082&view=rev
Author: pataphil
Date: 2010-07-08 17:37:42 +0000 (Thu, 08 Jul 2010)
Log Message:
-----------
* Committing (partially done) GUIModel framework and additional MapUtilities.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-07-06 20:19:54 UTC (rev 1081)
+++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-07-08 17:37:42 UTC (rev 1082)
@@ -36,6 +36,8 @@
org.cishell.utilities.mutateParameter.defaultvalue,
org.cishell.utilities.mutateParameter.dropdown,
org.cishell.utilities.osgi.logging,
- org.cishell.utilities.swt
+ org.cishell.utilities.swt,
+ org.cishell.utilities.swt.model,
+ org.cishell.utilities.swt.model.datasynchronizer
Require-Bundle: org.eclipse.ui;resolution:=optional,
org.eclipse.core.runtime;resolution:=optional
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-06 20:19:54 UTC (rev 1081)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -2,6 +2,8 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class MapUtilities {
@@ -20,4 +22,44 @@
return workingKeys;
}
+
+ public static<T> Map<T, T> mirror(Collection<T> items) {
+ Map<T, T> mirroredItems = new HashMap<T, T>();
+
+ for (T item : items) {
+ mirroredItems.put(item, item);
+ }
+
+ return mirroredItems;
+ }
+
+ public static<K, V> List<K> keysWithOrder(Map<K, V> map) {
+ List<K> keys = new ArrayList<K>();
+
+ for (K key : map.keySet()) {
+ keys.add(key);
+ }
+
+ return keys;
+ }
+
+ public static<K, V> Collection<V> valuesWithPreservedOrder(Map<K, V> map, Collection<K> keys) {
+ List<V> values = new ArrayList<V>();
+
+ for (K key : keys) {
+ values.add(map.get(key));
+ }
+
+ return values;
+ }
+
+ public static<V> Map<Integer, V> mapIndexToValues(List<V> values) {
+ Map<Integer, V> valuesByIndex = new HashMap<Integer, V>();
+
+ for (int ii = 0; ii < values.size(); ii++) {
+ valuesByIndex.put(ii, values.get(ii));
+ }
+
+ return valuesByIndex;
+ }
}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,110 @@
+package org.cishell.utilities.swt.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.DateDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer;
+import org.cishell.utilities.swt.model.datasynchronizer.TimeDataSynchronizer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DateTime;
+
+public class GUIModel {
+ private Map<String, GUIModelField<?>> inputFieldsByName =
+ new HashMap<String, GUIModelField<?>>();
+
+ public GUIModel() {
+ }
+
+ public Collection<String> getFieldNames() {
+ return this.inputFieldsByName.keySet();
+ }
+
+ public Collection<GUIModelField<?>> getFields() {
+ return this.inputFieldsByName.values();
+ }
+
+ public GUIModelField<?> getField(String name) {
+ return this.inputFieldsByName.get(name);
+ }
+
+ public Button addCheckBox(String name, boolean on, Composite parent, int style) {
+ Button checkBox = new Button(parent, style | SWT.CHECK);
+ ModelDataSynchronizer<Boolean> dataSynchronizer =
+ new CheckBoxDataSynchronizer(checkBox, on);
+ GUIModelField<Boolean> field =
+ new GUIModelField<Boolean>(name, on, checkBox, dataSynchronizer);
+ addField(field);
+
+ return checkBox;
+ }
+
+ public Combo addDropDown(
+ String name,
+ int selectedIndex,
+ Collection<String> unorderedOptionLabels,
+ Map<String, String> optionValuesByLabels,
+ Composite parent,
+ int style) {
+ List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
+ Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
+ ModelDataSynchronizer<String> dataSynchronizer = new DropDownDataSynchronizer(
+ dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
+ GUIModelField<String> field = new GUIModelField<String>(
+ name, orderedOptionLabels.get(selectedIndex), dropDown, dataSynchronizer);
+ addField(field);
+
+ return dropDown;
+ }
+
+ // TODO: Test this out.
+ public DateTime addDate(
+ String name, org.joda.time.DateTime date, Composite parent, int style) {
+ DateTime dateSelector = new DateTime(parent, style | SWT.DATE);
+ ModelDataSynchronizer<org.joda.time.DateTime> dataSynchronizer =
+ new DateDataSynchronizer(dateSelector, date);
+ GUIModelField<org.joda.time.DateTime> field = new GUIModelField<org.joda.time.DateTime>(
+ name, date, dateSelector, dataSynchronizer);
+ addField(field);
+
+ return dateSelector;
+ }
+
+ // TODO: Test this out.
+ public DateTime addTime(
+ String name, org.joda.time.DateTime time, Composite parent, int style) {
+ DateTime timeSelector = new DateTime(parent, style | SWT.TIME);
+ ModelDataSynchronizer<org.joda.time.DateTime> dataSynchronizer =
+ new TimeDataSynchronizer(timeSelector, time);
+ GUIModelField<org.joda.time.DateTime> field = new GUIModelField<org.joda.time.DateTime>(
+ name, time, timeSelector, dataSynchronizer);
+ addField(field);
+
+ return timeSelector;
+ }
+
+ // TODO: addCalendar
+
+// public List addSingleSelectionList(
+// String name,
+
+ public<T> void addField(GUIModelField<T> field) {
+ String fieldName = field.getName();
+
+ if (this.inputFieldsByName.containsKey(fieldName)) {
+ String exceptionMessage =
+ "A field with the name \"" + fieldName + "\" already exists. Unable to continue.";
+ throw new ModelFieldException(exceptionMessage);
+ }
+
+ this.inputFieldsByName.put(fieldName, field);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,51 @@
+package org.cishell.utilities.swt.model;
+
+import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Widget;
+
+public class GUIModelField<T> {
+ private String name;
+ private T defaultValue;
+ private T value;
+ private Widget widget;
+ private ModelDataSynchronizer<T> dataSynchronizer;
+
+ public GUIModelField(
+ String name,
+ T defaultValue,
+ Widget widget,
+ ModelDataSynchronizer<T> dataSynchronizer) {
+ this.name = name;
+ this.defaultValue = defaultValue;
+ this.value = this.defaultValue;
+ this.widget = widget;
+ this.dataSynchronizer = dataSynchronizer;
+
+ this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
+ GUIModelField.this.value =
+ GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
+ }
+ }
+ });
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public T getValue() {
+ return this.value;
+ }
+
+ public void setValue(T value) {
+ this.value = this.dataSynchronizer.synchronizeToGUI(value);
+ }
+
+ public void reset() {
+ this.value = this.dataSynchronizer.reset(this.defaultValue);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,21 @@
+package org.cishell.utilities.swt.model;
+
+public class ModelFieldException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public ModelFieldException() {
+ super();
+ }
+
+ public ModelFieldException(String arg0) {
+ super(arg0);
+ }
+
+ public ModelFieldException(Throwable arg0) {
+ super(arg0);
+ }
+
+ public ModelFieldException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,35 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+
+public class CheckBoxDataSynchronizer implements ModelDataSynchronizer<Boolean> {
+ private Button checkBox;
+
+ public CheckBoxDataSynchronizer(Button checkBox, boolean on) {
+ this.checkBox = checkBox;
+ this.checkBox.setSelection(on);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public Boolean value() {
+ return this.checkBox.getSelection();
+ }
+
+ public Boolean synchronizeFromGUI() {
+ return value();
+ }
+
+ public Boolean synchronizeToGUI(Boolean value) {
+ this.checkBox.setSelection(value);
+
+ return value;
+ }
+
+ public Boolean reset(Boolean defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,42 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.DateTime;
+
+public class DateDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
+ private DateTime dateSelector;
+
+ public DateDataSynchronizer(DateTime dateSelector, org.joda.time.DateTime date) {
+ this.dateSelector = dateSelector;
+ synchronizeToGUI(date);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public org.joda.time.DateTime value() {
+ return new org.joda.time.DateTime(
+ this.dateSelector.getYear(),
+ this.dateSelector.getMonth(),
+ this.dateSelector.getDay(),
+ 0,
+ 0,
+ 0,
+ 0);
+ }
+
+ public org.joda.time.DateTime synchronizeFromGUI() {
+ return value();
+ }
+
+ public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime date) {
+ this.dateSelector.setDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
+
+ return value();
+ }
+
+ public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,54 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.cishell.utilities.MapUtilities;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Combo;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+
+// TODO: Make this so options can change on it.
+public class DropDownDataSynchronizer implements ModelDataSynchronizer<String> {
+ private Combo dropDown;
+ private BiMap<Integer, String> optionLabels;
+ private Map<String, String> optionValuesByLabels;
+
+ public DropDownDataSynchronizer(
+ Combo dropDown,
+ int selectedIndex,
+ List<String> optionLabels,
+ Map<String, String> optionValuesByLabels) {
+ this.dropDown = dropDown;
+ this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels));
+ this.optionValuesByLabels = optionValuesByLabels;
+
+ this.dropDown.setItems(optionLabels.toArray(new String[0]));
+ this.dropDown.select(selectedIndex);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public String value() {
+ return this.optionValuesByLabels.get(
+ this.optionLabels.get(this.dropDown.getSelectionIndex()));
+ }
+
+ public String synchronizeFromGUI() {
+ return this.optionLabels.get(this.dropDown.getSelectionIndex());
+ }
+
+ public String synchronizeToGUI(String value) {
+ this.dropDown.select(this.optionLabels.inverse().get(value));
+
+ return value();
+ }
+
+ public String reset(String defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,9 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+public interface ModelDataSynchronizer<T> {
+ public int swtUpdateListenerCode();
+ public T value();
+ public T synchronizeFromGUI();
+ public T synchronizeToGUI(T value);
+ public T reset(T defaultValue);
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java 2010-07-08 17:37:42 UTC (rev 1082)
@@ -0,0 +1,43 @@
+package org.cishell.utilities.swt.model.datasynchronizer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.DateTime;
+
+public class TimeDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> {
+ private DateTime timeSelector;
+
+ public TimeDataSynchronizer(DateTime timeSelector, org.joda.time.DateTime time) {
+ this.timeSelector = timeSelector;
+ synchronizeToGUI(time);
+ }
+
+ public int swtUpdateListenerCode() {
+ return SWT.Selection;
+ }
+
+ public org.joda.time.DateTime value() {
+ return new org.joda.time.DateTime(
+ 0,
+ 0,
+ 0,
+ this.timeSelector.getHours(),
+ this.timeSelector.getMinutes(),
+ this.timeSelector.getSeconds(),
+ 0);
+ }
+
+ public org.joda.time.DateTime synchronizeFromGUI() {
+ return value();
+ }
+
+ public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime time) {
+ this.timeSelector.setTime(
+ time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute());
+
+ return value();
+ }
+
+ public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) {
+ return synchronizeToGUI(defaultValue);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-06 20:20:01
|
Revision: 1081
http://cishell.svn.sourceforge.net/cishell/?rev=1081&view=rev
Author: pataphil
Date: 2010-07-06 20:19:54 +0000 (Tue, 06 Jul 2010)
Log Message:
-----------
* Partially made Java 1.5.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-07-06 20:08:57 UTC (rev 1080)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-07-06 20:19:54 UTC (rev 1081)
@@ -74,9 +74,11 @@
Map<String, String> attributes,
Collection<String> types,
Collection<String> keysToSkip,
- String[] keysToAdd) {
+ Collection<String> keysToAddToFront) {
Collection<String> validNumberKeysInMap =
MapUtilities.getValidKeysOfTypesInMap(attributes, types, keysToSkip);
+ validNumberKeysInMap =
+ ArrayListUtilities.unionCollections(keysToAddToFront, validNumberKeysInMap, null);
AttributeDefinition numberAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validNumberKeysInMap, validNumberKeysInMap);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-06 20:09:03
|
Revision: 1080
http://cishell.svn.sourceforge.net/cishell/?rev=1080&view=rev
Author: pataphil
Date: 2010-07-06 20:08:57 +0000 (Tue, 06 Jul 2010)
Log Message:
-----------
* Partially made Java 1.5.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -1,40 +1,34 @@
package org.cishell.utilities;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
public class ArrayListUtilities {
- public static ArrayList unionArrayLists(ArrayList arrayList1,
- ArrayList arrayList2,
- String[] keysToSkip,
- String[] keysToAdd) {
- ArrayList union = new ArrayList();
-
- for (int ii = 0; ii < arrayList1.size(); ii++) {
- Object element = arrayList1.get(ii);
-
- if (!union.contains(element) &&
- Arrays.binarySearch(keysToSkip, element) < 0) {
+ // TODO: Move this to CollectionUtilities.
+ public static<T> Collection<T> unionCollections(
+ Collection<T> items1,
+ Collection<T> items2,
+ Collection<T> keysToSkip) {
+ Collection<T> union = new HashSet<T>();
+
+ if (keysToSkip == null) {
+ keysToSkip = new HashSet<T>();
+ }
+
+ for (T element : items1) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
union.add(element);
}
}
-
- for (int ii = 0; ii < arrayList2.size(); ii++) {
- Object element = arrayList2.get(ii);
-
- if (!union.contains(element)) {
+
+ for (T element : items2) {
+ if (!union.contains(element) && !keysToSkip.contains(element)) {
union.add(element);
}
}
- for (int ii = 0; ii < keysToAdd.length; ii++) {
- String keyToAdd = keysToAdd[ii];
- if (!union.contains(keyToAdd)) {
- union.add(keyToAdd);
- }
- }
-
return union;
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -1,24 +1,23 @@
package org.cishell.utilities;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Map;
-import java.util.Set;
public class MapUtilities {
- public static String[] getValidKeysOfTypesInMap(
- Map map, String[] types, String[] keysToSkip, String[] keysToAdd)
+ public static<K, V> Collection<K> getValidKeysOfTypesInMap(
+ Map<K, V> map, Collection<V> types, Collection<K> keysToSkip)
throws ColumnNotFoundException {
- ArrayList workingKeys = new ArrayList();
- Set entrySet = map.entrySet();
-
- for (int ii = 0; ii < types.length; ii++) {
- String type = types[ii];
- ArrayList keysForType =
+ Collection<K> workingKeys = new ArrayList<K>();
+ Collection<Map.Entry<K, V>> entrySet = map.entrySet();
+
+ for (V type : types) {
+ Collection<K> keysForType =
SetUtilities.getKeysOfMapEntrySetWithValue(entrySet, type);
- workingKeys = ArrayListUtilities.unionArrayLists(
- workingKeys, keysForType, keysToSkip, keysToAdd);
+ workingKeys =
+ ArrayListUtilities.unionCollections(workingKeys, keysForType, keysToSkip);
}
- return (String[])workingKeys.toArray(new String[0]);
+ return workingKeys;
}
}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
@@ -23,8 +24,8 @@
public static AttributeDefinition formLabelAttributeDefinition(
AttributeDefinition oldAttributeDefinition, Table table)
throws ColumnNotFoundException {
- String[] validStringColumnsInTable =
- TableUtilities.getValidStringColumnNamesInTable(table);
+ Collection<String> validStringColumnsInTable =
+ Arrays.asList(TableUtilities.getValidStringColumnNamesInTable(table));
AttributeDefinition labelAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validStringColumnsInTable, validStringColumnsInTable);
@@ -35,7 +36,8 @@
public static AttributeDefinition formDateAttributeDefinition(
AttributeDefinition oldAttributeDefinition, Table table)
throws ColumnNotFoundException {
- String[] validDateColumnsInTable = TableUtilities.getValidDateColumnNamesInTable(table);
+ Collection<String> validDateColumnsInTable =
+ Arrays.asList(TableUtilities.getValidDateColumnNamesInTable(table));
AttributeDefinition dateAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validDateColumnsInTable, validDateColumnsInTable);
@@ -46,8 +48,8 @@
public static AttributeDefinition formIntegerAttributeDefinition(
AttributeDefinition oldAttributeDefinition, Table table)
throws ColumnNotFoundException {
- String[] validIntegerColumnsInTable =
- TableUtilities.getValidIntegerColumnNamesInTable(table);
+ Collection<String> validIntegerColumnsInTable =
+ Arrays.asList(TableUtilities.getValidIntegerColumnNamesInTable(table));
AttributeDefinition integerAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validIntegerColumnsInTable, validIntegerColumnsInTable);
@@ -58,8 +60,8 @@
public static AttributeDefinition formNumberAttributeDefinition(
AttributeDefinition oldAttributeDefinition, Table table)
throws ColumnNotFoundException {
- String[] validNumberColumnsInTable =
- TableUtilities.getValidNumberColumnNamesInTable(table);
+ Collection<String> validNumberColumnsInTable =
+ Arrays.asList(TableUtilities.getValidNumberColumnNamesInTable(table));
AttributeDefinition numberAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validNumberColumnsInTable, validNumberColumnsInTable);
@@ -69,12 +71,12 @@
public static AttributeDefinition formAttributeDefinitionFromMap(
AttributeDefinition oldAttributeDefinition,
- Map<String, String> map,
- String[] types,
- String[] keysToSkip,
+ Map<String, String> attributes,
+ Collection<String> types,
+ Collection<String> keysToSkip,
String[] keysToAdd) {
- String[] validNumberKeysInMap = MapUtilities.getValidKeysOfTypesInMap(
- map, types, keysToSkip, keysToAdd);
+ Collection<String> validNumberKeysInMap =
+ MapUtilities.getValidKeysOfTypesInMap(attributes, types, keysToSkip);
AttributeDefinition numberAttributeDefinition = cloneToDropdownAttributeDefinition(
oldAttributeDefinition, validNumberKeysInMap, validNumberKeysInMap);
@@ -83,18 +85,20 @@
}
public static AttributeDefinition cloneToDropdownAttributeDefinition(
- AttributeDefinition oldAD, final String[] optionLabels, final String[] optionValues) {
+ AttributeDefinition oldAD,
+ final Collection<String> optionLabels,
+ final Collection<String> optionValues) {
AttributeDefinitionTransformer transformer = new DefaultDropdownTransformer() {
public boolean shouldTransform(AttributeDefinition ad) {
return true;
}
public String[] transformOptionLabels(String[] oldOptionLabels) {
- return optionLabels;
+ return optionLabels.toArray(new String[0]);
}
public String[] transformOptionValues(String[] oldOptionValues) {
- return optionValues;
+ return optionValues.toArray(new String[0]);
}
};
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetUtilities.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetUtilities.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -1,18 +1,18 @@
package org.cishell.utilities;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
public class SetUtilities {
- public static ArrayList getKeysOfMapEntrySetWithValue(Set mapEntrySet,
- Object value) {
- ArrayList keysOfMapEntrySetWithValue = new ArrayList();
- Iterator mapEntrySetIterator = mapEntrySet.iterator();
-
+ public static<K, V> Collection<K> getKeysOfMapEntrySetWithValue(
+ Collection<Map.Entry<K, V>> mapEntries, V value) {
+ Collection<K> keysOfMapEntrySetWithValue = new HashSet<K>();
+ Iterator<Map.Entry<K, V>> mapEntrySetIterator = mapEntries.iterator();
+
while (mapEntrySetIterator.hasNext()) {
- Map.Entry entry = (Map.Entry)mapEntrySetIterator.next();
+ Map.Entry<K, V> entry = mapEntrySetIterator.next();
if (entry.getValue().equals(value)) {
keysOfMapEntrySetWithValue.add(entry.getKey());
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -1,13 +1,13 @@
package org.cishell.utilities.mutateParameter;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import org.cishell.reference.service.metatype.BasicObjectClassDefinition;
import org.cishell.utilities.MutateParameterUtilities;
+import org.cishell.utilities.mutateParameter.dropdown.DropdownTransformer;
import org.osgi.service.metatype.AttributeDefinition;
import org.osgi.service.metatype.ObjectClassDefinition;
@@ -18,37 +18,40 @@
* @see ObjectClassDefinition#REQUIRED
* @see ObjectClassDefinition#OPTIONAL
*/
- public static final List ATOMIC_ATTRIBUTE_DEFINITION_FILTERS;
- static {
- List l = new ArrayList();
- l.add(new Integer(ObjectClassDefinition.REQUIRED));
- l.add(new Integer(ObjectClassDefinition.OPTIONAL));
- ATOMIC_ATTRIBUTE_DEFINITION_FILTERS = Collections.unmodifiableList(l);
- }
+ public static final Collection<Integer> ATOMIC_ATTRIBUTE_DEFINITION_FILTERS =
+ Collections.unmodifiableList(Arrays.asList(
+ new Integer(ObjectClassDefinition.REQUIRED),
+ new Integer(ObjectClassDefinition.OPTIONAL)));
+// static {
+// List l = new ArrayList();
+// l.add(new Integer(ObjectClassDefinition.REQUIRED));
+// l.add(new Integer(ObjectClassDefinition.OPTIONAL));
+// ATOMIC_ATTRIBUTE_DEFINITION_FILTERS = Collections.unmodifiableList(l);
+// }
/* Create newOCD from oldOCD by applying transformer
* to each AttributeDefinition.
*/
public static BasicObjectClassDefinition apply(
AttributeDefinitionTransformer transformer,
- ObjectClassDefinition oldOCD,
+ ObjectClassDefinition oldObjectClassDefinition,
Collection<String> attributesToIgnore) {
BasicObjectClassDefinition newOCD =
- MutateParameterUtilities.createNewParameters(oldOCD);
+ MutateParameterUtilities.createNewParameters(oldObjectClassDefinition);
// For each kind of AttributeDefinition filter ..
- for (Iterator filterIt = ATOMIC_ATTRIBUTE_DEFINITION_FILTERS.iterator();
+ for (Iterator<Integer> filterIt = ATOMIC_ATTRIBUTE_DEFINITION_FILTERS.iterator();
filterIt.hasNext();) {
- int filter = ((Integer) filterIt.next()).intValue();
+ int filter = filterIt.next().intValue();
// Grab all matching AttributeDefinitions and transform them.
- AttributeDefinition[] oldADs =
- oldOCD.getAttributeDefinitions(filter);
-
- for (int ii = 0; ii < oldADs.length; ii++) {
- if (!attributesToIgnore.contains(oldADs[ii].getID())) {
+ AttributeDefinition[] oldAttributeDefintions =
+ oldObjectClassDefinition.getAttributeDefinitions(filter);
+
+ for (AttributeDefinition attributeDefinition : oldAttributeDefintions) {
+ if (!attributesToIgnore.contains(attributeDefinition.getID())) {
newOCD.addAttributeDefinition(
- filter, transformer.transform(oldADs[ii]));
+ filter, transformer.transform(attributeDefinition));
}
}
}
@@ -58,16 +61,17 @@
// Convenience method for batching transformations.
public static ObjectClassDefinition transform(
- ObjectClassDefinition ocd, List transformers, Collection<String> attributesToIgnore) {
- ObjectClassDefinition newOCD = ocd;
+ ObjectClassDefinition objectClassDefinition,
+ Collection<DropdownTransformer> transformers,
+ Collection<String> attributesToIgnore) {
+ ObjectClassDefinition newObjectClassDefinition = objectClassDefinition;
- for (Iterator it = transformers.iterator(); it.hasNext();) {
- AttributeDefinitionTransformer transformer =
- (AttributeDefinitionTransformer) it.next();
-
- newOCD = apply(transformer, newOCD, attributesToIgnore);
+ for (Iterator<DropdownTransformer> it = transformers.iterator(); it.hasNext();) {
+ DropdownTransformer transformer = it.next();
+ newObjectClassDefinition =
+ apply(transformer, newObjectClassDefinition, attributesToIgnore);
}
- return newOCD;
+ return newObjectClassDefinition;
}
}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java 2010-07-01 20:13:22 UTC (rev 1079)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java 2010-07-06 20:08:57 UTC (rev 1080)
@@ -2,8 +2,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.cishell.utilities.ArrayUtilities;
@@ -19,31 +19,31 @@
* and mutate(ObjectClassDefinition)
*/
public class DropdownMutator {
- private List transforms;
+ private Collection<DropdownTransformer> transforms;
private Set<String> attributesToIgnore = new HashSet<String>();
public DropdownMutator() {
- transforms = new ArrayList();
+ this.transforms = new ArrayList<DropdownTransformer>();
}
- public ObjectClassDefinition mutate(ObjectClassDefinition ocd) {
+ public ObjectClassDefinition mutate(ObjectClassDefinition objectClassDefinition) {
return ObjectClassDefinitionTransformer.transform(
- ocd, transforms, this.attributesToIgnore);
+ objectClassDefinition, this.transforms, this.attributesToIgnore);
}
- public void add(String id, List options, String defaultOption) {
+ public void add(String id, Collection<String> options, String defaultOption) {
add(id, swapToFront(options, defaultOption));
}
- public void add(String id, List options) {
+ public void add(String id, Collection<String> options) {
add(id, options, options);
}
public void add(
String id,
- List optionLabels,
+ Collection<String> optionLabels,
String defaultOptionLabel,
- List optionValues,
+ Collection<String> optionValues,
String defaultOptionValue) {
add(
id,
@@ -51,7 +51,7 @@
swapToFront(optionValues, defaultOptionValue));
}
- public void add(String id, List optionLabels, List optionValues) {
+ public void add(String id, Collection<String> optionLabels, Collection<String> optionValues) {
add(
id,
(String[]) optionLabels.toArray(new String[0]),
@@ -81,9 +81,7 @@
}
public void add(
- final String id,
- final String[] optionLabels,
- final String[] optionValues) {
+ final String id, final String[] optionLabels, final String[] optionValues) {
if (!shouldIgnore(id)) {
transforms.add(
new DefaultDropdownTransformer() {
@@ -110,8 +108,8 @@
return this.attributesToIgnore.contains(id);
}
- private static List swapToFront(List list, String target) {
- String[] temp = (String[]) list.toArray(new String[]{});
+ private static Collection<String> swapToFront(Collection<String> items, String target) {
+ String[] temp = (String[]) items.toArray(new String[]{});
return Arrays.asList(swapToFront(temp, target));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-01 20:13:29
|
Revision: 1079
http://cishell.svn.sourceforge.net/cishell/?rev=1079&view=rev
Author: pataphil
Date: 2010-07-01 20:13:22 +0000 (Thu, 01 Jul 2010)
Log Message:
-----------
* Refactored some convenience styled printing functionality out of org.cishell.reference.gui.log.LogView and into org.cishell.utilities.swt.
* Discussed with Micah.
Modified Paths:
--------------
trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF
trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java
Modified: trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF 2010-07-01 20:11:42 UTC (rev 1078)
+++ trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF 2010-07-01 20:13:22 UTC (rev 1079)
@@ -8,4 +8,5 @@
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
Eclipse-LazyStart: true
-Import-Package: org.osgi.service.log;version="1.3.0"
+Import-Package: org.cishell.utilities.swt,
+ org.osgi.service.log;version="1.3.0"
Modified: trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2010-07-01 20:11:42 UTC (rev 1078)
+++ trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2010-07-01 20:13:22 UTC (rev 1079)
@@ -14,32 +14,27 @@
* ***************************************************************************/
package org.cishell.reference.gui.log;
-//standard java
import java.io.BufferedWriter;
-import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import org.cishell.utilities.swt.SWTUtilities;
+import org.cishell.utilities.swt.URLClickedListener;
+import org.cishell.utilities.swt.URLMouseCursorListener;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
@@ -59,45 +54,43 @@
public static final String CONFIGURATION_DIRECTORY = "configuration";
public static final String WELCOME_TEXT_FILE_NAME = "Welcome.properties";
public static final String GREETING_PROPERTY = "greeting";
+
+ public static final Color URL_COLOR = getSystemColor(SWT.COLOR_BLUE);
+ public static final Color LOG_ERROR_COLOR = getSystemColor(SWT.COLOR_RED);
+ public static final Color LOG_WARNING_COLOR = new Color(Display.getDefault(), 255, 127, 0);
+ public static final Color LOG_INFO_COLOR = getSystemColor(SWT.COLOR_BLACK);
+ public static final Color LOG_DEBUG_COLOR = new Color(Display.getDefault(), 150, 150, 150);
+
+ private static Color getSystemColor(final int swtColor) {
+ final Color[] color = new Color[1];
+
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ color[0] = Display.getDefault().getSystemColor(swtColor);
+ }
+ });
+
+ return color[0];
+ }
- private static LogView defaultView;
- private static Composite parent;
- private static StyledText text;
-
- private static Map colorMapping;
- private static Color URL_COLOR;
- private static Color LOG_ERROR_COLOR;
- private static Color LOG_WARNING_COLOR;
- //FOR ALGORITHM INFO
- private static Color LOG_INFO_COLOR;
- //FOR ACTIVITY INFO
- private static Color LOG_DEBUG_COLOR;
-
- private static URLClickedListener urlListener;
- private static URLMouseCursorListener urlCursorListener;
+ public static final Map<String, Color> COLOR_MAPPING = getColorMapping();
+
+ private static Map<String, Color> getColorMapping() {
+ Map<String, Color> colorMapping = new HashMap<String, Color>();
+ colorMapping.put("" + LogService.LOG_DEBUG, LOG_DEBUG_COLOR);
+ colorMapping.put("" + LogService.LOG_INFO, LOG_INFO_COLOR);
+ colorMapping.put("" + LogService.LOG_WARNING, LOG_WARNING_COLOR);
+ colorMapping.put("" + LogService.LOG_ERROR, LOG_ERROR_COLOR);
+
+ return Collections.unmodifiableMap(colorMapping);
+ }
+
+ private Composite parent;
+ private StyledText textField;
+ private URLClickedListener urlListener;
+ private URLMouseCursorListener urlCursorListener;
- static {
- Display.getDefault().syncExec(new Runnable(){
- public void run(){
- LOG_ERROR_COLOR =
- Display.getDefault().getSystemColor(SWT.COLOR_RED);
- // Orange.
- LOG_WARNING_COLOR =
- new Color(Display.getDefault(), 255, 127, 0);
- LOG_INFO_COLOR =
- Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
- // Gray.
- LOG_DEBUG_COLOR =
- new Color(Display.getDefault(), 150, 150, 150);
-
- URL_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
- }
- });
- }
-
public LogView() {
- defaultView = this;
-
//TODO: Need to set the log level based on preferences service
/* Configuration cfg = IVC.getInstance().getConfiguration();
boolean showAll = cfg.getBoolean(IVCPreferences.SHOW_ALL_ERRORS_PREFERENCE);
@@ -109,66 +102,56 @@
currentLevel = LogService.LOG_INFO;
}
*/
- this.colorMapping = new HashMap();
- this.colorMapping.put("" + LogService.LOG_DEBUG, LOG_DEBUG_COLOR);
- this.colorMapping.put("" + LogService.LOG_INFO, LOG_INFO_COLOR);
- this.colorMapping.put("" + LogService.LOG_WARNING, LOG_WARNING_COLOR);
- this.colorMapping.put("" + LogService.LOG_ERROR, LOG_ERROR_COLOR);
}
- public static LogView getDefault() {
- return defaultView;
- }
-
/**
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
+ // TODO: Refactor this. Do we even need the member variables?
+ @SuppressWarnings("unchecked")
public void createPartControl(Composite parent) {
- LogView.parent = parent;
- this.text = new StyledText(parent,
- SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY);
- this.text.setEditable(false);
- this.text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
- this.text.getCaret().setVisible(false);
+ this.parent = parent;
+ this.textField = new StyledText(parent, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY);
+ this.textField.setEditable(false);
+ this.textField.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
+ this.textField.getCaret().setVisible(false);
// Handle URL.
- this.urlListener = new URLClickedListener();
- this.text.addMouseListener(this.urlListener);
- this.urlCursorListener = new URLMouseCursorListener();
- this.text.addMouseMoveListener(this.urlCursorListener);
+ this.urlListener = new URLClickedListener(textField);
+ this.textField.addMouseListener(this.urlListener);
+ this.urlCursorListener = new URLMouseCursorListener(this.parent, this.textField);
+ this.textField.addMouseMoveListener(this.urlCursorListener);
- //add copy context menu when hover a block of text and right click the mouse
+ // Add copy context menu when hover a block of textField and right click the mouse.
Display display = Display.getDefault();
- final Clipboard cb = new Clipboard(display);
- final Menu menu = new Menu(text);
+ final Clipboard clipboard = new Clipboard(display);
+ final Menu menu = new Menu(textField);
menu.setVisible(false);
MenuItem actionItem = new MenuItem(menu, SWT.PUSH);
actionItem.setText("Copy");
- actionItem.addListener(SWT.Selection,
- new Listener() {
- public void handleEvent(Event event) {
- String textData = text.getSelectionText();
- TextTransfer textTransfer = TextTransfer.getInstance();
- cb.setContents(new Object[] { textData },
- new Transfer[] { textTransfer });
- }
- });
+ actionItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ String textData = LogView.this.textField.getSelectionText();
+ TextTransfer textTransfer = TextTransfer.getInstance();
+ clipboard.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
+ }
+ });
- text.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- String selection = ((StyledText) e.widget).getSelectionText();
+ textField.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ String selection = ((StyledText) event.widget).getSelectionText();
if (selection.equals("")) {
- text.setMenu(null);
+ textField.setMenu(null);
} else {
- text.setMenu(menu);
+ textField.setMenu(menu);
}
}
});
- //Get LogReaderService through BundleContext
- //Add itself to the LogReaderService as a LogListener
+ // Get LogReaderService through BundleContext.
+ // Add itself to the LogReaderService as a LogListener.
BundleContext context = Activator.getContext();
ServiceReference logReaderServiceReference =
context.getServiceReference(LogReaderService.class.getName());
@@ -191,31 +174,27 @@
ServiceReference logServiceReference =
context.getServiceReference(LogService.class.getName());
- LogService logService =
- (LogService)context.getService(logServiceReference);
+ LogService logService = (LogService) context.getService(logServiceReference);
if (logService != null) {
try {
- URL welcomeTextFileURL = new URL(new URL(System.getProperty("osgi.configuration.area")), WELCOME_TEXT_FILE_NAME);
+ URL welcomeTextFileURL = new URL(new URL(
+ System.getProperty("osgi.configuration.area")), WELCOME_TEXT_FILE_NAME);
Properties properties = new Properties();
properties.load(welcomeTextFileURL.openStream());
- String greetingText =
- properties.getProperty(GREETING_PROPERTY, null);
+ String greetingText = properties.getProperty(GREETING_PROPERTY, null);
logService.log(LogService.LOG_INFO, greetingText);
- } catch (IOException ioException) {
- System.err.println("Error reading Welcome properties file: " +
- ioException.getMessage());
+ } catch (IOException e) {
+ System.err.println("Error reading Welcome properties file: " + e.getMessage());
}
- }
- else {
+ } else {
try {
FileWriter fstream = new FileWriter("WelcomeTextError.txt", true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("The Log Service cannot be found.\r\n");
out.close();
- } catch (Exception exception) {
- System.err.println("Error writing to file: " +
- exception.getMessage());
+ } catch (Exception e) {
+ System.err.println("Error writing to file: " + e.getMessage());
}
}
}
@@ -224,21 +203,27 @@
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
*/
public void setFocus() {
- text.setFocus();
+ textField.setFocus();
}
public void logged(final LogEntry entry) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
- String message = entry.getMessage();
try {
+ String message = entry.getMessage();
if (goodMessage(message)) {
- //not all messages end w/ a new line, but they
- //need to to print properly
- if (!message.endsWith("\n"))
+ // Not all messages end w/ a new line, but they need to to print properly.
+ if (!message.endsWith("\n")) {
message += "\n";
+ }
- appendString(message, (Color) colorMapping.get(""+entry.getLevel()));
+ SWTUtilities.appendStringWithURL(
+ LogView.this.textField,
+ LogView.this.urlListener,
+ LogView.this.urlCursorListener,
+ message,
+ COLOR_MAPPING.get("" + entry.getLevel()),
+ URL_COLOR);
}
} catch (Throwable e) {
e.printStackTrace();
@@ -257,173 +242,4 @@
return true;
}
}
-
- /*
- * append the given string to the console with the given color,
- * this will do the job of checking for URLs within the string and
- * registering the proper listeners on them as well.
- */
- private void appendString(String message, Color color) {
- int index = message.indexOf("http://");
- if (index == -1) {
- index = message.indexOf("https://");
- }
- if (index == -1) {
- index = message.indexOf("www.");
- }
-
- if (index > -1) {
- String url = message.substring(index);
- if (url.indexOf(") ") > -1) {
- url = url.substring(0, url.indexOf(") "));
- }
- else if (url.indexOf(" ") > -1) {
- url = url.substring(0, url.indexOf(" "));
- if (url.trim().endsWith(".") ){
- url=url.substring(0, url.length()-1);
- }
- }
- if (url.endsWith(".\n") || url.endsWith(".\t")){
- url=url.substring(0, url.length()-2);
- }
- if (url.indexOf("\n") > -1) {
- url = url.substring(0, url.indexOf("\n"));
- }
- if (url.indexOf("\t") > -1) {
- url = url.substring(0, url.indexOf("\n"));
- }
-
-
- printHelper(message.substring(0, index), color, SWT.NORMAL);
- urlListener.addUrl(text.getText().length(), url);
- urlCursorListener.addUrl(text.getText().length(), url);
- printHelper(url, URL_COLOR, SWT.BOLD);
- appendString(message.substring(index + url.length()), color);
- } else {
- printHelper(message, color, SWT.NORMAL);
- }
- }
-
- /*
- * helper to actually format the string with a style range and
- * append it to the StyledText control
- */
- private static void printHelper(final String inText, final Color color, final int style) {
- Display.getDefault().syncExec(new Runnable(){
- public void run(){
- if (!text.isDisposed()) {
- text.append(inText);
-
- StyleRange sr = new StyleRange();
- sr.start = text.getText().length() - inText.length();
- sr.length = inText.length();
- sr.foreground = color;
- sr.fontStyle = style;
- text.setStyleRange(sr);
-
- //autoscroll
- text.setTopIndex(text.getLineCount());
- }
- }
- });
- }
-
-
- /*
- * class that monitors the mouse and changes the cursor when it is
- * over a URL
- */
- private class URLMouseCursorListener implements MouseMoveListener {
- Map offsetToUrlMap = new HashMap();
-
- public void addUrl(int offset, String url) {
- offsetToUrlMap.put(new Integer(offset), url);
- }
-
- public void mouseMove(MouseEvent e) {
- int position = -1;
-
- try {
- position = text.getOffsetAtLocation(new Point(e.x, e.y));
- } catch (IllegalArgumentException ex) {
- Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW);
- text.setCursor(cursor);
- }
-
- if (position < 0) {
- return;
- }
-
- Integer[] offsets = new Integer[1];
- offsets = (Integer[]) offsetToUrlMap.keySet().toArray(offsets);
-
- boolean overURL = false;
-
- for (int i = 0; i < offsets.length; i++) {
- Integer offset = offsets[i];
- String url = (String) offsetToUrlMap.get(offset);
-
- if (offset != null && url != null && (position >= offset.intValue()) &&
- (position <= (offset.intValue() + url.length()))) {
- overURL = true;
-
- break;
- }
- }
-
- if (overURL) {
- Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
- text.setCursor(cursor);
- } else {
- Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW);
- text.setCursor(cursor);
- }
- }
- }
-
- /*
- * class that listens for clicks on urls and launches a browser appropriatly
- */
- private class URLClickedListener extends MouseAdapter {
- Map offsetToUrlMap = new HashMap();
-
- public void addUrl(int offset, String url) {
- offsetToUrlMap.put(new Integer(offset), url);
- }
-
- public void mouseDown(MouseEvent e) {
- if (e.button != 1) {
- return;
- }
-
- int clicked = -1;
-
- try {
- clicked = text.getOffsetAtLocation(new Point(e.x, e.y));
- } catch (IllegalArgumentException ex) {
- }
-
- if (clicked < 0) {
- return;
- }
-
- Integer[] offsets = new Integer[1];
- offsets = (Integer[]) offsetToUrlMap.keySet().toArray(offsets);
-
- for (int i = 0; i < offsets.length; i++) {
- Integer offset = offsets[i];
- String url = (String) offsetToUrlMap.get(offset);
-
- if (url != null && (clicked >= offset.intValue()) &&
- (clicked <= (offset.intValue() + url.length()))) {
- try {
- Program.launch(url);
- } catch (Exception e1) {
- }
- }
- }
- }
- }
-
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2010-07-01 20:11:48
|
Revision: 1078
http://cishell.svn.sourceforge.net/cishell/?rev=1078&view=rev
Author: pataphil
Date: 2010-07-01 20:11:42 +0000 (Thu, 01 Jul 2010)
Log Message:
-----------
* Added org.cishell.utilities.swt to org.cishell.utilities.
* Added optional SWT dependencies to the manifest.
* Discussed with Micah.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java
Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-06-24 18:18:27 UTC (rev 1077)
+++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-07-01 20:11:42 UTC (rev 1078)
@@ -35,4 +35,7 @@
org.cishell.utilities.mutateParameter,
org.cishell.utilities.mutateParameter.defaultvalue,
org.cishell.utilities.mutateParameter.dropdown,
- org.cishell.utilities.osgi.logging
+ org.cishell.utilities.osgi.logging,
+ org.cishell.utilities.swt
+Require-Bundle: org.eclipse.ui;resolution:=optional,
+ org.eclipse.core.runtime;resolution:=optional
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java 2010-07-01 20:11:42 UTC (rev 1078)
@@ -0,0 +1,98 @@
+package org.cishell.utilities.swt;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+public class SWTUtilities {
+ /*
+ * Append the given string to the console with the given color, this will do the job of
+ * checking for URLs within the string and registering the proper listeners on them as well.
+ */
+ public static void appendStringWithURL(
+ StyledText textField,
+ URLClickedListener urlListener,
+ URLMouseCursorListener urlCursorListener,
+ String message,
+ Color normalColor,
+ Color urlColor) {
+
+ //find a URL in the message
+
+ int index = message.indexOf("http://");
+ if (index == -1) {
+ index = message.indexOf("https://");
+ }
+ if (index == -1) {
+ index = message.indexOf("www.");
+ }
+
+ if (index > -1) {
+ String url = message.substring(index);
+ if (url.indexOf(") ") > -1) {
+ url = url.substring(0, url.indexOf(") "));
+ }
+ else if (url.indexOf(" ") > -1) {
+ url = url.substring(0, url.indexOf(" "));
+ if (url.trim().endsWith(".") ){
+ url=url.substring(0, url.length()-1);
+ }
+ }
+ if (url.endsWith(".\n") || url.endsWith(".\t")){
+ url=url.substring(0, url.length()-2);
+ }
+ if (url.indexOf("\n") > -1) {
+ url = url.substring(0, url.indexOf("\n"));
+ }
+ if (url.indexOf("\t") > -1) {
+ url = url.substring(0, url.indexOf("\n"));
+ }
+
+
+ syncedStyledPrint(textField, message.substring(0, index), normalColor, SWT.NORMAL);
+ urlListener.addURL(textField.getText().length(), url);
+ urlCursorListener.addURL(textField.getText().length(), url);
+ syncedStyledPrint(textField, url, urlColor, SWT.BOLD);
+ appendStringWithURL(
+ textField,
+ urlListener,
+ urlCursorListener,
+ message.substring(index + url.length()),
+ normalColor,urlColor);
+ } else {
+ syncedStyledPrint(textField, message, normalColor, SWT.NORMAL);
+ }
+ }
+
+ /*
+ * Helper to actually format the string with a style range and
+ * append it to the StyledText control.
+ */
+
+ public static void syncedStyledPrint(
+ final StyledText textField, final String message, final Color color, final int style) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run(){
+ styledPrint(textField, message, color, style);
+ }
+ });
+ }
+
+ public static void styledPrint(StyledText textField, String message, Color color, int style) {
+ if (!textField.isDisposed()) {
+ textField.append(message);
+
+ StyleRange styleRange = new StyleRange();
+ styleRange.start = textField.getText().length() - message.length();
+ styleRange.length = message.length();
+ styleRange.foreground = color;
+ styleRange.fontStyle = style;
+ textField.setStyleRange(styleRange);
+
+ // This makes it autoscroll.
+ textField.setTopIndex(textField.getLineCount());
+ }
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java 2010-07-01 20:11:42 UTC (rev 1078)
@@ -0,0 +1,70 @@
+package org.cishell.utilities.swt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.program.Program;
+
+/*
+ * Listens for clicks on urls and launches a browser appropriately.
+ */
+public class URLClickedListener extends MouseAdapter {
+ private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>();
+ private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>();
+ private StyledText textField;
+
+ public URLClickedListener(StyledText textField) {
+ super();
+ this.textField = textField;
+ }
+
+ public void addURL(int offset, String url) {
+ addURL(offset, url, url);
+ }
+
+ public void addURL(int offset, String url, String displayURL) {
+ this.offsetsToURLs.put(offset, url);
+ this.urlsToDisplayURLs.put(url, displayURL);
+ }
+
+ public void mouseDown(MouseEvent event) {
+ if (event.button != 1) {
+ return;
+ }
+
+ int clickedPosition = determineClickedPosition(event);
+
+ if (clickedPosition < 0) {
+ return;
+ }
+
+ for (Integer offset : this.offsetsToURLs.keySet().toArray(new Integer[0])) {
+ String url = this.offsetsToURLs.get(offset);
+ String displayURL = this.urlsToDisplayURLs.get(url);
+
+ if ((displayURL != null) &&
+ (clickedPosition >= offset.intValue()) &&
+ (clickedPosition <= (offset.intValue() + displayURL.length()))) {
+ try {
+ Program.launch(url);
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+
+ private int determineClickedPosition(MouseEvent event) {
+ int clickedPosition = -1;
+
+ try {
+ clickedPosition = this.textField.getOffsetAtLocation(new Point(event.x, event.y));
+ } catch (IllegalArgumentException ex) {
+ }
+
+ return clickedPosition;
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-07-01 20:11:42 UTC (rev 1078)
@@ -0,0 +1,79 @@
+package org.cishell.utilities.swt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+
+/*
+ * Monitors the mouse and changes the cursor when it is over a URL.
+ */
+public class URLMouseCursorListener implements MouseMoveListener {
+ private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>();
+ private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>();
+ private Composite parent;
+ private StyledText textField;
+
+ public URLMouseCursorListener(Composite parent, StyledText textField) {
+ this.parent = parent;
+ this.textField = textField;
+ }
+
+ public void addURL(int offset, String url) {
+ addURL(offset, url, url);
+ }
+
+ public void addURL(int offset, String url, String displayURL) {
+ this.offsetsToURLs.put(new Integer(offset), url);
+ this.urlsToDisplayURLs.put(url, displayURL);
+ }
+
+ public void mouseMove(MouseEvent event) {
+ int urlOffsetOfMousePosition = determineURLOffsetOfMousePosition(event);
+ Integer[] urlOffsets = this.offsetsToURLs.keySet().toArray(new Integer[0]);
+ boolean mouseIsOverURL = determineIfMouseIsHoveringOverURL(urlOffsetOfMousePosition, urlOffsets);
+ Cursor cursor = new Cursor(parent.getDisplay(), determineMouseCursor(mouseIsOverURL));
+ textField.setCursor(cursor);
+ }
+
+ private int determineURLOffsetOfMousePosition(MouseEvent event) {
+ try {
+ return textField.getOffsetAtLocation(new Point(event.x, event.y));
+ } catch (IllegalArgumentException e) {
+ Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW);
+ textField.setCursor(cursor);
+ }
+
+ return -1;
+ }
+
+ private boolean determineIfMouseIsHoveringOverURL(
+ int urlOffsetOfMousePosition, Integer[] urlOffsets) {
+ for (Integer urlOffset : urlOffsets) {
+ String url = this.offsetsToURLs.get(urlOffset);
+
+ if ((urlOffset != null) &&
+ (url != null) &&
+ (urlOffsetOfMousePosition >= urlOffset.intValue()) &&
+ (urlOffsetOfMousePosition <= (urlOffset.intValue() + url.length()))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private int determineMouseCursor(boolean mouseIsOverURL) {
+ if (mouseIsOverURL) {
+ return SWT.CURSOR_HAND;
+ } else {
+ return SWT.CURSOR_ARROW;
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|