Author: dmaliarevich
Date: 2008-06-05 03:28:21 -0400 (Thu, 05 Jun 2008)
New Revision: 8558
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderCellEditorEx.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderEditor.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderFieldEditor.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
Log:
http://jira.jboss.com/jira/browse/JBIDE-2111, slider control added, source-visual editors
sash weights configuration now available.
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-06-05 07:20:39
UTC (rev 8557)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-06-05 07:28:21
UTC (rev 8558)
@@ -107,8 +107,12 @@
</attributeEditor>
<attributeEditor
class="org.jboss.tools.common.model.ui.attribute.editor.MutableMultipleChoiceEditor"
id="MutableMultipleChoice">
</attributeEditor>
+ <attributeEditor
class="org.jboss.tools.common.model.ui.attribute.editor.SliderEditor"
id="Slider">
+ </attributeEditor>
</extension>
<extension point="org.jboss.tools.common.model.ui.attributeAdapter">
+ <attributeAdapter
class="org.jboss.tools.common.model.ui.attribute.adapter.DefaultValueAdapter"
id="Slider">
+ </attributeAdapter>
<attributeAdapter
class="org.jboss.tools.common.model.ui.attribute.adapter.DefaultValueAdapter"
id="Default">
</attributeAdapter>
<attributeAdapter
class="org.jboss.tools.common.model.ui.attribute.adapter.custom.FileSystemListAdapter"
id="CommonFileSystem">
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderCellEditorEx.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderCellEditorEx.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderCellEditorEx.java 2008-06-05
07:28:21 UTC (rev 8558)
@@ -0,0 +1,67 @@
+package org.jboss.tools.common.model.ui.attribute.editor;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Slider;
+
+public class SliderCellEditorEx extends CellEditor {
+
+ private Slider slider = null;
+ private int style = SWT.HORIZONTAL;
+ private static final int MAX_SLIDER_VALUE = 1000;
+ private static final int MIN_SLIDER_VALUE = 0;
+ private static final int INCREMENT_SLIDER_VALUE = 10;
+ private static final int DEFAULT_SLIDER_VALUE = 500;
+ public SliderCellEditorEx() {
+ super();
+ }
+
+ public SliderCellEditorEx(Composite parent) {
+ super(parent);
+ }
+
+ public SliderCellEditorEx(Composite parent, int style) {
+ super(parent, style);
+ this.style = style;
+ }
+
+ @Override
+ protected Control createControl(Composite parent) {
+ slider = new Slider(parent, this.style);
+ slider.setMaximum(MAX_SLIDER_VALUE);
+ slider.setMinimum(MIN_SLIDER_VALUE);
+ slider.setIncrement(INCREMENT_SLIDER_VALUE);
+ slider.setSelection(DEFAULT_SLIDER_VALUE);
+ return slider;
+ }
+
+ @Override
+ protected Object doGetValue() {
+ if (null != slider) {
+ slider.getSelection();
+ }
+ return null;
+ }
+
+ @Override
+ protected void doSetFocus() {
+ if (null != slider) {
+ slider.setFocus();
+ }
+ }
+
+ @Override
+ protected void doSetValue(Object value) {
+ try {
+ int intValue = Integer.parseInt(value.toString());
+ if (intValue <= MAX_SLIDER_VALUE && intValue >= MIN_SLIDER_VALUE) {
+ slider.setSelection(intValue);
+ }
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderCellEditorEx.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderEditor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderEditor.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderEditor.java 2008-06-05
07:28:21 UTC (rev 8558)
@@ -0,0 +1,41 @@
+package org.jboss.tools.common.model.ui.attribute.editor;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.common.model.ui.widgets.IWidgetSettings;
+
+public class SliderEditor extends ValueEditor {
+
+ public SliderEditor() {}
+
+ public SliderEditor(IWidgetSettings settings) {
+ super(settings);
+ lineEditor = true;
+ }
+
+ public void dispose() {
+ super.dispose();
+ if (cellEditor != null) {
+ cellEditor.dispose();
+ }
+ cellEditor = null;
+ if (fieldEditor != null) {
+ fieldEditor.dispose();
+ }
+ fieldEditor = null;
+ }
+
+ @Override
+ protected CellEditor createCellEditor(Composite parent) {
+ cellEditor = new SliderCellEditorEx();
+ return cellEditor;
+ }
+
+ @Override
+ protected ExtendedFieldEditor createFieldEditor(Composite parent) {
+ fieldEditor = new SliderFieldEditor();
+ fieldEditor.setLabelText(getLabelText());
+ return fieldEditor;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderEditor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderFieldEditor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderFieldEditor.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderFieldEditor.java 2008-06-05
07:28:21 UTC (rev 8558)
@@ -0,0 +1,284 @@
+package org.jboss.tools.common.model.ui.attribute.editor;
+
+import java.beans.PropertyChangeListener;
+
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Slider;
+import org.jboss.tools.common.model.ui.IAttributeErrorProvider;
+import org.jboss.tools.common.model.ui.IValueChangeListener;
+import org.jboss.tools.common.model.ui.IValueProvider;
+import org.jboss.tools.common.model.ui.widgets.IWidgetSettings;
+
+public class SliderFieldEditor extends ExtendedFieldEditor implements
+ IFieldEditor, IPropertyFieldEditor, IPropertyChangeListener,
+ PropertyChangeListener {
+
+ protected IPropertyEditor propertyEditor;
+
+ protected IValueProvider valueProvider;
+ protected IValueChangeListener valueChangeListener;
+
+ private static final String SLIDER_LABEL_DEFAULT_TEXT = "50% / 50% ";
//$NON-NLS-1$
+ private static final int MAX_SLIDER_VALUE = 1000;
+ private static final int MIN_SLIDER_VALUE = 0;
+ private static final int INCREMENT_SLIDER_VALUE = 10;
+ private static final int DEFAULT_SLIDER_VALUE = 500;
+ private Composite composite = null;
+ private Label sliderLabel = null;
+ private Slider slider = null;
+ private SelectionListener selectionListener = null;
+ private int intValue = 0;
+
+ public SliderFieldEditor() {
+ super();
+ }
+
+ public SliderFieldEditor(IWidgetSettings settings) {
+ super(settings);
+ }
+
+ public SliderFieldEditor(IPropertyEditor propertyEditor) {
+ super();
+ this.propertyEditor = propertyEditor;
+ }
+
+ /**
+ * Initializes the slider.
+ */
+ protected void init() {
+ /*
+ * Initialize slider selection value with stored value
+ */
+ try {
+ intValue = Integer.parseInt(valueProvider.getStringValue(true));
+ } catch (Exception e) {
+ // Do nothing
+ }
+ setPropertyChangeListener(this);
+ valueProvider.addValueChangeListener(this);
+ }
+
+ @Override
+ protected void adjustForNumColumns(int numColumns) {
+ if (null != composite) {
+ if (null != composite.getLayoutData()) {
+ ((GridData)slider.getLayoutData()).horizontalSpan = numColumns;
+ }
+ }
+ }
+
+ @Override
+ protected void doFillIntoGrid(Composite parent, int numColumns) {
+ getLabelComposite(parent);
+ Control control = createSpinnerControl(parent);
+ GridData gd;
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ control.setLayoutData(gd);
+ }
+
+ @Override
+ protected void doLoad() {
+ if (null != slider) {
+ slider.setSelection(getPreferenceStore().getInt(getPreferenceName()));
+ valueChanged();
+ }
+ }
+
+ @Override
+ protected void doLoadDefault() {
+ if (null != slider) {
+ slider.setSelection(getPreferenceStore().getDefaultInt(getPreferenceName()));
+ valueChanged();
+ }
+ }
+
+ @Override
+ protected void doStore() {
+ if (null != slider) {
+ getPreferenceStore().setValue(getPreferenceName(), slider.getSelection());
+ }
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 2;
+ }
+
+ @Override
+ public Control[] getControls(Composite parent) {
+ return new Control[] {
+ getLabelComposite(parent),
+ createSpinnerControl(parent)
+ };
+ }
+
+ @Override
+ public void setPropertyEditor(IPropertyEditor propertyEditor) {
+ this.propertyEditor = propertyEditor;
+ if (null != propertyEditor) {
+ valueProvider = (IValueProvider)propertyEditor.getAdapter(IValueProvider.class);
+ valueChangeListener =
(IValueChangeListener)propertyEditor.getAdapter(IValueChangeListener.class);
+ setErrorProvider((IAttributeErrorProvider)propertyEditor.getAdapter(IAttributeErrorProvider.class));
+ }
+ init();
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if(ExtendedFieldEditor.VALUE.equals(event.getProperty())) {
+ setPropertyChangeListener(null);
+ java.beans.PropertyChangeEvent e = new java.beans.PropertyChangeEvent(this,
IPropertyEditor.VALUE, event.getOldValue(), event.getNewValue());
+ valueChangeListener.valueChange(e);
+ setPropertyChangeListener(this);
+ }
+ }
+
+ @Override
+ public void propertyChange(java.beans.PropertyChangeEvent evt) {
+ valueProvider.removeValueChangeListener(this);
+ if (IPropertyEditor.VALUE.equals(evt.getPropertyName())) {
+ Object v = evt.getNewValue();
+ if (null != v) {
+ this.setStringValue(v.toString());
+ }
+ }
+ valueProvider.addValueChangeListener(this);
+ }
+
+ protected Control createSpinnerControl(Composite parent) {
+ /*
+ * Create composite control with label and slider in it.
+ */
+ composite = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.horizontalSpacing = HORIZONTAL_GAP;
+ composite.setLayout(gridLayout);
+ GridData gd;
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ composite.setLayoutData(gd);
+
+ /*
+ * Create label
+ */
+ sliderLabel = new Label(composite,SWT.NONE);
+ gd = new GridData(SWT.LEFT);
+ sliderLabel.setLayoutData(gd);
+ sliderLabel.setText(SLIDER_LABEL_DEFAULT_TEXT);
+ Point size = sliderLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ sliderLabel.setSize(size);
+
+ /*
+ * Create slider
+ */
+ slider = new Slider(composite, SWT.HORIZONTAL);
+ gd = new GridData(SWT.RIGHT | GridData.FILL_HORIZONTAL);
+ slider.setLayoutData(gd);
+
+ slider.setMaximum(MAX_SLIDER_VALUE + slider.getThumb());
+ slider.setMinimum(MIN_SLIDER_VALUE);
+ slider.setIncrement(INCREMENT_SLIDER_VALUE);
+
+ /*
+ * Add listener to handle value change
+ */
+ selectionListener = new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ valueChanged();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
+ }
+ };
+ slider.addSelectionListener(selectionListener);
+ try {
+ intValue = Integer.parseInt(valueProvider.getStringValue(true).toString());
+ } catch (Exception e) {
+ intValue = DEFAULT_SLIDER_VALUE;
+ }
+
+ /*
+ * Initialize slider presentation
+ */
+ slider.setSelection(intValue);
+ String weightsString = "" + (intValue /10)+"% / " + ((100 -
intValue/10)) + "%"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ slider.setToolTipText(weightsString);
+ sliderLabel.setText(weightsString);
+
+ slider.pack();
+ sliderLabel.pack();
+ return composite;
+ }
+
+ /**
+ * Notifies listeners of value change.
+ */
+ protected void valueChanged() {
+ int newValue = slider.getSelection();
+ int oldValue = this.intValue;
+ intValue = newValue;
+ java.beans.PropertyChangeEvent event = new java.beans.PropertyChangeEvent(
+ this, IPropertyEditor.VALUE, oldValue, newValue);
+ valueChangeListener.valueChange(event);
+ }
+
+ /**
+ * Sets the value to slider and updates controls presentation.
+ *
+ * @param stringValue the new slider value
+ */
+ private void setStringValue(String stringValue) {
+ if (null != slider) {
+ try {
+ intValue = Integer.parseInt(stringValue);
+ slider.setSelection(intValue);
+ /*
+ * Show value in percents.
+ */
+ String weightsString = "" + (intValue / 10) + "% / "
//$NON-NLS-1$ //$NON-NLS-2$
+ + ((100 - intValue / 10)) + "%"; //$NON-NLS-1$
+ slider.setToolTipText(weightsString);
+ if (null != sliderLabel) {
+ sliderLabel.setText(weightsString);
+ }
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
+ }
+
+ @Override
+ public void copy() {
+
+ }
+
+ @Override
+ public void cut() {
+
+ }
+
+ @Override
+ public void delete() {
+
+ }
+
+ @Override
+ public void paste() {
+
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/SliderFieldEditor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native