From: <mwl...@us...> - 2008-03-21 16:07:33
|
Revision: 664 http://cishell.svn.sourceforge.net/cishell/?rev=664&view=rev Author: mwlinnem Date: 2008-03-21 09:07:14 -0700 (Fri, 21 Mar 2008) Log Message: ----------- Initial import. Moved from NWB repository (shouldn't have been there in the first place). Added Paths: ----------- branches/user_prefs/org.cishell.reference.gui.prefs.swt/.classpath branches/user_prefs/org.cishell.reference.gui.prefs.swt/.project branches/user_prefs/org.cishell.reference.gui.prefs.swt/.settings/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/META-INF/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/META-INF/MANIFEST.MF branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/algorithm.properties branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/component.xml branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/l10n/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/l10n/bundle_en.properties branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/metatype/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/metatype/METADATA.XML branches/user_prefs/org.cishell.reference.gui.prefs.swt/build.properties branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/ComboFieldEditor.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/LabelFieldEditor.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/SpacerFieldEditor.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/TabbedFieldEditorPreferencePage.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/DoubleFieldEditor.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/FloatFieldEditor.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/BlankPreferencePage.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/CIShellPreferencePage.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/CIShellPreferenceStore.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/PreferenceGuiAlgorithm.java branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/PreferenceGuiAlgorithmFactory.java Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/.classpath =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/.classpath (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/.classpath 2008-03-21 16:07:14 UTC (rev 664) @@ -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="build"/> +</classpath> Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/.project =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/.project (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/.project 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.reference.gui.prefs.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: branches/user_prefs/org.cishell.reference.gui.prefs.swt/META-INF/MANIFEST.MF =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/META-INF/MANIFEST.MF (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/META-INF/MANIFEST.MF 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Preference GUI +Bundle-SymbolicName: org.cishell.reference.gui.prefs.swt +Bundle-Version: 0.0.1 +Bundle-ClassPath: . +Import-Package: org.cishell.framework, + org.cishell.framework.algorithm, + org.cishell.framework.data, + org.cishell.service.guibuilder, + org.cishell.reference.prefs.admin, + org.eclipse.jface.dialogs, + org.eclipse.jface.preference, + org.eclipse.jface.resource, + org.eclipse.jface.util, + org.eclipse.jface.window, + org.eclipse.swt, + org.eclipse.swt.events, + org.eclipse.swt.graphics, + org.eclipse.swt.layout, + org.eclipse.swt.widgets, + org.eclipse.ui, + org.osgi.framework;version="1.3.0", + org.osgi.service.cm;version="1.2.0", + org.osgi.service.component;version="1.0.0", + org.osgi.service.log;version="1.3.0", + org.osgi.service.metatype;version="1.1.0", + org.osgi.service.prefs;version="1.1.0" +X-AutoStart: true +Service-Component: OSGI-INF/component.xml Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/algorithm.properties =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/algorithm.properties (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/algorithm.properties 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,7 @@ +menu_path=File/additions +label=Preferences +description=Lets you view and edit CIShell preferences +in_data=null +out_data=null +service.pid=org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithm +remoteable=false Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/component.xml =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/component.xml (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/component.xml 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithm.component" immediate="true"> + <implementation class="org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithmFactory"/> + <properties entry="OSGI-INF/algorithm.properties"/> + <reference name="LOG" interface="org.osgi.service.log.LogService"/> + <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> + <reference name="PREF_ADMIN" interface="org.cishell.reference.prefs.admin.PrefAdmin"/> + + <service> + <provide interface= + "org.cishell.framework.algorithm.AlgorithmFactory"/> + </service> +</component> \ No newline at end of file Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/l10n/bundle_en.properties =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/l10n/bundle_en.properties (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/l10n/bundle_en.properties 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,7 @@ +#Localization variables for OSGI-INF/metatatype/METADATA.XML +# +#Samples: +#input=Input +#desc=Enter an integer (that will be converted to a string) +#name=Input->String +#name_desc=Converts inputted integer to string Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/metatype/METADATA.XML =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/metatype/METADATA.XML (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/OSGI-INF/metatype/METADATA.XML 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> + <OCD name="Preferences" id="org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithm.OCD" + description="Lets you view and edit CIShell preferences "> + <AD name="what" id="ever" type="String" default="work"/> + </OCD> + <Designate pid="org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithm"> + <Object ocdref="org.cishell.reference.gui.prefs.swt.PreferenceGuiAlgorithm.OCD" /> + </Designate> +</metatype:MetaData> Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/build.properties =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/build.properties (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/build.properties 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,5 @@ +source.. = src/ +output.. = build/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/ComboFieldEditor.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/ComboFieldEditor.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/ComboFieldEditor.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,540 @@ +/* ==================================================================== + * Copyright 2003-2004 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package net.sf.commonclipse.preferences; + +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + + +/** + * Implementation identical to StringFieldEditor but using a combo instead of a Text field. + * @author fgiust + * @version $Revision: 1.4 $ ($Author: fgiust $) + */ +public class ComboFieldEditor extends FieldEditor +{ + + /** + * Text limit constant (value <code>-1</code>) indicating unlimited text limit and width. + */ + public static final int UNLIMITED = -1; + + /** + * The text field, or <code>null</code> if none. + */ + Combo textField; + + /** + * predefined values to be shown in list. + */ + private String[] predefinedValues; + + /** + * Cached valid state. + */ + private boolean isValid; + + /** + * Old text value. + */ + private String oldValue; + + /** + * Width of text field in characters; initially unlimited. + */ + private int widthInChars = UNLIMITED; + + /** + * Text limit of text field in characters; initially unlimited. + */ + private int textLimit = UNLIMITED; + + /** + * The error message, or <code>null</code> if none. + */ + private String errorMessage; + + /** + * Indicates whether the empty string is legal; <code>true</code> by default. + */ + private boolean emptyStringAllowed = true; + + /** + * Creates a new string field editor. + */ + protected ComboFieldEditor() + { + } + + /** + * Creates a string field editor. Use the method <code>setTextLimit</code> to limit the text. + * @param name the name of the preference this field editor works on + * @param labelText the label text of the field editor + * @param width the width of the text input field in characters, or <code>UNLIMITED</code> for no limit + * @param parent the parent of the field editor's control + */ + public ComboFieldEditor(String name, String labelText, int width, Composite parent) + { + init(name, labelText); + this.widthInChars = width; + this.isValid = false; + this.errorMessage = JFaceResources.getString("StringFieldEditor.errorMessage"); //$NON-NLS-1$ + createControl(parent); + } + + /** + * Creates a string field editor of unlimited width. Use the method <code>setTextLimit</code> to limit the text. + * @param name the name of the preference this field editor works on + * @param labelText the label text of the field editor + * @param parent the parent of the field editor's control + */ + public ComboFieldEditor(String name, String labelText, Composite parent) + { + this(name, labelText, UNLIMITED, parent); + } + + /** + * Checks whether the text input field contains a valid value or not. + * @return <code>true</code> if the field value is valid, and <code>false</code> if invalid + */ + protected boolean checkState() + { + boolean result = false; + if (this.emptyStringAllowed) + { + result = true; + } + + if (this.textField == null) + { + result = false; + } + + String txt = this.textField.getText(); + + if (txt == null) + { + result = false; + } + + result = (txt.trim().length() > 0) || this.emptyStringAllowed; + + // call hook for subclasses + result = result && doCheckState(); + + if (result) + { + clearErrorMessage(); + } + else + { + showErrorMessage(this.errorMessage); + } + + return result; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#doLoad() + */ + protected void doLoad() + { + if (this.textField != null) + { + + addDefaultOptions(); + String value = getPreferenceStore().getString(getPreferenceName()); + this.textField.setText(value); + this.oldValue = value; + + } + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() + */ + protected void doLoadDefault() + { + if (this.textField != null) + { + addDefaultOptions(); + String value = getPreferenceStore().getDefaultString(getPreferenceName()); + this.textField.setText(value); + + } + valueChanged(); + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#doStore() + */ + protected void doStore() + { + getPreferenceStore().setValue(getPreferenceName(), this.textField.getText()); + } + + /** + * Returns the error message that will be displayed when and if an error occurs. + * @return the error message, or <code>null</code> if none + */ + public String getErrorMessage() + { + return this.errorMessage; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#getNumberOfControls() + */ + public int getNumberOfControls() + { + return 2; + } + + /** + * Returns the field editor's value. + * @return the current value + */ + public String getStringValue() + { + if (this.textField != null) + { + return this.textField.getText(); + } + return getPreferenceStore().getString(getPreferenceName()); + } + + /** + * Returns this field editor's text control. + * @return the text control, or <code>null</code> if no text field is created yet + */ + protected Combo getTextControl() + { + return this.textField; + } + + /** + * Returns this field editor's text control. + * <p> + * The control is created if it does not yet exist + * </p> + * @param parent the parent + * @return the text control + */ + public Combo getTextControl(Composite parent) + { + if (this.textField == null) + { + this.textField = new Combo(parent, SWT.SINGLE | SWT.BORDER); + + this.textField.setFont(parent.getFont()); + + this.textField.addKeyListener(new KeyAdapter() + { + + public void keyReleased(KeyEvent e) + { + valueChanged(); + } + }); + this.textField.addSelectionListener(new SelectionListener() + { + + public void widgetSelected(SelectionEvent e) + { + valueChanged(); + } + + public void widgetDefaultSelected(SelectionEvent e) + { + valueChanged(); + } + + }); + this.textField.addFocusListener(new FocusAdapter() + { + + public void focusGained(FocusEvent e) + { + refreshValidState(); + } + + public void focusLost(FocusEvent e) + { + valueChanged(); + clearErrorMessage(); + } + }); + + this.textField.addDisposeListener(new DisposeListener() + { + + public void widgetDisposed(DisposeEvent event) + { + ComboFieldEditor.this.textField = null; + } + }); + if (this.textLimit > 0) + { // Only set limits above 0 - see SWT spec + this.textField.setTextLimit(this.textLimit); + } + } + else + { + checkParent(this.textField, parent); + } + return this.textField; + } + + /** + * Returns whether an empty string is a valid value. + * @return <code>true</code> if an empty string is a valid value, and <code>false</code> if an empty string is + * invalid + * @see #setEmptyStringAllowed + */ + public boolean isEmptyStringAllowed() + { + return this.emptyStringAllowed; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor # isValid() + */ + public boolean isValid() + { + return this.isValid; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#refreshValidState() + */ + protected void refreshValidState() + { + this.isValid = checkState(); + } + + /** + * Sets whether the empty string is a valid value or not. + * @param b <code>true</code> if the empty string is allowed, and <code>false</code> if it is considered invalid + */ + public void setEmptyStringAllowed(boolean b) + { + this.emptyStringAllowed = b; + } + + /** + * Sets the error message that will be displayed when and if an error occurs. + * @param message the error message + */ + public void setErrorMessage(String message) + { + this.errorMessage = message; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#setFocus() + */ + public void setFocus() + { + if (this.textField != null) + { + this.textField.setFocus(); + } + } + + /** + * Sets this field editor's value. + * @param value the new value, or <code>null</code> meaning the empty string + */ + public void setStringValue(String value) + { + if (this.textField != null) + { + String newValue = value; + if (newValue == null) + { + newValue = ""; //$NON-NLS-1$ + } + + this.oldValue = this.textField.getText(); + + if (!this.oldValue.equals(newValue)) + { + this.textField.setText(newValue); + + valueChanged(); + } + } + } + + /** + * Sets this text field's text limit. + * @param limit the limit on the number of character in the text input field, or <code>UNLIMITED</code> for no + * limit + */ + public void setTextLimit(int limit) + { + this.textLimit = limit; + if (this.textField != null) + { + this.textField.setTextLimit(limit); + } + } + + /** + * Shows the error message set via <code>setErrorMessage</code>. + */ + public void showErrorMessage() + { + showErrorMessage(this.errorMessage); + } + + /** + * Informs this field editor's listener, if it has one, about a change to the value (<code>VALUE</code> property) + * provided that the old and new values are different. + * <p> + * This hook is <em>not</em> called when the text is initialized (or reset to the default value) from the + * preference store. + * </p> + */ + protected void valueChanged() + { + setPresentsDefaultValue(false); + boolean oldState = this.isValid; + refreshValidState(); + + if (this.isValid != oldState) + { + fireStateChanged(IS_VALID, oldState, this.isValid); + } + + String newValue = this.textField.getText(); + if (!newValue.equals(this.oldValue)) + { + fireValueChanged(VALUE, this.oldValue, newValue); + this.oldValue = newValue; + } + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean,Composite). + */ + public void setEnabled(boolean enabled, Composite parent) + { + super.setEnabled(enabled, parent); + getTextControl(parent).setEnabled(enabled); + } + + /** + * Hook for subclasses to do specific state checks. + * <p> + * The default implementation of this framework method does nothing and returns <code>true</code>. Subclasses + * should override this method to specific state checks. + * </p> + * @return <code>true</code> if the field value is valid, and <code>false</code> if invalid + */ + protected boolean doCheckState() + { + return true; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) + */ + protected void adjustForNumColumns(int numColumns) + { + GridData gd = (GridData) this.textField.getLayoutData(); + gd.horizontalSpan = numColumns - 1; + // We only grab excess space if we have to + // If another field editor has more columns then + // we assume it is setting the width. + gd.grabExcessHorizontalSpace = gd.horizontalSpan == 1; + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(Composite, int) + */ + protected void doFillIntoGrid(Composite parent, int numColumns) + { + getLabelControl(parent); + + this.textField = getTextControl(parent); + GridData gd = new GridData(); + gd.horizontalSpan = numColumns - 1; + if (this.widthInChars != UNLIMITED) + { + GC gc = new GC(this.textField); + try + { + Point extent = gc.textExtent("X"); //$NON-NLS-1$ + gd.widthHint = this.widthInChars * extent.x; + } + finally + { + gc.dispose(); + } + } + else + { + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = true; + } + this.textField.setLayoutData(gd); + } + + /** + * Sets a list of predefined values that must be shown in the combo. + * @param strings array of Strings added to the combo + */ + public void setPredefinedValues(String[] strings) + { + this.predefinedValues = strings; + } + + /** + * Adds predefined options to the combo. + */ + private void addDefaultOptions() + { + if (this.textField != null && this.predefinedValues != null) + { + this.textField.setItems(this.predefinedValues); + } + } + + /** + * @see org.eclipse.jface.preference.FieldEditor#clearErrorMessage() + */ + protected void clearErrorMessage() + { + super.clearErrorMessage(); + } + +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/LabelFieldEditor.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/LabelFieldEditor.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/LabelFieldEditor.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,104 @@ +/* ==================================================================== + * Copyright 2003-2004 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package net.sf.commonclipse.preferences; + +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * A field editor for displaying labels not associated with other widgets. + * @author fgiust + * @version $Revision: 1.3 $ ($Author: fgiust $) + */ +public class LabelFieldEditor extends FieldEditor +{ + + /** + * Label for this field editor. + */ + private Label label; + + /** + * All labels can use the same preference name since they don't store any preference. + * @param labelText text for the label + * @param parent Composite + */ + public LabelFieldEditor(String labelText, Composite parent) + { + super("label", labelText, parent); //$NON-NLS-1$ + } + + /** + * Adjusts the field editor to be displayed correctly for the given number of columns. + * @param numColumns number of columns + */ + protected void adjustForNumColumns(int numColumns) + { + ((GridData) this.label.getLayoutData()).horizontalSpan = numColumns; + } + + /** + * Fills the field editor's controls into the given parent. + * @param parent Composite + * @param numColumns cumber of columns + */ + protected void doFillIntoGrid(Composite parent, int numColumns) + { + this.label = getLabelControl(parent); + + GridData gridData = new GridData(); + gridData.horizontalSpan = numColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = false; + gridData.verticalAlignment = GridData.CENTER; + gridData.grabExcessVerticalSpace = false; + + this.label.setLayoutData(gridData); + } + + /** + * Returns the number of controls in the field editor. + * @return 1 + */ + public int getNumberOfControls() + { + return 1; + } + + /** + * Labels do not persist any preferences, so this method is empty. + */ + protected void doLoad() + { + } + + /** + * Labels do not persist any preferences, so this method is empty. + */ + protected void doLoadDefault() + { + } + + /** + * Labels do not persist any preferences, so this method is empty. + */ + protected void doStore() + { + } +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/SpacerFieldEditor.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/SpacerFieldEditor.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/SpacerFieldEditor.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,36 @@ +/* ==================================================================== + * Copyright 2003-2004 Fabrizio Giustina. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package net.sf.commonclipse.preferences; + +import org.eclipse.swt.widgets.Composite; + +/** + * A field editor for adding space to a preference page. + * @author fgiust + * @version $Revision: 1.3 $ ($Author: fgiust $) + */ +public class SpacerFieldEditor extends LabelFieldEditor +{ + /** + * Implemented as an empty label field editor. + * @param parent Composite + */ + public SpacerFieldEditor(Composite parent) + { + super("", parent); //$NON-NLS-1$ + } +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/TabbedFieldEditorPreferencePage.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/TabbedFieldEditorPreferencePage.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/net/sf/commonclipse/preferences/TabbedFieldEditorPreferencePage.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,138 @@ +package net.sf.commonclipse.preferences; + +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; + + +/** + * @author fgiust + * @version $Revision $ ($Author $) + */ +public abstract class TabbedFieldEditorPreferencePage extends FieldEditorPreferencePage +{ + + /** + * Tab folder. + */ + private TabFolder folder; + + /** + * Maximum number of columns for field editors. + */ + private int maxNumOfColumns; + + /** + * Creates a new field editor preference page with the given style, an empty title, and no image. + * @param style either <code>GRID</code> or <code>FLAT</code> + */ + protected TabbedFieldEditorPreferencePage(int style) + { + super(style); + } + + /** + * Creates a new field editor preference page with the given title and style, but no image. + * @param title the title of this preference page + * @param style either <code>GRID</code> or <code>FLAT</code> + */ + protected TabbedFieldEditorPreferencePage(String title, int style) + { + super(title, style); + } + + /** + * Creates a new field editor preference page with the given title, image, and style. + * @param title the title of this preference page + * @param image the image for this preference page, or <code>null</code> if none + * @param style either <code>GRID</code> or <code>FLAT</code> + */ + protected TabbedFieldEditorPreferencePage(String title, ImageDescriptor image, int style) + { + super(title, image, style); + } + + /** + * Adds the given field editor to this page. + * @param editor the field editor + */ + protected void addField(FieldEditor editor) + { + // needed for layout, since there is no way to get fields editor from parent + this.maxNumOfColumns = Math.max(this.maxNumOfColumns, editor.getNumberOfControls()); + super.addField(editor); + } + + /** + * Adjust the layout of the field editors so that they are properly aligned. + */ + protected void adjustGridLayout() + { + if (folder != null) + { + TabItem[] items = folder.getItems(); + for (int j = 0; j < items.length; j++) + { + GridLayout layout = ((GridLayout) ((Composite) items[j].getControl()).getLayout()); + layout.numColumns = this.maxNumOfColumns; + layout.marginHeight = 5; + layout.marginWidth = 5; + } + } + + // need to call super.adjustGridLayout() since fieldEditor.adjustForNumColumns() is protected + super.adjustGridLayout(); + + // reset the main container to a single column + ((GridLayout) super.getFieldEditorParent().getLayout()).numColumns = 1; + } + + /** + * Returns a parent composite for a field editor. + * <p> + * This value must not be cached since a new parent may be created each time this method called. Thus this method + * must be called each time a field editor is constructed. + * </p> + * @return a parent + */ + protected Composite getFieldEditorParent() + { + if (folder == null || folder.getItemCount() == 0) + { + return super.getFieldEditorParent(); + } + return (Composite) folder.getItem(folder.getItemCount() - 1).getControl(); + } + + /** + * Adds a tab to the page. + * @param text the tab label + */ + public void addTab(String text) + { + if (folder == null) + { + // initialize tab folder + folder = new TabFolder(super.getFieldEditorParent(), SWT.NONE); + folder.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + TabItem item = new TabItem(folder, SWT.NONE); + item.setText(text); + + Composite currentTab = new Composite(folder, SWT.NULL); + GridLayout layout = new GridLayout(); + currentTab.setLayout(layout); + currentTab.setFont(super.getFieldEditorParent().getFont()); + currentTab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + item.setControl(currentTab); + } + +} \ No newline at end of file Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/DoubleFieldEditor.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/DoubleFieldEditor.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/DoubleFieldEditor.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,52 @@ +package org.cishell.gui.prefgui.customfields; + +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +public class DoubleFieldEditor extends StringFieldEditor { + + public DoubleFieldEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + setEmptyStringAllowed(false); + } + + protected void doLoad() { + Text text = getTextControl(); + if (text != null) { + double value = getPreferenceStore().getDouble(getPreferenceName()); + text.setText("" + value); + } + } + + protected void doLoadDefault() { + Text text = getTextControl(); + if (text != null) { + double value = getPreferenceStore().getDefaultDouble(getPreferenceName()); + text.setText("" + value);//$NON-NLS-1$ + } + valueChanged(); + } + + protected void doStore() { + Text text = getTextControl(); + if (text != null) { + Double i = Double.valueOf(text.getText()); + getPreferenceStore().setValue(getPreferenceName(), i.doubleValue()); + } + } + + public double getDoubleValue() { + return Double.parseDouble(this.getStringValue()); + } + + public boolean checkState() { + try { + Double.parseDouble(this.getStringValue()); + return true; + } catch (NumberFormatException e) { + //if parsing throws an error, it's invalid. + return false; + } + } +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/FloatFieldEditor.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/FloatFieldEditor.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/customfields/FloatFieldEditor.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,52 @@ +package org.cishell.gui.prefgui.customfields; + +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +public class FloatFieldEditor extends StringFieldEditor { + + public FloatFieldEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + setEmptyStringAllowed(false); + } + + protected void doLoad() { + Text text = getTextControl(); + if (text != null) { + float value = getPreferenceStore().getFloat(getPreferenceName()); + text.setText("" + value); + } + } + + protected void doLoadDefault() { + Text text = getTextControl(); + if (text != null) { + float value = getPreferenceStore().getDefaultFloat(getPreferenceName()); + text.setText("" + value);//$NON-NLS-1$ + } + valueChanged(); + } + + protected void doStore() { + Text text = getTextControl(); + if (text != null) { + Float i = Float.valueOf(text.getText()); + getPreferenceStore().setValue(getPreferenceName(), i.floatValue()); + } + } + + public float getFloatValue() { + return Float.parseFloat(this.getStringValue()); + } + + public boolean checkState() { + try { + Float.parseFloat(this.getStringValue()); + return true; + } catch (NumberFormatException e) { + //if parsing throws an error, it's invalid. + return false; + } + } +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/BlankPreferencePage.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/BlankPreferencePage.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/BlankPreferencePage.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,22 @@ +package org.cishell.gui.prefgui.preferencepages; + +import net.sf.commonclipse.preferences.LabelFieldEditor; + +import org.eclipse.jface.preference.FieldEditorPreferencePage; + +public class BlankPreferencePage extends FieldEditorPreferencePage { + + private String description; + + public BlankPreferencePage(int style, String title, String description) { + super(style); + this.setTitle(title); + this.description = description; + } + + protected void createFieldEditors() { + LabelFieldEditor label = new LabelFieldEditor(description, this.getFieldEditorParent()); + this.addField(label); + } + +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/CIShellPreferencePage.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/CIShellPreferencePage.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/gui/prefgui/preferencepages/CIShellPreferencePage.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,133 @@ +package org.cishell.gui.prefgui.preferencepages; + +import java.io.IOException; + +import org.cishell.gui.prefgui.customfields.DoubleFieldEditor; +import org.cishell.gui.prefgui.customfields.FloatFieldEditor; +import org.cishell.reference.gui.prefs.swt.CIShellPreferenceStore; +import org.cishell.reference.prefs.admin.PreferenceAD; +import org.cishell.reference.prefs.admin.PreferenceOCD; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ColorFieldEditor; +import org.eclipse.jface.preference.DirectoryFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.FileFieldEditor; +import org.eclipse.jface.preference.FontFieldEditor; +import org.eclipse.jface.preference.IntegerFieldEditor; +import org.eclipse.jface.preference.PathEditor; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.jface.preference.StringFieldEditor; +import org.osgi.service.log.LogService; +import org.osgi.service.metatype.ObjectClassDefinition; + +public class CIShellPreferencePage extends FieldEditorPreferencePage { + + private PreferenceOCD prefOCD; + + private LogService log; + + public CIShellPreferencePage(LogService log, PreferenceOCD prefOCD, + CIShellPreferenceStore prefStore) { + super(FieldEditorPreferencePage.FLAT); + this.setTitle(prefOCD.getName()); + + this.prefOCD = prefOCD; + + this.setPreferenceStore(prefStore); + } + + protected void createFieldEditors() { + PreferenceAD[] prefADs = + prefOCD.getPreferenceAttributeDefinitions(ObjectClassDefinition.ALL); + + for (int ii = 0; ii < prefADs.length; ii++) { + PreferenceAD prefAD = prefADs[ii]; + + int attrType = prefAD.getPreferenceType(); + if (attrType == PreferenceAD.BOOLEAN) { + BooleanFieldEditor bField = + new BooleanFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(bField); + } else if (attrType == PreferenceAD.INTEGER) { + IntegerFieldEditor iField = + new IntegerFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(iField); + } else if (attrType == PreferenceAD.CHOICE) { + String[] optionLabels = prefAD.getOptionLabels(); + String[] optionValues = prefAD.getOptionValues(); + String [][] labelAndValues = new String[optionLabels.length][2]; + + for (int jj = 0; jj < labelAndValues.length; jj++) { + labelAndValues[jj][0] = optionLabels[jj]; + labelAndValues[jj][1] = optionValues[jj]; + } + + RadioGroupFieldEditor rgField + = new RadioGroupFieldEditor( + prefAD.getID(), + prefAD.getName(), + 1, + labelAndValues, + getFieldEditorParent(), + true); + addField(rgField); + } else if (attrType == PreferenceAD.FONT) { + FontFieldEditor foField = + new FontFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(foField); + } else if (attrType == PreferenceAD.DIRECTORY) { + DirectoryFieldEditor dField = + new DirectoryFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + dField.setEmptyStringAllowed(true); + addField(dField); + } else if (attrType == PreferenceAD.FILE) { + FileFieldEditor fiField = + new FileFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + fiField.setEmptyStringAllowed(true); + addField(fiField); + } else if (attrType == PreferenceAD.PATH) { + PathEditor pField = + new PathEditor(prefAD.getID(), prefAD.getName(), prefAD.getName(), getFieldEditorParent()); + addField(pField); + } else if (attrType == PreferenceAD.TEXT) { + StringFieldEditor sField = + new StringFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(sField); + } else if (attrType == PreferenceAD.DOUBLE) { + DoubleFieldEditor dField = + new DoubleFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(dField); + } else if (attrType == PreferenceAD.FLOAT) { + FloatFieldEditor fField = + new FloatFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(fField); + } else if (attrType == PreferenceAD.COLOR) { + ColorFieldEditor cField = + new ColorFieldEditor(prefAD.getID(), prefAD.getName(), getFieldEditorParent()); + addField(cField); + } + } + } + + public void performApply() { + super.performApply(); + //WARNING: this will not work if the PreferenceStore is ever not the CIShellPreferenceStore + + /* + * necessary because we need the preference store to actually save in order to + * distribute the changes we have made, unlike the usual way a preferenceStore operates + * where you can simply set the changes to the preference store and they propagate correctly. + */ + + try { + if (this.getPreferenceStore() instanceof CIShellPreferenceStore) { + CIShellPreferenceStore realPrefStore = (CIShellPreferenceStore) this.getPreferenceStore(); + realPrefStore.save(); + } + } catch (ClassCastException e) { + super.performApply(); + } catch (IOException e) { + this.log.log(LogService.LOG_WARNING, "Unable to save preferences due to I/O Exception", e); + } + } +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/CIShellPreferenceStore.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/CIShellPreferenceStore.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/CIShellPreferenceStore.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,194 @@ +package org.cishell.reference.gui.prefs.swt; + +import java.io.IOException; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.reference.prefs.admin.PreferenceAD; +import org.cishell.reference.prefs.admin.PreferenceOCD; +import org.eclipse.jface.preference.IPersistentPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.osgi.service.cm.Configuration; +import org.osgi.service.log.LogService; +import org.osgi.service.metatype.ObjectClassDefinition; + +public class CIShellPreferenceStore implements IPersistentPreferenceStore { + + private LogService log; + + private PreferenceOCD prefOCD; //could be useful if we implement some new features + private Configuration prefConf; + private Dictionary prefDict; + private Map prefDefaults; + + private boolean needsSaving = false; + + public CIShellPreferenceStore(LogService log, PreferenceOCD prefOCD, Configuration prefConf) { + this.log = log; + this.prefOCD = prefOCD; + this.prefConf = prefConf; + this.prefDict = prefConf.getProperties(); + + if (this.prefDict == null) { + this.log.log(LogService.LOG_WARNING, "The configuration dictionary for the configuration object " + + prefConf.getPid() + "is null. \r\n" + "This may be due to an error in a bundles metadata, or may" + + " be an internal error. This will likely cause errors related to preferences."); + } + + generatePrefDefaults(prefOCD); + } + + public boolean contains(String name) { + return prefDict.get(name) != null; + } + + public boolean getBoolean(String name) { + return Boolean.parseBoolean((String) this.prefDict.get(name)); + } + + public boolean getDefaultBoolean(String name) { + return Boolean.valueOf(((String) this.prefDefaults.get(name))).booleanValue(); + } + + public double getDefaultDouble(String name) { + return Double.valueOf(((String) this.prefDefaults.get(name))).doubleValue(); + } + + public float getDefaultFloat(String name) { + return Float.valueOf(((String) this.prefDefaults.get(name))).floatValue(); + } + + public int getDefaultInt(String name) { + return Integer.valueOf(((String) this.prefDefaults.get(name))).intValue(); + } + + public long getDefaultLong(String name) { + return Long.valueOf(((String) this.prefDefaults.get(name))).longValue(); + } + + public String getDefaultString(String name) { + return ((String) this.prefDefaults.get(name)); + } + + public double getDouble(String name) { + return Double.parseDouble(((String) this.prefDict.get(name))); + } + + public float getFloat(String name) { + return Float.parseFloat(((String) this.prefDict.get(name))); + } + + public int getInt(String name) { + return Integer.parseInt(((String) this.prefDict.get(name))); + } + + public long getLong(String name) { + return Long.parseLong(((String) this.prefDict.get(name))); + } + + public String getString(String name) { + String result = (String) this.prefDict.get(name); + return result; + } + + public boolean isDefault(String name) { + return prefDefaults.get(name).equals(prefDict.get(name)); + } + + public boolean needsSaving() { + return this.needsSaving; + } + + public void putValue(String name, String value) { + this.prefDict.put(name, value); + } + + + public void setToDefault(String name) { + this.needsSaving = true; + String defaultVal = (String) this.prefDefaults.get(name); + this.prefDict.put(name, defaultVal); + } + + public void setValue(String name, double value) { + this.needsSaving = true; + this.prefDict.put(name, String.valueOf(value)); + } + + public void setValue(String name, float value) { + this.needsSaving = true; + this.prefDict.put(name, String.valueOf(value)); + } + + public void setValue(String name, int value) { + this.needsSaving = true; + this.prefDict.put(name, String.valueOf(value)); + } + + public void setValue(String name, long value) { + this.needsSaving = true; + this.prefDict.put(name,String.valueOf(value)); + } + + public void setValue(String name, String value) { + this.needsSaving = true; + this.prefDict.put(name, value); + } + + public void setValue(String name, boolean value) { + this.needsSaving = true; + + this.prefDict.put(name, String.valueOf(value)); + } + + public void save() throws IOException { + this.needsSaving = false; + this.prefConf.update(this.prefDict); + } + + private void generatePrefDefaults(PreferenceOCD prefOCD) { + PreferenceAD[] prefADs = prefOCD.getPreferenceAttributeDefinitions(ObjectClassDefinition.ALL); + Map prefDefaults = new HashMap(prefADs.length); + for (int ii = 0; ii < prefADs.length; ii++) { + PreferenceAD prefAD = prefADs[ii]; + prefDefaults.put(prefAD.getID(), prefAD.getDefaultValue()[0]); + } + this.prefDefaults = prefDefaults; + } + + //We don't set defaults like this (they are defined by the default field in MetaType Attribute Definitions) + + public void setDefault(String name, double value) { + } + + public void setDefault(String name, float value) { + } + + public void setDefault(String name, int value) { + } + + public void setDefault(String name, long value) { + } + + public void setDefault(String name, String defaultObject) { + } + + public void setDefault(String name, boolean value) { + } + + //more unsupported methods + + public void removePropertyChangeListener(IPropertyChangeListener listener) { + } + + public void firePropertyChangeEvent(String name, Object oldValue, + Object newValue) { + } + + public void addPropertyChangeListener(IPropertyChangeListener listener) { + } + + + +} Added: branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/PreferenceGuiAlgorithm.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/PreferenceGuiAlgorithm.java (rev 0) +++ branches/user_prefs/org.cishell.reference.gui.prefs.swt/src/org/cishell/reference/gui/prefs/swt/PreferenceGuiAlgorithm.java 2008-03-21 16:07:14 UTC (rev 664) @@ -0,0 +1,137 @@ +package org.cishell.reference.gui.prefs.swt; + +import java.util.Arrays; +import java.util.Dictionary; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.data.Data; +import org.cishell.gui.prefgui.preferencepages.BlankPreferencePage; +import org.cishell.gui.prefgui.preferencepages.CIShellPreferencePage; +import org.cishell.reference.prefs.admin.PrefAdmin; +import org.cishell.reference.prefs.admin.PrefPage; +import org.cishell.reference.prefs.admin.PrefPageComparator; +import org.cishell.reference.prefs.admin.PreferenceOCD; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.jface.preference.PreferenceManager; +import org.eclipse.jface.preference.PreferenceNode; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.osgi.service.cm.Configuration; +import org.osgi.service.log.LogService; + + +public class PreferenceGuiAlgorithm implements Algorithm { + Data[] data; + Dictionary parameters; + CIShellContext context; + + PrefAdmin prefAdmin; + + LogService log; + + public PreferenceGuiAlgorithm(Data[] data, Dictionary parameters, CIShellContext context, + PrefAdmin prefAdmin, LogService log) { + this.data = data; + this.parameters = parameters; + this.context = context; + + this.prefAdmin = prefAdmin; + this.log = log; + } + + public Data[] execute() { + PreferenceManager prefManager = new PreferenceManager(); + + addGlobalPreferences(prefManager); + addLocalPreferences(prefManager); + addParamPreferences(prefManager); + + Shell parentShell = getParentShell(); + PreferenceGUIRunnable prefGUIRunnable = new PreferenceGUIRunnable(parentShell, prefManager); + Thread preferenceGUIThread = new Thread(prefGUIRunnable); + + //We must tell SWT to run the preference dialog, instead of running it directly ourselves + parentShell.getDisplay().asyncExec(preferenceGUIThread); + + return null; + } + + private void addGlobalPreferences(PreferenceManager prefManager) { + PrefPage[] globalPrefPages = prefAdmin.getGlobalPrefPages(); + + BlankPreferencePage globalPrefPageRoot = new BlankPreferencePage(1, "General Preferences", "Contains preferences that change the workbench's functionality."); + PreferenceNode rootNode = new PreferenceNode("General Preferences Root", globalPrefPageRoot); + prefManager.addToRoot(rootNode); + + addPrefPages(globalPrefPages, rootNode); + } + + private void addLocalPreferences(PreferenceManager prefManager) { + PrefPage[] localPrefPages = prefAdmin.getLocalPrefPages(); + + BlankPreferencePage localPrefPageRoot = new BlankPreferencePage(1, + "Algorithm Preferences", "Contains preferences that modify how particular algorithms work."); + PreferenceNode rootNode = new PreferenceNode("Algorithm Preferences Root", localPrefPageRoot); + prefManager.addToRoot(rootNode); + + addPrefPages(localPrefPages, rootNode); + } + + private void addParamPreferences(PreferenceManager prefManager) { + PrefPage[] paramPrefPages = prefAdmin.getParamPrefPages(); + + BlankPreferencePage paramPrefPageRoot = new BlankPreferencePage(1, "Algorithm Parameter Preferences", + "Contains preferences that specify the default values for algorithm menus"); + PreferenceNode rootNode = new PreferenceNode("General Preferences Root", paramPrefPageRoot); + prefManager.addToRoot(rootNode); + + addPrefPages(paramPrefPages, rootNode); + } + + private Shell getParentShell() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); + + //possibly a better, less seamingly arbitrary way to do this + IWorkbenchWindow window = windows[0]; + Shell parentShell = window.getShell(); + return parentShell; + } + + private void addPrefPages(PrefPage[] prefPages, PreferenceNode rootNode) { + Arrays.sort(prefPages, new PrefPageComparator()); + for (int ii = 0; ii < prefPages.length; ii++) { + PreferenceNode prefNode = makePreferenceNode(prefPages[ii]); + rootNode.add(prefNode); + } + } + + private PreferenceNode makePreferenceNode(PrefPage prefPage) { + PreferenceOCD prefOCD = prefPage.getPrefOCD(); + Configuration prefConf = prefPage.getPrefConf(); + + CIShellPreferenceStore prefStore = new CIShellPreferenceStore(this.log, prefOCD, prefConf); + CIShellPreferencePage guiPrefPage = new CIShellPreferencePage(this.log, + prefOCD, prefStore); + return new PreferenceNode(prefConf.getPid(), guiPrefPage); + } + + private class PreferenceGUIRunnable implements Runnable { + + private Shell parentShell; + private PreferenceManager prefManager; + + public PreferenceGUIRunnable(Shell parentShell, PreferenceManager prefManager) { + this.parentShell = parentShell; + this.prefManager = prefManager; + } + + public void run() { + PreferenceDialog prefDialog = new PreferenceDialog(parentShell, prefManager); + prefDialog.open(); + } + } +} Added: b... [truncated message content] |