From: <bh...@us...> - 2006-10-04 01:46:56
|
Revision: 219 http://svn.sourceforge.net/cishell/?rev=219&view=rev Author: bh2 Date: 2006-09-28 15:16:30 -0700 (Thu, 28 Sep 2006) Log Message: ----------- Initial commit of the new SWT-based GUIBuilder with no dependencies on old IVC code. This will be the official gui builder going forward. Multi-Valued AttributeDefinitions are not yet supported by this version of the GUI Builder. Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.classpath trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.project trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.settings/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.settings/org.eclipse.pde.core.prefs trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/build.properties trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractDialog.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/GUIComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/StringConverter.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/UpdateListener.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/DirectoryComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/FileComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.classpath (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.classpath 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.project =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.project (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.project 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.reference.gui.guibuilder.swt</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/clients/gui/org.cishell.reference.gui.guibuilder.swt/.settings/org.eclipse.pde.core.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.settings/org.eclipse.pde.core.prefs (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/.settings/org.eclipse.pde.core.prefs 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,4 @@ +#Thu Sep 14 16:30:07 EST 2006 +eclipse.preferences.version=1 +pluginProject.equinox=false +pluginProject.extensions=false Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: GUI Builder Reference Implementation Using SWT +Bundle-SymbolicName: org.cishell.reference.gui.guibuilder.swt +Bundle-Version: 0.0.1 +Bundle-Localization: plugin +Import-Package: org.cishell.framework, + org.cishell.service.guibuilder, + org.osgi.framework;version="1.3.0", + org.osgi.service.metatype;version="1.1.0" +Require-Bundle: org.eclipse.swt +Export-Package: org.cishell.reference.gui.guibuilder.swt Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/build.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/build.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/build.properties 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,212 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 14, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt; + +import java.util.Dictionary; + +import org.cishell.reference.gui.guibuilder.swt.builder.GUIComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.UpdateListener; +import org.cishell.service.guibuilder.GUI; +import org.cishell.service.guibuilder.SelectionListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.ObjectClassDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public class SWTGui implements GUI, UpdateListener { + private Shell shell; + private SWTGuiComposite composite; + private SelectionListener listener; + private boolean hitOk = false; + + private Button okButton; + + public SWTGui(final Shell shell, int style, + String id, MetaTypeProvider provider) { + this.shell = shell; + + if (provider == null) { + throw new IllegalArgumentException("Null MetaTypeProvider given"); + } + + ObjectClassDefinition ocd = provider.getObjectClassDefinition(id, null); + shell.setText(ocd.getName()); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + shell.setLayout(gridLayout); + + Font defaultFont = new Font(shell.getDisplay(), "SanSerif", 8, SWT.NONE); + + //stuff to display a message + String message = ocd.getDescription(); + if(message != null && !message.equals("")){ + Label msg = new Label(shell, SWT.CENTER); + msg.setText(message); + + GridData labelData = new GridData(); + labelData.horizontalAlignment = SWT.CENTER; + msg.setLayoutData(labelData); + } + + //set up the user area where the main GUI will be set up using Parameters + composite = new SWTGuiComposite(shell, style, id, provider); + composite.addUpdateListener(this); + + //the group w/ ok and cancel + Composite buttonsGroup = new Composite(shell, SWT.NONE); + FillLayout rowLayout = new FillLayout(); + rowLayout.spacing = 5; + buttonsGroup.setLayout(rowLayout); + + //place them at the bottom right + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.END; + gridData.grabExcessHorizontalSpace = false; + buttonsGroup.setLayoutData(gridData); + + Button cancel = new Button(buttonsGroup, SWT.NONE); + cancel.setText("Cancel"); + cancel.setSize(40, 20); + cancel.setFont(defaultFont); + cancel.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + close(); + } + }); + + okButton = new Button(buttonsGroup, SWT.PUSH); + okButton.setText("OK"); + okButton.setSize(40, 20); + okButton.setFont(defaultFont); + okButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + hitOk = true; + close(); + + if (listener != null) { + listener.hitOk(composite.getEnteredResponses()); + } + } + }); + + shell.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + if (!hitOk && listener != null) { + listener.cancelled(); + } + }}); + + validate(); + } + + /** + * @see org.cishell.service.guibuilder.GUI#close() + */ + public void close() { + shell.getDisplay().syncExec(new Runnable() { + public void run() { + shell.close(); + shell.dispose(); + }}); + } + + /** + * @see org.cishell.service.guibuilder.GUI#isClosed() + */ + public boolean isClosed() { + return shell.isDisposed(); + } + + /** + * @see org.cishell.service.guibuilder.GUI#open() + */ + public void open() { + shell.getDisplay().syncExec(new Runnable() { + public void run() { + shell.pack(); + shell.open(); + }}); + } + + /** + * @see org.cishell.service.guibuilder.GUI#openAndWait() + */ + public Dictionary openAndWait() { + open(); + final Display display = shell.getDisplay(); + + OpenAndWaitListener listener = new OpenAndWaitListener(); + setSelectionListener(listener); + + display.syncExec(new Runnable() { + public void run() { + while (!isClosed()) { + if (!display.readAndDispatch()) display.sleep(); + } + }}); + + return listener.valuesEntered; + } + + private static class OpenAndWaitListener implements SelectionListener { + Dictionary valuesEntered = null; + + public void cancelled() {} + + public void hitOk(Dictionary valuesEntered) { + this.valuesEntered = valuesEntered; + } + } + + /** + * @see org.cishell.service.guibuilder.GUI#setSelectionListener(org.cishell.service.guibuilder.SelectionListener) + */ + public void setSelectionListener(SelectionListener listener) { + this.listener = listener; + } + + public String validate() { + String valid = composite.validate(); + + //if valid is a string then the string is the error message + if (valid != null && valid.length() > 0) { + okButton.setEnabled(false); + } else { + okButton.setEnabled(true); + } + + return valid; + } + + public void componentUpdated(GUIComponent component) { + validate(); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,188 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 14, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Dictionary; +import java.util.Hashtable; + +import org.cishell.reference.gui.guibuilder.swt.builder.AbstractDialog; +import org.cishell.service.guibuilder.GUI; +import org.cishell.service.guibuilder.GUIBuilderService; +import org.cishell.service.guibuilder.SelectionListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.osgi.service.metatype.MetaTypeProvider; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public class SWTGuiBuilderService implements GUIBuilderService { + private static final GUI NULL_GUI = new GUI() { + public void open() {} + public void close() {} + + public boolean isClosed() { + return true; + } + + public Dictionary openAndWait() { + return new Hashtable(); + } + + public void setSelectionListener(SelectionListener listener) { + if (listener != null) + listener.cancelled(); + }}; + + private Display display; + + + public SWTGuiBuilderService(Display display) { + this.display = display; + } + + + public GUI createGUI(String id, MetaTypeProvider parameters) { + GUICreator creator = new GUICreator(id, parameters); + display.syncExec(creator); + + return creator.gui; + } + + private class GUICreator implements Runnable { + GUI gui = NULL_GUI; + String id; + MetaTypeProvider parameters; + + public GUICreator(String id, MetaTypeProvider parameters) { + this.id = id; + this.parameters = parameters; + } + + public void run() { + try { + Shell activeShell = display.getActiveShell(); + + Shell shell = new Shell(activeShell, SWT.DIALOG_TRIM | SWT.RESIZE); + if (activeShell != null) { + shell.setImage(activeShell.getImage()); + } + + gui = new SWTGui(shell,SWT.NONE,id,parameters); + } catch (IllegalArgumentException e) {} + } + } + + private static class Returner { + Object returnValue; + } + + private Shell getActiveShell() { + final Returner returner = new Returner(); + guiRun(new Runnable() { + public void run() { + returner.returnValue = display.getActiveShell(); + }}); + + return (Shell) returner.returnValue; + } + + private void guiRun(Runnable runner) { + if (display.getThread() == Thread.currentThread()) { + runner.run(); + } else { + display.syncExec(runner); + } + } + + public Dictionary createGUIandWait(String id, MetaTypeProvider parameters) { + return createGUI(id, parameters).openAndWait(); + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showConfirm(java.lang.String, java.lang.String, java.lang.String) + */ + public boolean showConfirm(final String title, final String message, final String detail) { + final Returner returner = new Returner(); + + guiRun(new Runnable() { + public void run() { + returner.returnValue = new Boolean( + AbstractDialog.openConfirm(getActiveShell(), title, message, detail)); + }}); + + return ((Boolean)returner.returnValue).booleanValue(); + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showError(java.lang.String, java.lang.String, java.lang.String) + */ + public void showError(final String title, final String message, final String detail) { + guiRun(new Runnable() { + public void run() { + AbstractDialog.openError(getActiveShell(), title, message, detail); + }}); + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showError(java.lang.String, java.lang.String, java.lang.Throwable) + */ + public void showError(String title, String message, Throwable error) { + if (error != null) { + StringWriter writer = new StringWriter(); + error.printStackTrace(new PrintWriter(writer)); + + showError(title, message, writer.getBuffer().toString()); + } + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showInformation(java.lang.String, java.lang.String, java.lang.String) + */ + public void showInformation(final String title, final String message, final String detail) { + guiRun(new Runnable() { + public void run() { + AbstractDialog.openInformation(getActiveShell(), title, message, detail); + }}); + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showQuestion(java.lang.String, java.lang.String, java.lang.String) + */ + public boolean showQuestion(final String title, final String message, final String detail) { + final Returner returner = new Returner(); + + guiRun(new Runnable() { + public void run() { + returner.returnValue = new Boolean( + AbstractDialog.openQuestion(getActiveShell(), title, message, detail)); + }}); + + return ((Boolean)returner.returnValue).booleanValue(); + } + + /** + * @see org.cishell.service.guibuilder.GUIBuilderService#showWarning(java.lang.String, java.lang.String, java.lang.String) + */ + public void showWarning(final String title, final String message, final String detail) { + guiRun(new Runnable() { + public void run() { + AbstractDialog.openWarning(getActiveShell(), title, message, detail); + }}); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,186 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 14, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt; + +import java.util.Dictionary; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Set; + +import org.cishell.reference.gui.guibuilder.swt.builder.ComponentProvider; +import org.cishell.reference.gui.guibuilder.swt.builder.GUIComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.UpdateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.ObjectClassDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public class SWTGuiComposite implements UpdateListener { + private ObjectClassDefinition ocd; + private Dictionary idToComponentMap; + private Dictionary enteredResponses; + protected Set listeners; + + private Composite parent; + private Composite userArea; + private ScrolledComposite userScroll; + private int style; + + public SWTGuiComposite(Composite parent, int style, + String id, MetaTypeProvider provider) { + if (provider == null) { + throw new IllegalArgumentException("Null MetaTypeProvider given"); + } + + this.idToComponentMap = new Hashtable(); + this.ocd = provider.getObjectClassDefinition(id, null); + this.parent = parent; + this.style = style; + this.listeners = new HashSet(); + this.enteredResponses = new Hashtable(); + + setupGUI(); + + AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + for (int i=0; i < attrs.length; i++) { + GUIComponent component = ComponentProvider.getInstance().createComponent(attrs[i]); + + component.setAttributeDefinition(attrs[i]); + component.createGUI(userArea, style); + idToComponentMap.put(attrs[i].getID(), component); + component.addUpdateListener(this); + + Object value = component.getValue(); + String valid = component.validate(); + + if (value != null && (valid == null || valid.length() == 0)) { + enteredResponses.put(component.getAttributeDefinition().getID(), value); + } + } + + userArea.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + enteredResponses = getEnteredResponses(); + }}); + } + + private void setupGUI() { + userScroll = new ScrolledComposite(parent, style); + userScroll.setLayout(new GridLayout(1, true)); + userScroll.setExpandHorizontal(true); + userScroll.setExpandVertical(true); + userScroll.setAlwaysShowScrollBars(false); + + userArea = new Composite(userScroll, SWT.NONE); + userArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN+1,false)); + + GridData gd = new GridData(SWT.FILL,SWT.FILL,true,true); + userArea.setLayoutData(gd); + + GridData userData = new GridData(); + userData.grabExcessVerticalSpace = true; + userData.grabExcessHorizontalSpace = true; + userData.verticalAlignment = SWT.FILL; + userData.horizontalAlignment = SWT.FILL; + + userScroll.setLayoutData(userData); + userScroll.setContent(userArea); + } + + + public ObjectClassDefinition getObjectClassDefinition() { + return ocd; + } + + public Object getResponse(String id) { + GUIComponent component = (GUIComponent) idToComponentMap.get(id); + + return component == null ? null : component.getValue(); + } + + public Dictionary getEnteredResponses() { + return enteredResponses; + } + + /** + * Get this GUI's associated shell. + * @return the shell + */ + public Shell getShell() { + return parent.getShell(); + } + + /** + * Return the created composite GUI. + * @return the composite + */ + public Composite getUserArea() { + return userArea; + } + + public Composite getComposite() { + return userScroll; + } + + public String validate() { + String totalValid = ""; + + AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED); + + for (int i=0; i < attrs.length; i++) { + GUIComponent component = (GUIComponent) idToComponentMap.get(attrs[i].getID()); + String valid = component.validate(); + if (valid != null && valid.length() > 0) { + totalValid += "\"" + valid + "\"; "; + } + } + + return totalValid; + } + + public void componentUpdated(GUIComponent component) { + Object value = component.getValue(); + String valid = component.validate(); + + if (value != null && (valid == null || valid.length() == 0)) { + enteredResponses.put(component.getAttributeDefinition().getID(), value); + } else { + enteredResponses.remove(component.getAttributeDefinition().getID()); + } + + for (Iterator i=listeners.iterator(); i.hasNext(); ) { + ((UpdateListener) i.next()).componentUpdated(component); + } + } + + public void addUpdateListener(UpdateListener listener) { + listeners.add(listener); + } + + public void removeUpdateListener(UpdateListener listener) { + listeners.remove(listener); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,76 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 20, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt.builder; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.osgi.service.metatype.AttributeDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public abstract class AbstractComponent implements GUIComponent { + protected AttributeDefinition attr; + protected boolean drawsLabel; + protected int numColumns; + protected Set listeners; + + public abstract void setValue(Object value); + public abstract Object getValue(); + public abstract String validate(); + public abstract Control createGUI(Composite parent, int style); + + public AbstractComponent(boolean drawsLabel, int numColumns) { + this.drawsLabel = drawsLabel; + this.numColumns = numColumns; + this.listeners = new HashSet(); + } + + public AttributeDefinition getAttributeDefinition() { + if (attr == null) { + throw new IllegalStateException("AttributeDefinition has not been set"); + } + + return attr; + } + + public void setAttributeDefinition(AttributeDefinition attr) { + this.attr = attr; + } + public boolean drawsLabel() { + return drawsLabel; + } + public int getColumns() { + return numColumns; + } + + protected void update() { + for (Iterator i=listeners.iterator(); i.hasNext(); ) { + ((UpdateListener) i.next()).componentUpdated(this); + } + } + + public void addUpdateListener(UpdateListener listener) { + listeners.add(listener); + } + + public void removeUpdateListener(UpdateListener listener) { + listeners.remove(listener); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractDialog.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractDialog.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractDialog.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,493 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Feb 22, 2005 at Indiana University. + */ +package org.cishell.reference.gui.guibuilder.swt.builder; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + + +/** + * This class provides a DialogBox structure that can be extended to create Dialogs for CIShell. + * This framework will enforce consistency in the look and feel of Dialogs in CIShell by providing a + * standard layout of description, content, and buttons[, along with a choice of icon images + * defined as constants in this class]. An optional details section allows the Dialog designer + * to provide additional information when the details button is pressed. + * + * @author Team IVC + */ +public abstract class AbstractDialog extends Dialog { + private static final int DETAILS_HEIGHT = 75; + + public static Image INFORMATION; + public static Image WARNING; + public static Image ERROR; + public static Image QUESTION; + public static Image WORKING; + + static { + Runnable runner = new Runnable() { + public void run() { + INFORMATION = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION); + WARNING = Display.getDefault().getSystemImage(SWT.ICON_WARNING); + ERROR = Display.getDefault().getSystemImage(SWT.ICON_ERROR); + QUESTION = Display.getDefault().getSystemImage(SWT.ICON_QUESTION); + WORKING = Display.getDefault().getSystemImage(SWT.ICON_WORKING); + }}; + + if (Display.getDefault().getThread() == Thread.currentThread()) { + runner.run(); + } else { + Display.getDefault().asyncExec(runner); + } + } + + + private String description = ""; + private String detailsString = ""; + private Text detailsText; + private Shell shell; + private Image image; + private boolean success; + private Composite header; + private Composite content; + private Composite buttons; + private Shell parent; + + /** + * Creates a new AbstractDialog object. + * + * @param parent the parent Shell of this AbstractDialog + * @param title the title to put in the title bar of this AbstractDialog + * @param image the Image to display to the left of the description specified + * for this AbstractDialog. This will usually be one of: + * <ul> + * <li>AbstractDialog.WARNING</li> + * <li>AbstractDialog.INFORMATION</li> + * <li>AbstractDialog.ERROR</li> + * <li>AbstractDialog.WORKING</li> + * <li>AbstractDialog.QUESTION</li> + * </ul> + */ + public AbstractDialog(Shell parent, String title, Image image) { + super(parent, 0); + setText(title); + this.image = image; + this.parent = parent; + init(); + } + + /** + * Closes this AbstractDialog. + * + * @param success true if the dialog was successful, false if it + * was cancelled by the user (or closed prematurely) + */ + public void close(boolean success){ + shell.dispose(); + this.success = success; + } + + /** + * Returns the shell used by this AbstractDialog + * + * @return the shell used by this AbstractDialog + */ + public Shell getShell(){ + return shell; + } + + /** + * Initializes this AbstractDialog. This consists of resetting all of the + * customizable components like the content area, details pane, buttons, + * and description label, and readying the dialog to be refilled with + * new content. + */ + public void init(){ + if(shell != null) + shell.dispose(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); + + if (parent != null) + shell.setImage(parent.getImage()); + + shell.setText(getText()); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + shell.setLayout(layout); + } + + /** + * Opens this AbstractDialog. + * + * @return true if this AbstractDialog was closed by clicking the 'x' in the upper right + * corner of the window, signifying a cancellation, false if the dialog is exited otherwise. + */ + public boolean open() { + if (shell.getDisplay().getThread() == Thread.currentThread()) { + doOpen(); + } else { + shell.getDisplay().syncExec(new Runnable() { + public void run() { + doOpen(); + }}); + } + + Display display = getParent().getDisplay(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return success; + } + + protected void doOpen() { + success = true; + + setupHeader(); + setupContent(); + setupButtons(); + + shell.pack(); + setLocation(); + shell.open(); + shell.addShellListener(new ShellAdapter(){ + public void shellClosed(ShellEvent e) { + success = false; + } + }); + } + + /* + * centers the dialog on its parents shell + */ + private void setLocation(){ + Point parentLocation = parent.getLocation(); + int parentWidth = parent.getSize().x; + int parentHeight = parent.getSize().y; + int shellWidth = shell.getSize().x; + int shellHeight = shell.getSize().y; + + int x = parentLocation.x + (parentWidth - shellWidth)/2; + int y = parentLocation.y + (parentHeight - shellHeight)/2; + shell.setLocation(x, y); + } + + /** + * Sets the Description of this AbstractDialog. This is the text that is displayed in the + * top section of the Dialog window, giving information about the question that is being + * asked or the information that is being given. + * + * @param description the description for this AbstractDialog to use + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the details text of this AbstractDialog. This is the text that is displayed in the lower + * section of the Dialog window when the user presses the "Details >>" button. If this String + * is null or the empty string, the details button will be disabled. + * + * @param details DOCUMENT ME! + */ + public void setDetails(String details) { + this.detailsString = details; + } + + /** + * Creates the Buttons to use in this AbstractDialog based on the given parent. These are + * the buttons that show up at the bottom of the dialog for user input, such as a + * "Yes/No" group or "Continue/Cancel" or something like that. This does not encompass all + * Buttons created in the dialog (such as those created in the content section), just those + * to display at the bottom of the dialog. + * + * @param parent the parent to be used to create the Buttons for this AbstractDialog + */ + public abstract void createDialogButtons(Composite parent); + + /** + * Creates the content section of this AbstractDialog based on the given parent. + * This section is where all of the "guts" of the AbstractDialog go, specifying the controls + * that are needed to interact with the user and provide whatever questions or information + * are needed. + * + * @param parent the parent to be used to create the Buttosn for this AbstractDialog + * + * @return the Composite that is created to display the content of this AbstractDialog + */ + public abstract Composite createContent(Composite parent); + + /* + * Sets up the header section of the dialog. This section contains the image for the + * type of dialog it is, as well as the description label + */ + private void setupHeader() { + header = new Composite(shell, SWT.NONE); + header.setLayoutData(new GridData(GridData.FILL_BOTH)); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + header.setLayout(layout); + + Label canvas = new Label(header, SWT.NONE); + if (image != null) { + canvas.setImage(image); + } + GridData canvasData = new GridData(); + canvasData.heightHint = image.getBounds().height; + canvas.setLayoutData(canvasData); + + Label desc = new Label(header, SWT.WRAP); + + if ((description != null) && !description.equals("")) { + desc.setText(description); + } + + GridData data = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_CENTER); + data.widthHint = 300; + desc.setLayoutData(data); + } + + /* + * sets up the content section of the dialog, this calls the abstract method to + * create the content that must be implemented by all subclasses + */ + private void setupContent() { + content = createContent(shell); + + if (content != null) { + content.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + } + + /* + * sets up the button section in the bottom of the dialog. These buttons + * are created in the abstract method createDialogButtons(parent). In addition to + * any created buttons, a "Details >>" button is added to allow the user to see any + * details that are available in the current Dialog. + */ + private void setupButtons() { + buttons = new Composite(shell, SWT.NONE); + buttons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END)); + + //there are two sections, all the user stuff to the left, and + //then the details button on the far right + //User Buttons Section + createDialogButtons(buttons); + Control[] controls = buttons.getChildren(); + GridLayout buttonsLayout = new GridLayout(); + buttonsLayout.numColumns = controls.length + 1; + buttonsLayout.makeColumnsEqualWidth = true; + buttons.setLayout(buttonsLayout); + + //setup the grid data for each button for standard look + for (int i = 0; i < controls.length; i++) { + controls[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } + + //Details Button section + final Button details = new Button(buttons, SWT.PUSH); + details.setText("Details >>"); + details.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + details.addSelectionListener(new SelectionAdapter() { + public synchronized void widgetSelected(SelectionEvent e) { + GridData data = (GridData) detailsText.getLayoutData(); + + if (detailsText.getVisible()) { + detailsText.setText(""); + details.setText("Details >>"); + data.heightHint = 0; + } else { + detailsText.setText(detailsString); + details.setText("Details <<"); + data.heightHint = DETAILS_HEIGHT; + } + + detailsText.setLayoutData(data); + detailsText.setVisible(!detailsText.getVisible()); + + shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + shell.layout(); + } + }); + + setupDetails(); + details.setEnabled(detailsString != null && !detailsString.equals("")); + } + + /* + * creates the details text box when the "Details >>" button is toggled + */ + private void setupDetails() { + detailsText = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); + detailsText.setEditable(false); + detailsText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); + data.grabExcessHorizontalSpace = true; + data.horizontalSpan = 2; + data.grabExcessVerticalSpace = false; + data.widthHint = 400; + data.heightHint = 0; + + detailsText.setLayoutData(data); + detailsText.setVisible(false); + } + + /** + * Open a standard error dialog with OK button + * + * @param parent the parent Shell of this dialog + * @param title the text to display in the title bar of this dialog + * @param message the message to give in the dialog's body + * @param details the text to put in the details pane to be visible when the + * "Details >>" button is pressed (can be null or empty, resulting + * in the "Details >>" button not being enabled) + * @return true if the dialog was exited by pressing the OK button, false + * if it was cancelled by pressing the 'x' in the title bar + */ + public static boolean openError(Shell parent, String title, String message, String details){ + return openOKDialog(parent, ERROR, title, message, details); + } + + /** + * Open a standard information dialog with OK button + * + * @param parent the parent Shell of this dialog + * @param title the text to display in the title bar of this dialog + * @param message the message to give in the dialog's body + * @param details the text to put in the details pane to be visible when the + * "Details >>" button is pressed (can be null or empty, resulting + * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false + * if it was cancelled by pressing the 'x' in the title bar + */ + public static boolean openInformation(Shell parent, String title, String message, String details){ + return openOKDialog(parent, INFORMATION, title, message, details); + } + + /** + * Open a standard warning dialog with OK button + * + * @param parent the parent Shell of this dialog + * @param title the text to display in the title bar of this dialog + * @param message the message to give in the dialog's body + * @param details the text to put in the details pane to be visible when the + * "Details >>" button is pressed (can be null or empty, resulting + * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false + * if it was cancelled by pressing the 'x' in the title bar + */ + public static boolean openWarning(Shell parent, String title, String message, String details){ + return openOKDialog(parent, WARNING, title, message, details); + } + + /** + * Open a standard question dialog with Yes/No buttons + * + * @param parent the parent Shell of this dialog + * @param title the text to display in the title bar of this dialog + * @param message the message to give in the dialog's body + * @param details the text to put in the details pane to be visible when the + * "Details >>" button is pressed (can be null or empty, resulting + * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false + * if it was cancelled by pressing the 'x' in the title bar or pressing the + * No button + */ + public static boolean openQuestion(Shell parent, String title, String message, String details){ + return openConfirmDenyDialog(parent, QUESTION, title, message, details, "Yes", "No"); + } + + /** + * Open a standard confirmation dialog with OK/Cancel buttons + * + * @param parent the parent Shell of this dialog + * @param title the text to display in the title bar of this dialog + * @param message the message to give in the dialog's body + * @param details the text to put in the details pane to be visible when the + * "Details >>" button is pressed (can be null or empty, resulting + * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false + * if it was cancelled by pressing the 'x' in the title bar or pressing + * the Cancel button + */ + public static boolean openConfirm(Shell parent, String title, String message, String details){ + return openConfirmDenyDialog(parent, QUESTION, title, message, details, "OK", "Cancel"); + } + + /* + * helper to create OK dialogs: error, warning, information + */ + private static boolean openOKDialog(Shell parent, Image image, String title, String message, String details){ + AbstractDialog okDialog = new AbstractDialog(parent, title, image){ + public void createDialogButtons(Composite parent) { + Button ok = new Button(parent, SWT.PUSH); + ok.setText("OK"); + ok.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(true); + } + }); + } + + public Composite createContent(Composite parent) { + return null; + } + }; + okDialog.setDescription(message); + okDialog.setDetails(details); + return okDialog.open(); + } + + /* + * helper to create confirm/deny dialogs: question, confirmation + */ + private static boolean openConfirmDenyDialog(Shell parent, Image image, String title, String message, String details, final String confirmLabel, final String denyLabel){ + AbstractDialog dialog = new AbstractDialog(parent, title, image){ + public void createDialogButtons(Composite parent) { + Button confirm = new Button(parent, SWT.PUSH); + if(confirmLabel != null) + confirm.setText(confirmLabel); + confirm.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(true); + } + }); + Button deny = new Button(parent, SWT.PUSH); + if(denyLabel != null) + deny.setText(denyLabel); + deny.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + return null; + } + }; + dialog.setDescription(message); + dialog.setDetails(details); + return dialog.open(); + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,77 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 15, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt.builder; + +import org.cishell.reference.gui.guibuilder.swt.builder.components.BooleanComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.components.DirectoryComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.components.FileComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.components.LabelingComponent; +import org.cishell.reference.gui.guibuilder.swt.builder.components.StringComponent; +import org.osgi.service.metatype.AttributeDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public class ComponentProvider { + private static final ComponentProvider INSTANCE = new ComponentProvider(); + private ComponentProvider() {} + + public static ComponentProvider getInstance() { + return INSTANCE; + } + + public GUIComponent createComponent(AttributeDefinition attr) { + GUIComponent component = createBasicComponent(attr); + + component = new LabelingComponent(component); + + return component; + } + + public GUIComponent createBasicComponent(AttributeDefinition attr) { + GUIComponent component = null; + switch (attr.getType()) { + case (AttributeDefinition.BOOLEAN): + component = new BooleanComponent(); + break; + case (AttributeDefinition.STRING): + String[] defaultValue = attr.getDefaultValue(); + if (defaultValue != null && defaultValue.length == 1 + && defaultValue[0] != null) { + if (defaultValue[0].startsWith("file:")) { + component = new FileComponent(); + break; + } else if (defaultValue[0].startsWith("directory:")) { + component = new DirectoryComponent(); + break; + } + } + case (AttributeDefinition.BYTE): + case (AttributeDefinition.CHARACTER): + case (AttributeDefinition.DOUBLE): + case (AttributeDefinition.FLOAT): + case (AttributeDefinition.LONG): + case (AttributeDefinition.SHORT): + case (AttributeDefinition.INTEGER): + default: + component = new StringComponent(); + break; + } + + component.setAttributeDefinition(attr); + + return component; + } +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/GUIComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/GUIComponent.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/GUIComponent.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,44 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 15, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt.builder; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.osgi.service.metatype.AttributeDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public interface GUIComponent { + public static final int MAX_SPAN = 3; + public static final Color ERROR_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_RED); + + public Control createGUI(Composite parent, int style); + public int getColumns(); + public boolean drawsLabel(); + + public Object getValue(); + public void setValue(Object value); + public String validate(); + + public void setAttributeDefinition(AttributeDefinition attr); + public AttributeDefinition getAttributeDefinition(); + + public void addUpdateListener(UpdateListener listener); + public void removeUpdateListener(UpdateListener listener); +} Added: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/StringConverter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/StringConverter.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/StringConverter.java 2006-09-28 22:16:30 UTC (rev 219) @@ -0,0 +1,76 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Sep 15, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.reference.gui.guibuilder.swt.builder; + +import org.osgi.service.metatype.AttributeDefinition; + +/** + * + * @author Bruce Herr (bh...@bh...) + */ +public class StringConverter { + private static final StringConverter INSTANCE = new StringConverter(); + private StringConverter() {} + + public static StringConverter getInstance() { + return INSTANCE; + } + + public Object stringToObject(AttributeDefinition attr, String string) { + Object value; + + try { + ... [truncated message content] |