diff options
Diffstat (limited to 'propertysheet/src/org/eclipse/wb/internal/core/model/property/editor')
37 files changed, 0 insertions, 3555 deletions
diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboBoxPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboBoxPropertyEditor.java deleted file mode 100644 index f122381..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboBoxPropertyEditor.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.core.controls.CComboBox; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; -import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils; -import org.eclipse.wb.internal.core.utils.execution.RunnableEx; - -import org.eclipse.swt.SWT; -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.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; - -/** - * The {@link PropertyEditor} for selecting single value using {@link CComboBox}. This editor has - * in-line search-feature and is more suitable (vs {@link AbstractComboPropertyEditor}) for - * properties with large lists of value items. - * - * @author sablin_aa - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class AbstractComboBoxPropertyEditor extends TextDisplayPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - private CComboBox m_combo; - private String m_dropDelayedText; - - @Override - public final boolean activate(final PropertyTable propertyTable, - final Property property, - Point location) throws Exception { - m_combo = new CComboBox(propertyTable, SWT.NONE); - // initialize - addItems(property, m_combo); - selectItem(property, m_combo); - // install listeners - m_combo.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - handleKeyPressed(propertyTable, property, e); - } - }); - m_combo.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - propertyTable.deactivateEditor(true); - } - }); - m_combo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - propertyTable.deactivateEditor(true); - } - }); - m_combo.setFocus(); - // schedule showing drop-down, because we don't have bounds yet - ExecutionUtils.runAsync(new RunnableEx() { - public void run() throws Exception { - m_combo.comboDropDown(true); - if (m_dropDelayedText != null) { - m_combo.setEditText(m_dropDelayedText); - m_combo.setEditSelection(m_dropDelayedText.length(), m_dropDelayedText.length()); - m_dropDelayedText = null; - } - } - }); - // keep editor active - return true; - } - - private void handleKeyPressed(PropertyTable propertyTable, Property property, KeyEvent e) { - if (e.keyCode == SWT.ESC) { - propertyTable.deactivateEditor(false); - } else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { - e.doit = false; - propertyTable.deactivateEditor(true); - propertyTable.navigate(e); - } - } - - @Override - public final void deactivate(PropertyTable propertyTable, Property property, boolean save) { - if (save) { - toProperty(propertyTable, property); - } - if (m_combo != null) { - m_combo.dispose(); - m_combo = null; - } - } - - private void toProperty(PropertyTable propertyTable, Property property) { - try { - toPropertyEx(property, m_combo); - } catch (Throwable e) { - propertyTable.handleException(e); - } - } - - @Override - public void setBounds(Rectangle bounds) { - m_combo.setBounds(bounds); - } - - @Override - public void keyDown(PropertyTable propertyTable, Property property, KeyEvent event) - throws Exception { - boolean withAlt = (event.stateMask & SWT.ALT) != 0; - boolean withCtrl = (event.stateMask & SWT.CTRL) != 0; - if (event.character > 0x20 && !(withAlt || withCtrl)) { - propertyTable.activateEditor(property, null); - m_dropDelayedText = "" + event.character; - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // Abstract methods - // - //////////////////////////////////////////////////////////////////////////// - /** - * Adds items to given {@link CComboBox}. - */ - protected abstract void addItems(Property property, CComboBox combo) throws Exception; - - /** - * Selects current item in given {@link CCombo3}. - */ - protected void selectItem(Property property, CComboBox combo) throws Exception { - } - - /** - * Transfers data from widget to {@link Property}. - */ - protected abstract void toPropertyEx(Property property, CComboBox combo) throws Exception; -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboPropertyEditor.java deleted file mode 100644 index a225f45..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractComboPropertyEditor.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * The {@link PropertyEditor} for selecting single value using {@link CCombo3}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class AbstractComboPropertyEditor extends TextDisplayPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - private CCombo3 m_combo; - private boolean m_doDropDown; - - @Override - public boolean activate(final PropertyTable propertyTable, final Property property, Point location) - throws Exception { - // create combo - { - m_combo = new CCombo3(propertyTable, SWT.NONE); - m_doDropDown = true; - // add items - addItems(property, m_combo); - // select item - selectItem(property, m_combo); - } - // add listeners - m_combo.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - propertyTable.deactivateEditor(true); - } - }); - m_combo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - int index = m_combo.getSelectionIndex(); - toProperty(propertyTable, property, index); - } - }); - m_combo.addListener(SWT.KeyDown, new Listener() { - public void handleEvent(Event event) { - switch (event.keyCode) { - case SWT.ESC : - propertyTable.deactivateEditor(false); - break; - case SWT.DEL : - try { - property.setValue(Property.UNKNOWN_VALUE); - event.doit = false; - selectItem(property, m_combo); - } catch (Throwable e) { - propertyTable.handleException(e); - propertyTable.deactivateEditor(false); - } - m_combo.doDropDown(false); - break; - } - } - }); - m_combo.addMouseListener(new MouseAdapter() { - @Override - public void mouseDoubleClick(MouseEvent e) { - int index = (m_combo.getSelectionIndex() + 1) % m_combo.getItemCount(); - toProperty(propertyTable, property, index); - } - }); - // keep editor active - return true; - } - - @Override - public final void setBounds(Rectangle bounds) { - m_combo.setBounds(bounds); - // editor created without bounds, so activate it after first setBounds() - if (m_doDropDown) { - m_doDropDown = false; - m_combo.setFocus(); - m_combo.doDropDown(true); - m_combo.startDrag(); - } - } - - @Override - public final void deactivate(PropertyTable propertyTable, Property property, boolean save) { - if (m_combo != null) { - m_combo.dispose(); - m_combo = null; - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // Abstract methods - // - //////////////////////////////////////////////////////////////////////////// - /** - * Adds items to given {@link CCombo3}. - */ - protected abstract void addItems(Property property, CCombo3 combo) throws Exception; - - /** - * Selects current item in given {@link CCombo3}. - */ - protected abstract void selectItem(Property property, CCombo3 combo) throws Exception; - - /** - * Transfers data from widget to {@link Property}. - */ - protected abstract void toPropertyEx(Property property, CCombo3 combo, int index) - throws Exception; - - /** - * Transfers data from widget to {@link Property}. - */ - private void toProperty(PropertyTable propertyTable, Property property, int index) { - try { - toPropertyEx(property, m_combo, index); - } catch (Throwable e) { - propertyTable.handleException(e); - } - propertyTable.deactivateEditor(false); - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractListPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractListPropertyEditor.java deleted file mode 100644 index ba34103..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractListPropertyEditor.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.check.Assert; - -import java.util.List; -import java.util.Map; - -/** - * The {@link PropertyEditor} for selecting single expression from given set. - * - * @author sablin_aa - * @coverage core.model.property.editor - */ -public abstract class AbstractListPropertyEditor extends AbstractComboPropertyEditor - implements - IValueSourcePropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // TextDisplayPropertyEditor - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - // return title for value - Object value = property.getValue(); - if (value != Property.UNKNOWN_VALUE) { - int index = getValueIndex(value); - if (index >= 0) { - return getTitle(index); - } else { - if (value instanceof String) { - return (String) value; - } - } - } - // unknown value - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // IValueSourcePropertyEditor - // - //////////////////////////////////////////////////////////////////////////// - @Override -public String getValueSource(Object value) throws Exception { - // return expression for value - if (value != Property.UNKNOWN_VALUE) { - int index = getValueIndex(value); - if (index >= 0) { - return getExpression(index); - } - } - // unknown value - return null; - } - -// //////////////////////////////////////////////////////////////////////////// -// // -// // IClipboardSourceProvider -// // -// //////////////////////////////////////////////////////////////////////////// -// @Override -//public String getClipboardSource(GenericProperty property) throws Exception { -// Object value = property.getValue(); -// return getValueSource(value); -// } - - //////////////////////////////////////////////////////////////////////////// - // - // Combo - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void addItems(Property property, CCombo3 combo) throws Exception { - for (int i = 0; i < getCount(); i++) { - combo.add(getTitle(i)); - } - } - - @Override - protected void selectItem(Property property, CCombo3 combo) throws Exception { - combo.setText(getText(property)); - } - - @Override - protected void toPropertyEx(Property property, CCombo3 combo, int index) throws Exception { -// if (property instanceof GenericProperty) { -// GenericProperty genericProperty = (GenericProperty) property; -// String expression = getExpression(index); -// Object evaluatedExpression = evaluateExpression(genericProperty, expression); -// // apply expression -// genericProperty.setExpression(expression, evaluatedExpression); -// } else { - toPropertyEx_simpleProperty(property, combo, index); -// } - } - -// private static Object evaluateExpression(final GenericProperty genericProperty, -// final String expression) { -// return ExecutionUtils.runObjectIgnore(new RunnableObjectEx<Object>() { -// public Object runObject() throws Exception { -// JavaInfo javaInfo = genericProperty.getJavaInfo(); -// ClassLoader classLoader = JavaInfoUtils.getClassLoader(javaInfo); -// return ScriptUtils.evaluate(classLoader, expression); -// } -// }, Property.UNKNOWN_VALUE); -// System.out.println("HACK 1234"); -// return Property.UNKNOWN_VALUE; -// } - - /** - * Sets value of simple {@link Property}, not {@link GenericProperty}. - */ - protected void toPropertyEx_simpleProperty(Property property, CCombo3 combo, int index) - throws Exception { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Access to list items - // - //////////////////////////////////////////////////////////////////////////// - abstract protected int getCount(); - - abstract protected int getValueIndex(Object value); - - abstract protected String getTitle(int index); - - abstract protected String getExpression(int index) throws Exception; - - //////////////////////////////////////////////////////////////////////////// - // - // Utils - // - //////////////////////////////////////////////////////////////////////////// - /** - * Extract string array from parameters. - */ - protected static String[] getParameterAsArray(Map<String, Object> parameters, String name) { - return getParameterAsArray(parameters, name, false); - } - - @SuppressWarnings("unchecked") - protected static String[] getParameterAsArray(Map<String, Object> parameters, - String name, - boolean noAssert) { - String[] values = null; - if (parameters.containsKey(name)) { - List<String> list = (List<String>) parameters.get(name); - values = list.toArray(new String[list.size()]); - } else { - if (noAssert) { - values = null; - } else { - Assert.fail(String.format("No parameter %s in %s.", name, parameters)); - } - } - return values; - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractTextPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractTextPropertyEditor.java deleted file mode 100644 index 1cf9574..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/AbstractTextPropertyEditor.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.fieldassist.ContentProposalAdapter; -import org.eclipse.jface.fieldassist.IContentProposalProvider; -import org.eclipse.jface.fieldassist.IControlContentAdapter; -import org.eclipse.jface.fieldassist.TextContentAdapter; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -/** - * Abstract {@link PropertyEditor} for that uses {@link Text} as control. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class AbstractTextPropertyEditor extends TextDisplayPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - private Text m_textControl; - private boolean m_ignoreFocusLost; - - // BEGIN ADT MODIFICATIONS - // ContentProposalAdapter which exposes the openProposalPopup method such - // that we can open the dialog up immediately on focus gain to show all available - // alternatives (the default implementation requires at least one keytroke before - // it shows up) - private static class ImmediateProposalAdapter extends ContentProposalAdapter { - public ImmediateProposalAdapter(Text control, - IControlContentAdapter controlContentAdapter, - IContentProposalProvider proposalProvider, KeyStroke keyStroke, - char[] autoActivationCharacters) { - super(control, controlContentAdapter, proposalProvider, keyStroke, - autoActivationCharacters); - - // On focus gain, start completing - control.addFocusListener(new FocusListener() { - @Override - public void focusGained(FocusEvent event) { - openIfNecessary(); - } - - @Override - public void focusLost(FocusEvent event) { - } - }); - - /* Triggering on empty is disabled for now: it has the unfortunate side-effect - that it's impossible to enter a blank text field - blank matches everything, - so the first item will automatically be selected when you press return. - - - // If you edit the text and delete everything, the normal implementation - // will close the popup; we'll reopen it - control.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent event) { - if (((Text) getControl()).getText().isEmpty()) { - openIfNecessary(); - } - } - }); - */ - } - - private void openIfNecessary() { - getControl().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!isProposalPopupOpen()) { - openProposalPopup(); - } - } - }); - } - } - // END ADT MODIFICATIONS - - @Override - public boolean activate(final PropertyTable propertyTable, final Property property, Point location) - throws Exception { - // create Text - { - m_textControl = new Text(propertyTable, SWT.NONE); - new TextControlActionsManager(m_textControl); - m_textControl.setEditable(isEditable()); - - // BEGIN ADT MODIFICATIONS - // Add support for field completion, if the property provides an IContentProposalProvider - // via its the getAdapter method. - IContentProposalProvider completion = property.getAdapter(IContentProposalProvider.class); - if (completion != null) { - ImmediateProposalAdapter adapter = new ImmediateProposalAdapter( - m_textControl, new TextContentAdapter(), completion, null, null); - adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE); - adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); - ILabelProvider labelProvider = property.getAdapter(ILabelProvider.class); - if (labelProvider != null) { - adapter.setLabelProvider(labelProvider); - } - } - // END ADT MODIFICATIONS - m_textControl.setFocus(); - } - // add listeners - m_textControl.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - try { - handleKeyPressed(propertyTable, property, e); - } catch (Throwable ex) { - propertyTable.deactivateEditor(false); - propertyTable.handleException(ex); - } - } - }); - m_textControl.addListener(SWT.FocusOut, new Listener() { - @Override - public void handleEvent(Event event) { - if (!m_ignoreFocusLost) { - propertyTable.deactivateEditor(true); - } - } - }); - // set data - toWidget(property); - // keep us active - return true; - } - - @Override - public final void setBounds(Rectangle bounds) { - m_textControl.setBounds(bounds); - } - - @Override - public final void deactivate(PropertyTable propertyTable, Property property, boolean save) { - if (save) { - try { - toProperty(property); - } catch (Throwable e) { - propertyTable.deactivateEditor(false); - propertyTable.handleException(e); - } - } - // dispose Text widget - if (m_textControl != null) { - m_textControl.dispose(); - m_textControl = null; - } - } - - @Override - public void keyDown(PropertyTable propertyTable, Property property, KeyEvent event) - throws Exception { - boolean withAlt = (event.stateMask & SWT.ALT) != 0; - boolean withCtrl = (event.stateMask & SWT.CTRL) != 0; - if (event.character != 0 && !(withAlt || withCtrl)) { - propertyTable.activateEditor(property, null); - postKeyEvent(SWT.KeyDown, event); - postKeyEvent(SWT.KeyUp, event); - } - } - - /** - * Posts low-level {@link SWT.KeyDown} or {@link SWT.KeyUp} event. - */ - private static void postKeyEvent(int type, KeyEvent event) { - Event lowEvent = new Event(); - lowEvent.type = type; - lowEvent.keyCode = event.keyCode; - lowEvent.character = event.character; - // post event - Display.getCurrent().post(lowEvent); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Events - // - //////////////////////////////////////////////////////////////////////////// - /** - * Handles {@link KeyListener#keyPressed(KeyEvent)}. - */ - private void handleKeyPressed(PropertyTable propertyTable, Property property, KeyEvent e) - throws Exception { - if (e.keyCode == SWT.CR) { - toProperty(property); - - // BEGIN ADT MODIFICATIONS - // After pressing return, dismiss the text cursor to make the value "committed". - // I'm not sure why this is necessary here and not in WindowBuilder proper. - propertyTable.deactivateEditor(true); - // END ADT MODIFICATIONS - } else if (e.keyCode == SWT.ESC) { - propertyTable.deactivateEditor(false); - } else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { - e.doit = false; - boolean success = toProperty(property); - // don't allow navigation if current text can not be transferred to property - if (!success) { - return; - } - // OK, deactivate and navigate - propertyTable.deactivateEditor(true); - propertyTable.navigate(e); - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // Implementation - // - //////////////////////////////////////////////////////////////////////////// - private String m_currentText; - - /** - * Transfers data from {@link Property} to widget. - */ - private void toWidget(Property property) throws Exception { - // prepare text - String text = getEditorText(property); - if (text == null) { - text = ""; - } - // set text - m_currentText = text; - m_textControl.setText(text); - m_textControl.selectAll(); - } - - /** - * Transfers data from widget to {@link Property}. - * - * @return <code>true</code> if transfer was successful. - */ - private boolean toProperty(Property property) throws Exception { - String text = m_textControl.getText(); - // change property only if text was changed - if (!m_currentText.equals(text)) { - m_ignoreFocusLost = true; - try { - boolean success = setEditorText(property, text); - if (!success) { - return false; - } - } finally { - m_ignoreFocusLost = false; - } - // if value was successfully changed, update current text - m_currentText = text; - } - // OK, success - return true; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Operations - // - //////////////////////////////////////////////////////////////////////////// - /** - * @return <code>true</code> if this editor can modify text. - */ - protected boolean isEditable() { - return true; - } - - /** - * @return the text to display in {@link Text} control. - */ - protected abstract String getEditorText(Property property) throws Exception; - - /** - * Modifies {@link Property} using given text. - * - * @return <code>true</code> if {@link Property} was successfully modified. - */ - protected abstract boolean setEditorText(Property property, String text) throws Exception; -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanObjectPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanObjectPropertyEditor.java deleted file mode 100644 index 4f80bb9..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanObjectPropertyEditor.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; -import org.eclipse.wb.internal.core.utils.ui.DrawUtils; - -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; - -/** - * The {@link PropertyEditor} for <code>Boolean</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class BooleanObjectPropertyEditor extends PropertyEditor { - private static final Image m_nullImage = DesignerPlugin.getImage("properties/BooleanNull.png"); - private static final Image m_trueImage = DesignerPlugin.getImage("properties/true.png"); - private static final Image m_falseImage = DesignerPlugin.getImage("properties/false.png"); - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new BooleanObjectPropertyEditor(); - - private BooleanObjectPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception { - Object value = property.getValue(); - if (value instanceof Boolean) { - boolean booleanValue = ((Boolean) value).booleanValue(); - Image image = booleanValue ? m_trueImage : m_falseImage; - String text = Boolean.toString(booleanValue); - paint(gc, x, y, width, height, text, image); - } - if (value == null) { - Image image = m_nullImage; - String text = "null"; - paint(gc, x, y, width, height, text, image); - } - } - - private void paint(GC gc, int x, int y, int width, int height, String text, Image image) { - // draw image - { - DrawUtils.drawImageCV(gc, image, x, y, height); - // prepare new position/width - int imageWidth = image.getBounds().width + 2; - x += imageWidth; - width -= imageWidth; - } - // draw text - { - DrawUtils.drawStringCV(gc, text, x, y, width, height); - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - public boolean activate(PropertyTable propertyTable, Property property, Point location) - throws Exception { - // check that user clicked on image - if (location == null || location.x < m_trueImage.getBounds().width + 2) { - invertValue(property); - } - // don't activate - return false; - } - - @Override - public void doubleClick(Property property, Point location) throws Exception { - invertValue(property); - } - - /** - * Inverts the value of given boolean {@link Property}. - */ - private void invertValue(Property property) throws Exception { - Object value = property.getValue(); - // null - if (value == null) { - property.setValue(true); - return; - } - // boolean - if (value instanceof Boolean) { - boolean booleanValue = ((Boolean) value).booleanValue(); - property.setValue(!booleanValue); - return; - } - // unknown - property.setValue(true); - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanPropertyEditor.java deleted file mode 100644 index 6639afe..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/BooleanPropertyEditor.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; -import org.eclipse.wb.internal.core.utils.ui.DrawUtils; - -/** - * The {@link PropertyEditor} for <code>boolean</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class BooleanPropertyEditor extends PropertyEditor { - private static final Image m_trueImage = DesignerPlugin.getImage("properties/true.png"); - private static final Image m_falseImage = DesignerPlugin.getImage("properties/false.png"); - private static final Image m_unknownImage = - DesignerPlugin.getImage("properties/BooleanUnknown.png"); - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new BooleanPropertyEditor(); - - private BooleanPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception { - Object value = property.getValue(); - if (value instanceof Boolean) { - boolean booleanValue = ((Boolean) value).booleanValue(); - Image image = booleanValue ? m_trueImage : m_falseImage; - String text = Boolean.toString(booleanValue); - paint(gc, x, y, width, height, image, text); - } else { - paint(gc, x, y, width, height, m_unknownImage, "unknown"); - } - } - - /** - * Paints {@link Image} and text. - */ - private void paint(GC gc, int x, int y, int width, int height, Image image, String text) { - // draw image - { - DrawUtils.drawImageCV(gc, image, x, y, height); - // prepare new position/width - int imageWidth = image.getBounds().width + 2; - x += imageWidth; - width -= imageWidth; - } - // draw text - DrawUtils.drawStringCV(gc, text, x, y, width, height); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - public boolean activate(PropertyTable propertyTable, Property property, Point location) - throws Exception { - // check that user clicked on image - if (location == null || location.x < m_trueImage.getBounds().width + 2) { - invertValue(property); - } - // don't activate - return false; - } - - @Override - public void doubleClick(Property property, Point location) throws Exception { - invertValue(property); - } - - /** - * Inverts the value of given boolean {@link Property}. - */ - private void invertValue(Property property) throws Exception { - // prepare current boolean value - boolean booleanValue = false; - { - Object value = property.getValue(); - if (value instanceof Boolean) { - booleanValue = ((Boolean) value).booleanValue(); - } - } - // set inverted value - property.setValue(!booleanValue); - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/CharacterPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/CharacterPropertyEditor.java deleted file mode 100644 index 7e6cfe8..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/CharacterPropertyEditor.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for {@link String}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class CharacterPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new CharacterPropertyEditor(); - - private CharacterPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Character) { - return String.valueOf(((Character) value).charValue()); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // only one character - if (text.length() > 1) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.CharacterPropertyEditor_notValid, text)); - return false; - } - // modify property - property.setValue(new Character(text.charAt(0))); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoubleObjectPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoubleObjectPropertyEditor.java deleted file mode 100644 index bb7dfc5..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoubleObjectPropertyEditor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for {@link Double}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class DoubleObjectPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final DoubleObjectPropertyEditor INSTANCE = new DoubleObjectPropertyEditor(); - - private DoubleObjectPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value == null) { - return "null"; - } - if (value instanceof Double) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // check for "null" - if (text.equals("null")) { - property.setValue(null); - return true; - } - // prepare value - Double value; - try { - value = Double.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.DoubleObjectPropertyEditor_notValidDouble, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoublePropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoublePropertyEditor.java deleted file mode 100644 index 40b73bf..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/DoublePropertyEditor.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for <code>double</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class DoublePropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new DoublePropertyEditor(); - - private DoublePropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Number) { - double doubleValue = ((Number) value).doubleValue(); - return Double.toString(doubleValue); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - } - // prepare value - Double value; - try { - value = Double.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.DoublePropertyEditor_notValidDouble, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/EnumerationValuesPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/EnumerationValuesPropertyEditor.java deleted file mode 100644 index a715df3..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/EnumerationValuesPropertyEditor.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import com.google.common.base.Objects; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.internal.core.model.property.Property; - -import java.beans.PropertyDescriptor; - -/** - * {@link PropertyEditor} for "enumerationValues" attribute of {@link PropertyDescriptor}. - * <p> - * See http://javadude.com/articles/javabeanattributes.html for attributes. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class EnumerationValuesPropertyEditor extends AbstractComboPropertyEditor - implements - IValueSourcePropertyEditor { - private final String[] m_names; - private final Object[] m_values; - private final String[] m_sources; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public EnumerationValuesPropertyEditor(Object attributeValue) { - Object[] enumElements = (Object[]) attributeValue; - int items = enumElements.length / 3; - m_names = new String[items]; - m_values = new Object[items]; - m_sources = new String[items]; - for (int i = 0; i < items; i++) { - m_names[i] = (String) enumElements[3 * i + 0]; - m_values[i] = enumElements[3 * i + 1]; - m_sources[i] = (String) enumElements[3 * i + 2]; - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // TextDisplayPropertyEditor - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - // return name for value - if (value != Property.UNKNOWN_VALUE) { - for (int i = 0; i < m_values.length; i++) { - if (Objects.equal(m_values[i], value)) { - return m_names[i]; - } - } - } - // unknown value - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // IValueSourcePropertyEditor - // - //////////////////////////////////////////////////////////////////////////// - @Override -public String getValueSource(Object value) throws Exception { - if (value != Property.UNKNOWN_VALUE) { - for (int i = 0; i < m_values.length; i++) { - if (Objects.equal(m_values[i], value)) { - return m_sources[i]; - } - } - } - // unknown value - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // IClipboardSourceProvider - // - //////////////////////////////////////////////////////////////////////////// -// public String getClipboardSource(GenericProperty property) throws Exception { -// Object value = property.getValue(); -// return getValueSource(value); -// } - - //////////////////////////////////////////////////////////////////////////// - // - // Combo - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void addItems(Property property, CCombo3 combo) throws Exception { - for (String title : m_names) { - combo.add(title); - } - } - - @Override - protected void selectItem(Property property, CCombo3 combo) throws Exception { - combo.setText(getText(property)); - } - - @Override - protected void toPropertyEx(Property property, CCombo3 combo, int index) throws Exception { - Object value = m_values[index]; -// if (property instanceof GenericProperty) { -// GenericProperty genericProperty = (GenericProperty) property; -// String source = getValueSource(value); -// genericProperty.setExpression(source, value); -// } else { - property.setValue(value); -// } - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/FloatPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/FloatPropertyEditor.java deleted file mode 100644 index d4b468e..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/FloatPropertyEditor.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for <code>float</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class FloatPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new FloatPropertyEditor(); - - protected FloatPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Float) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - } - // prepare value - Float value; - try { - value = Float.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.FloatPropertyEditor_notValidFloat, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ITextValuePropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ITextValuePropertyEditor.java deleted file mode 100644 index ed38c04..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ITextValuePropertyEditor.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.model.property.Property; - -/** - * Extension of {@link PropertyEditor} that can set value using its text presentation. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public interface ITextValuePropertyEditor { - /** - * Sets value that corresponds given text. - */ - void setText(Property property, String text) throws Exception; -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IValueSourcePropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IValueSourcePropertyEditor.java deleted file mode 100644 index 2999bf1..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IValueSourcePropertyEditor.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -/** - * Extension for {@link PropertyEditor} that can be used to convert {@link Object} value into Java - * source. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public interface IValueSourcePropertyEditor { - /** - * @return the Java source for given value. - */ - String getValueSource(Object value) throws Exception; -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerObjectPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerObjectPropertyEditor.java deleted file mode 100644 index f488dff..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerObjectPropertyEditor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for {@link Integer}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class IntegerObjectPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final IntegerObjectPropertyEditor INSTANCE = new IntegerObjectPropertyEditor(); - - private IntegerObjectPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value == null) { - return "null"; - } - if (value instanceof Integer) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // check for "null" - if (text.equals("null")) { - property.setValue(null); - return true; - } - // prepare value - Integer value; - try { - value = Integer.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.IntegerObjectPropertyEditor_notValidInt, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerPropertyEditor.java deleted file mode 100644 index 5be13da..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/IntegerPropertyEditor.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for <code>int</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class IntegerPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final IntegerPropertyEditor INSTANCE = new IntegerPropertyEditor(); - - private IntegerPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Integer) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // prepare value - Integer value; - try { - value = Integer.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.IntegerPropertyEditor_notValidInt, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LocalePropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LocalePropertyEditor.java deleted file mode 100644 index 9a6563d..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LocalePropertyEditor.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.model.property.Property; - -import java.util.Locale; - -/** - * {@link PropertyEditor} for {@link Locale}. - * - * @author sablin_aa - * @coverage core.model.property.editor - */ -public final class LocalePropertyEditor extends TextDialogPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new LocalePropertyEditor(); - - private LocalePropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Locale) { - return ((Locale) value).getDisplayName(); - } - // unknown value - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void openDialog(Property property) throws Exception { - Object value = property.getValue(); -// ChooseLocaleDialog localeDialog; -// if (value instanceof Locale) { -// localeDialog = new ChooseLocaleDialog(DesignerPlugin.getShell(), (Locale) value); -// } else { -// localeDialog = new ChooseLocaleDialog(DesignerPlugin.getShell(), null); -// } -// // open dialog -// if (localeDialog.open() == Window.OK) { -// property.setValue(localeDialog.getSelectedLocale().getLocale()); -// } - System.out.println("TODO: Custom locale chooser here"); - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongObjectPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongObjectPropertyEditor.java deleted file mode 100644 index 7a74ded..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongObjectPropertyEditor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for {@link Long}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class LongObjectPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final LongObjectPropertyEditor INSTANCE = new LongObjectPropertyEditor(); - - private LongObjectPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value == null) { - return "null"; - } - if (value instanceof Long) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // check for "null" - if (text.equals("null")) { - property.setValue(null); - return true; - } - // prepare value - Long value; - try { - value = Long.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.LongObjectPropertyEditor_notValidLong, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongPropertyEditor.java deleted file mode 100644 index 8c17f83..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/LongPropertyEditor.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for <code>long</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class LongPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new LongPropertyEditor(); - - private LongPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Long) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - } - // prepare value - Long value; - try { - value = Long.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.LongPropertyEditor_notValidLong, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyDescriptorEditorProvider.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyDescriptorEditorProvider.java deleted file mode 100644 index a60b698..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyDescriptorEditorProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import java.beans.PropertyDescriptor; - -/** - * {@link PropertyEditorProvider} that creates editors based on {@link PropertyDescriptor} - * attributes, such as "enumerationValues". - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class PropertyDescriptorEditorProvider extends PropertyEditorProvider { - //////////////////////////////////////////////////////////////////////////// - // - // PropertyEditorProvider - // - //////////////////////////////////////////////////////////////////////////// - @Override - public PropertyEditor getEditorForPropertyDescriptor(PropertyDescriptor descriptor) - throws Exception { - { - Object attributeValue = descriptor.getValue("enumerationValues"); - if (isEnumerationProperty(descriptor)) { - return new EnumerationValuesPropertyEditor(attributeValue); - } - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Utils - // - //////////////////////////////////////////////////////////////////////////// - /** - * @return <code>true</code> if given {@link PropertyDescriptor} has attribute "enumerationValues" - * with valid value structure. - */ - private static boolean isEnumerationProperty(PropertyDescriptor descriptor) { - Object attributeValue = descriptor.getValue("enumerationValues"); - // should be Object[] - if (!(attributeValue instanceof Object[])) { - return false; - } - Object[] enumElements = (Object[]) attributeValue; - // should be multiple 3 - if (enumElements.length % 3 != 0) { - return false; - } - // elements should be sequence of [String,Object,String] - for (int i = 0; i < enumElements.length; i++) { - Object element = enumElements[i]; - if (i % 3 == 0 && !(element instanceof String)) { - return false; - } - if (i % 3 == 2 && !(element instanceof String)) { - return false; - } - } - // OK - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditor.java deleted file mode 100644 index fd2fa8f..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditor.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -/** - * Abstract editor for {@link Property}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class PropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - /** - * @return the instance of {@link PropertyEditorPresentation}. - */ - public PropertyEditorPresentation getPresentation() { - return null; - } - - /** - * Paints given {@link Property} given rectangle <code>(x, y, width, height)</code> of {@link GC}. - */ - public abstract void paint(Property property, GC gc, int x, int y, int width, int height) - throws Exception; - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - /** - * Activates editor for given {@link Property} at given place of {@link Composite}. Activation - * happens when user selects property in {@link PropertyTable}. {@link PropertyEditor} should - * create here any {@link Control}'s required to edit {@link Property}. - * - * If any exception happens, {@link PropertyEditor} will be deactivated. - * - * @param location - * the mouse location, if editor is activated using mouse click, or <code>null</code> if - * it is activated using keyboard. - * - * @return <code>true</code> if editor should be remembered as active for future - * {@link #setBounds(Rectangle)} and {@link #deactivate(boolean)} invocation. Some editors - * need such local activation (for example for String), some - not (for boolean). - */ - public boolean activate(PropertyTable propertyTable, Property property, Point location) - throws Exception { - return false; - } - - /** - * Sets the new bounds for editor's control. - */ - public void setBounds(Rectangle bounds) { - } - - /** - * Deactivates editor for current {@link Property}. {@link PropertyEditor} should dispose any - * {@link Control}'s created before in {@link #activate(PropertyTable, Property, Point)}. - * - * If any exception happened during activation, editor still should be able to deactivate - * correctly. - * - * @param save - * is <code>true</code> if property should save value to {@link Property}. - */ - public void deactivate(PropertyTable propertyTable, Property property, boolean save) { - } - - /** - * Handles double click on {@link Property} value in {@link PropertyTable}. - * - * @param location - * the mouse location, relative to editor - */ - public void doubleClick(Property property, Point location) throws Exception { - } - - /** - * Handles {@link SWT#KeyDown} event in {@link PropertyTable}. - */ - public void keyDown(PropertyTable propertyTable, Property property, KeyEvent event) - throws Exception { - } - - //////////////////////////////////////////////////////////////////////////// - // - // IAdaptable - // - //////////////////////////////////////////////////////////////////////////// - public <T> T getAdapter(Class<T> adapter) { - return null; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditorProvider.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditorProvider.java deleted file mode 100644 index 2d11cbc..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/PropertyEditorProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import java.beans.PropertyDescriptor; - -/** - * Provider for creating {@link PropertyEditor}'s. - * - * @author lobas_av - * @coverage core.model.property.editor - */ -public class PropertyEditorProvider { - /** - * @return the {@link PropertyEditor} for given property type or <code>null</code>. - */ - public PropertyEditor getEditorForType(Class<?> propertyType) throws Exception { - return null; - } - - /** - * @return the {@link PropertyEditor} for given {@link java.beans.PropertyEditor} editor type or - * <code>null</code>. - */ - public PropertyEditor getEditorForEditorType(Class<?> editorType) throws Exception { - return null; - } - - /** - * @return the {@link PropertyEditor} for given {@link PropertyDescriptor} or <code>null</code>. - */ - public PropertyEditor getEditorForPropertyDescriptor(PropertyDescriptor descriptor) - throws Exception { - return null; - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortObjectPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortObjectPropertyEditor.java deleted file mode 100644 index c1f8383..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortObjectPropertyEditor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for {@link Short}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class ShortObjectPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final ShortObjectPropertyEditor INSTANCE = new ShortObjectPropertyEditor(); - - private ShortObjectPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value == null) { - return "null"; - } - if (value instanceof Short) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - return true; - } - // check for "null" - if (text.equals("null")) { - property.setValue(null); - return true; - } - // prepare value - Short value; - try { - value = Short.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.ShortObjectPropertyEditor_notValidShort, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortPropertyEditor.java deleted file mode 100644 index dba61c9..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/ShortPropertyEditor.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.UiUtils; - -import java.text.MessageFormat; - -/** - * The {@link PropertyEditor} for <code>short</code>. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class ShortPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new ShortPropertyEditor(); - - private ShortPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof Short) { - return value.toString(); - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - text = text.trim(); - // check for delete - if (text.length() == 0) { - property.setValue(Property.UNKNOWN_VALUE); - } - // prepare value - Short value; - try { - value = Short.valueOf(text); - } catch (Throwable e) { - UiUtils.openWarning( - DesignerPlugin.getShell(), - property.getTitle(), - MessageFormat.format(ModelMessages.ShortPropertyEditor_notValidShort, text)); - return false; - } - // modify property - property.setValue(value); - return true; - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringArrayPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringArrayPropertyEditor.java deleted file mode 100644 index fd78e01..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringArrayPropertyEditor.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import com.google.common.base.Joiner; - -import org.eclipse.jface.window.Window; -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.ui.dialogs.StringsDialog; - -/** - * {@link PropertyEditor} for array of {@link String}'s. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public final class StringArrayPropertyEditor extends TextDialogPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new StringArrayPropertyEditor(); - - private StringArrayPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getText(Property property) throws Exception { - String[] items = getItems(property); - return "[" + Joiner.on(", ").join(items) + "]"; - } - - /** - * @return the items specified in value of given {@link Property}. - */ - private static String[] getItems(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof String[]) { - return (String[]) value; - } - // no items - return new String[0]; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void openDialog(Property property) throws Exception { - StringsDialog itemsDialog = - new StringsDialog(DesignerPlugin.getShell(), - DesignerPlugin.getDefault(), - property.getTitle(), - ModelMessages.StringArrayPropertyEditor_itemsLabel, - ModelMessages.StringArrayPropertyEditor_hint); - itemsDialog.setItems(getItems(property)); - // open dialog - if (itemsDialog.open() == Window.OK) { - property.setValue(itemsDialog.getItems()); - } - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringComboPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringComboPropertyEditor.java deleted file mode 100644 index 1861475..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringComboPropertyEditor.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.internal.core.model.property.Property; - -/** - * The {@link PropertyEditor} for selecting single {@link String} value from given array. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class StringComboPropertyEditor extends AbstractComboPropertyEditor { - private final String[] m_items; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public StringComboPropertyEditor(String... items) { - m_items = items; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getText(Property property) throws Exception { - return (String) property.getValue(); - } - - //////////////////////////////////////////////////////////////////////////// - // - // AbstractComboPropertyEditor - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void addItems(Property property, CCombo3 combo) throws Exception { - for (String item : m_items) { - combo.add(item); - } - } - - @Override - protected void selectItem(Property property, CCombo3 combo) throws Exception { - combo.setText(getText(property)); - } - - @Override - protected void toPropertyEx(Property property, CCombo3 combo, int index) throws Exception { - property.setValue(m_items[index]); - } -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringListPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringListPropertyEditor.java deleted file mode 100644 index 1bb8cd8..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/StringListPropertyEditor.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.core.controls.CCombo3; -import org.eclipse.wb.internal.core.model.property.Property; - -/** - * The {@link PropertyEditor} for selecting single string from given set. - * - * @author sablin_aa - * @coverage core.model.property.editor - */ -public final class StringListPropertyEditor extends AbstractListPropertyEditor { - private boolean m_ignoreCase; - private String[] m_strings; - - //////////////////////////////////////////////////////////////////////////// - // - // Combo - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void toPropertyEx_simpleProperty(Property property, CCombo3 combo, int index) - throws Exception { - property.setValue(m_strings[index]); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Access to list items - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected int getCount() { - return m_strings.length; - } - - @Override - protected int getValueIndex(Object value) { - if (value instanceof String) { - String string = (String) value; - for (int i = 0; i < getCount(); i++) { - if (m_ignoreCase) { - if (string.equalsIgnoreCase(m_strings[i])) { - return i; - } - } else { - if (string.equals(m_strings[i])) { - return i; - } - } - } - } - return -1; - } - - @Override - protected String getTitle(int index) { - return m_strings[index]; - } - - @Override - protected String getExpression(int index) throws Exception { - //return StringConverter.INSTANCE.toJavaSource(null, m_strings[index]); - // HACK!! - System.out.println("HACK!"); - return m_strings[index]; - } -// -// //////////////////////////////////////////////////////////////////////////// -// // -// // IConfigurablePropertyObject -// // -// //////////////////////////////////////////////////////////////////////////// -// public void configure(EditorState state, Map<String, Object> parameters) throws Exception { -// m_strings = getParameterAsArray(parameters, "strings"); -// m_ignoreCase = "true".equals(parameters.get("ignoreCase")); -// } -// -// /** -// * Configures this editor externally. -// */ -// public void configure(String[] strings) { -// m_strings = strings; -// } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextControlActionsManager.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextControlActionsManager.java deleted file mode 100644 index dc7ba74..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextControlActionsManager.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.utils.binding.editors.controls.DefaultControlActionsManager; - -import org.eclipse.swt.widgets.Text; - -/** - * Manager for installing/unistalling global handlers for {@link Text} actions commands. - * - * @author mitin_aa - * @author sablin_aa - * @coverage core.model.property.editor - */ -public final class TextControlActionsManager extends DefaultControlActionsManager { - private final Text m_text; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public TextControlActionsManager(final Text text) { - super(text); - m_text = text; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Handlers - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void selectAllExecuted() { - m_text.selectAll(); - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDialogPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDialogPropertyEditor.java deleted file mode 100644 index 885d4ef..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDialogPropertyEditor.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.editor.presentation.ButtonPropertyEditorPresentation; -import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import org.eclipse.swt.graphics.Point; - -/** - * Abstract {@link PropertyEditor} that displays text and button to open dialog. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class TextDialogPropertyEditor extends TextDisplayPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - private final PropertyEditorPresentation m_presentation = new ButtonPropertyEditorPresentation() { - @Override - protected void onClick(PropertyTable propertyTable, Property property) throws Exception { - openDialog(property); - } - }; - - @Override - public final PropertyEditorPresentation getPresentation() { - return m_presentation; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - public boolean activate(PropertyTable propertyTable, Property property, Point location) - throws Exception { - // activate using keyboard - if (location == null) { - openDialog(property); - } - // don't activate - return false; - } - - /** - * Opens editing dialog. - */ - protected abstract void openDialog(Property property) throws Exception; -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDisplayPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDisplayPropertyEditor.java deleted file mode 100644 index 9cf3703..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/TextDisplayPropertyEditor.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor; - -import org.eclipse.swt.graphics.GC; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; -import org.eclipse.wb.internal.core.model.property.table.PropertyTooltipProvider; -import org.eclipse.wb.internal.core.utils.ui.DrawUtils; - -/** - * Abstract {@link PropertyEditor} for displaying text as {@link Property} value in - * {@link PropertyTable}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class TextDisplayPropertyEditor extends PropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception { - String text = getText(property); - if (text != null) { - DrawUtils.drawStringCV(gc, text, x, y, width, height); - } - } - - /** - * @return the text for displaying value of given {@link Property} or <code>null</code> if value - * of {@link Property} is unknown. - */ - protected abstract String getText(Property property) throws Exception; - - //////////////////////////////////////////////////////////////////////////// - // - // IAdaptable - // - //////////////////////////////////////////////////////////////////////////// - @Override - public <T> T getAdapter(Class<T> adapter) { - // tooltip for value text - if (adapter == PropertyTooltipProvider.class) { - return adapter.cast(createPropertyTooltipProvider()); - } - return super.getAdapter(adapter); - } - - /** - * @return the {@link PropertyTooltipProvider} to display value tooltip. - */ - protected PropertyTooltipProvider createPropertyTooltipProvider() { - return null; - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/complex/IComplexPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/complex/IComplexPropertyEditor.java deleted file mode 100644 index 0634cfe..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/complex/IComplexPropertyEditor.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.complex; - -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.editor.PropertyEditor; - -/** - * Extension for {@link PropertyEditor} that specifies that it has sub-properties. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public interface IComplexPropertyEditor { - /** - * @return sub-properties of given complex property. - */ - Property[] getProperties(Property property) throws Exception; -}
\ No newline at end of file diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentation.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentation.java deleted file mode 100644 index e33970d..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentation.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.presentation; - -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.EnvironmentUtils; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Button; - -/** - * Implementation of {@link PropertyEditorPresentation} for displaying {@link Button}. - * - * @author scheglov_ke - * @author mitin_aa - * @coverage core.model.property.editor - */ -public abstract class ButtonPropertyEditorPresentation extends PropertyEditorPresentation { - private final int m_style; - private final ButtonPropertyEditorPresentationImpl m_impl; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructors - // - //////////////////////////////////////////////////////////////////////////// - public ButtonPropertyEditorPresentation() { - this(SWT.NONE); - } - - public ButtonPropertyEditorPresentation(int style) { - m_style = style; - m_impl = - EnvironmentUtils.IS_MAC - ? new ButtonPropertyEditorPresentationImplMac(this) - : new ButtonPropertyEditorPresentationImpl(this); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Access - // - //////////////////////////////////////////////////////////////////////////// - /** - * Sets "selection" property of {@link Button}. - */ - public final void setSelection(PropertyTable propertyTable, Property property, boolean selected) { - m_impl.setSelection(propertyTable, property, selected); - } - - //////////////////////////////////////////////////////////////////////////// - // - // PropertyEditorPresentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public final int show(final PropertyTable propertyTable, - final Property property, - final int x, - final int y, - final int width, - final int height) { - return m_impl.show(propertyTable, property, x, y, width, height); - } - - @Override - public final void hide(PropertyTable propertyTable, Property property) { - m_impl.hide(propertyTable, property); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Access - // - //////////////////////////////////////////////////////////////////////////// - final int getStyle() { - return m_style; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Implementation - // - //////////////////////////////////////////////////////////////////////////// - /** - * @return the {@link Image} to display on {@link Button}. - */ - protected Image getImage() { - return DesignerPlugin.getImage("properties/dots.gif"); - } - - /** - * @return the tooltip text to display for {@link Button}. - */ - protected String getTooltip() { - return null; - } - - /** - * Handles click on {@link Button}. - */ - protected abstract void onClick(PropertyTable propertyTable, Property property) throws Exception; -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImpl.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImpl.java deleted file mode 100644 index 209bf39..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImpl.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.presentation; - -import com.google.common.collect.Maps; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; -import org.eclipse.wb.internal.core.utils.Pair; - -import java.util.Map; - -/** - * Internal implementation of {@link PropertyEditorPresentation} for displaying {@link Button}. - * - * @author scheglov_ke - * @author mitin_aa - * @coverage core.model.property.editor - */ -class ButtonPropertyEditorPresentationImpl extends PropertyEditorPresentation { - protected final PropertyToControlMap m_propertyToControl = new PropertyToControlMap(); - private final ButtonPropertyEditorPresentation m_presentation; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public ButtonPropertyEditorPresentationImpl(ButtonPropertyEditorPresentation presentation) { - m_presentation = presentation; - } - - //////////////////////////////////////////////////////////////////////////// - // - // PropertyEditorPresentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public final void hide(PropertyTable propertyTable, Property property) { - Control control = m_propertyToControl.remove(propertyTable, property); - if (control != null) { - control.dispose(); - } - } - - @Override - public final int show(PropertyTable propertyTable, - Property property, - int x, - int y, - int width, - int height) { - // prepare control - Control control = m_propertyToControl.get(propertyTable, property); - if (control == null) { - control = createControl(propertyTable, property); - } - // set bounds - final int controlWidth = height; - final int controlX = x + width - controlWidth; - setBounds(control, controlX, y, controlWidth, height); - return controlWidth; - } - - /** - * Finds and select the appropriate {@link Control} belonging to given property. - */ - public void setSelection(PropertyTable propertyTable, Property property, boolean selected) { - Button button = (Button) m_propertyToControl.get(propertyTable, property); - if (button != null) { - button.setSelection(selected); - } - } - - //////////////////////////////////////////////////////////////////////////// - // - // Control - // - //////////////////////////////////////////////////////////////////////////// - /** - * Creates the control for given property and initializes newly created control. - */ - private Control createControl(final PropertyTable propertyTable, final Property property) { - Control control = createControlImpl(propertyTable, property); - m_propertyToControl.put(propertyTable, property, control); - // when Control disposed, remove Control/Property from map to avoid memory leak - control.addListener(SWT.Dispose, new Listener() { - @Override - public void handleEvent(Event e) { - m_propertyToControl.remove(propertyTable, property); - } - }); - // activate property on mouse down - control.addListener(SWT.MouseDown, new Listener() { - @Override - public void handleEvent(Event event) { - propertyTable.deactivateEditor(true); - propertyTable.setActiveProperty(property); - } - }); - // return focus on propertyTable after click - control.addListener(SWT.MouseUp, new Listener() { - @Override - public void handleEvent(Event event) { - propertyTable.forceFocus(); - } - }); - // handle selection - control.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - try { - getPresentation().onClick(propertyTable, property); - } catch (Throwable e) { - propertyTable.deactivateEditor(false); - propertyTable.handleException(e); - } - } - }); - return control; - } - - /** - * Creates the {@link Control} instance. By default, {@link Button} instance created. - */ - protected Control createControlImpl(final PropertyTable propertyTable, final Property property) { - Button button = new Button(propertyTable, getPresentation().getStyle()); - button.setImage(getPresentation().getImage()); - button.setToolTipText(getPresentation().getTooltip()); - return button; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Access - // - //////////////////////////////////////////////////////////////////////////// - /** - * @return the 'parent' presentation. Internal usage only. - */ - protected final ButtonPropertyEditorPresentation getPresentation() { - return m_presentation; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Utils - // - //////////////////////////////////////////////////////////////////////////// - /** - * Sets new bounds for {@link Control}, optimizing when possible. - */ - private static void setBounds(Control control, int newX, int newY, int newWidth, int newHeight) { - // check, may be Control is invisible, so no reason to change bounds - { - // is in negative zone - if (newY + newHeight < 0) { - control.setVisible(false); - return; - } - // is out of client area height - Rectangle parentArea = control.getParent().getClientArea(); - if (newY > parentArea.height) { - control.setVisible(false); - return; - } - } - // well, now we sure that Control is visible - if (!control.getVisible()) { - control.setVisible(true); - } - // prepare old size, remember new - Integer oldWidthObject = (Integer) control.getData("oldWidth"); - Integer oldHeightObject = (Integer) control.getData("oldHeight"); - control.setData("oldWidth", newWidth); - control.setData("oldHeight", newHeight); - // check, may be same size - if (oldWidthObject != null) { - int oldWidth = oldWidthObject.intValue(); - int oldHeight = oldHeightObject.intValue(); - if (oldWidth == newWidth && oldHeight == newHeight) { - control.setLocation(newX, newY); - return; - } - } - // no any optimization possible, just set bounds - control.setBounds(newX, newY, newWidth, newHeight); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Controls map - // - //////////////////////////////////////////////////////////////////////////// - protected static final class PropertyToControlMap { - private final Map<Pair<PropertyTable, Property>, Control> m_map = Maps.newHashMap(); - - void put(PropertyTable propertyTable, Property property, Control control) { - m_map.put(Pair.create(propertyTable, property), control); - } - - Control remove(PropertyTable propertyTable, Property property) { - return m_map.remove(Pair.create(propertyTable, property)); - } - - Control get(PropertyTable propertyTable, Property property) { - return m_map.get(Pair.create(propertyTable, property)); - } - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImplMac.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImplMac.java deleted file mode 100644 index d61a606..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/ButtonPropertyEditorPresentationImplMac.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.presentation; - -import org.eclipse.wb.core.controls.CFlatButton; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Control; - -/** - * Internal implementation of {@link PropertyEditorPresentation} for displaying special owner-draw - * button for Mac OSX. - * - * @author mitin_aa - * @coverage core.model.property.editor - */ -final class ButtonPropertyEditorPresentationImplMac extends ButtonPropertyEditorPresentationImpl { - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public ButtonPropertyEditorPresentationImplMac(ButtonPropertyEditorPresentation presentation) { - super(presentation); - } - - //////////////////////////////////////////////////////////////////////////// - // - // Control - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected final Control createControlImpl(final PropertyTable propertyTable, Property property) { - CFlatButton button = new CFlatButton(propertyTable, SWT.NONE); - button.setImage(getPresentation().getImage()); - button.setToolTipText(getPresentation().getTooltip()); - return button; - } - - @Override - public final void setSelection(PropertyTable propertyTable, Property property, boolean selected) { - CFlatButton button = (CFlatButton) m_propertyToControl.get(propertyTable, property); - if (button != null) { - button.setSelected(selected); - } - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/CompoundPropertyEditorPresentation.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/CompoundPropertyEditorPresentation.java deleted file mode 100644 index 39bfa7a..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/CompoundPropertyEditorPresentation.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.presentation; - -import com.google.common.collect.Lists; - -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import java.util.List; - -/** - * Implementation of {@link PropertyEditorPresentation} that contains zero or more other - * {@link PropertyEditorPresentation}'s. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class CompoundPropertyEditorPresentation extends PropertyEditorPresentation { - private final List<PropertyEditorPresentation> m_presentations = Lists.newArrayList(); - - //////////////////////////////////////////////////////////////////////////// - // - // Access - // - //////////////////////////////////////////////////////////////////////////// - /** - * Adds child {@link PropertyEditorPresentation}.<br> - * Child {@link PropertyEditorPresentation}'s are displayed from right to left. - */ - public void add(PropertyEditorPresentation presentation) { - m_presentations.add(presentation); - } - - //////////////////////////////////////////////////////////////////////////// - // - // PropertyEditorPresentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public int show(PropertyTable propertyTable, - Property property, - int x, - int y, - int width, - int height) { - int sumWidth = 0; - for (PropertyEditorPresentation presentation : m_presentations) { - int presentationWidth = presentation.show(propertyTable, property, x, y, width, height); - sumWidth += presentationWidth; - width -= presentationWidth; - } - return sumWidth; - } - - @Override - public void hide(PropertyTable propertyTable, Property property) { - for (PropertyEditorPresentation presentation : m_presentations) { - presentation.hide(propertyTable, property); - } - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/PropertyEditorPresentation.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/PropertyEditorPresentation.java deleted file mode 100644 index 843338e..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/presentation/PropertyEditorPresentation.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.presentation; - -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.editor.PropertyEditor; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -/** - * Implementations of {@link PropertyEditorPresentation} are used to show some presentation for - * visible, but not activated yet {@link PropertyEditor}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public abstract class PropertyEditorPresentation { - /** - * Shows presentation for given {@link Property}. - * - * @return the width that this presentation occupies on the right of given rectangle. - */ - public abstract int show(PropertyTable propertyTable, - Property property, - int x, - int y, - int width, - int height); - - /** - * Hides presentation. - */ - public abstract void hide(PropertyTable propertyTable, Property property); -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyDialog.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyDialog.java deleted file mode 100644 index 2b0d47e..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyDialog.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.string; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wb.internal.core.DesignerPlugin; -import org.eclipse.wb.internal.core.model.ModelMessages; -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils; -import org.eclipse.wb.internal.core.utils.execution.RunnableEx; -import org.eclipse.wb.internal.core.utils.ui.GridDataFactory; -import org.eclipse.wb.internal.core.utils.ui.dialogs.ResizableDialog; - -/** - * {@link Dialog} for editing value in {@link StringPropertyEditor}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class StringPropertyDialog extends ResizableDialog { - // NOTE: In WindowBuilder this class had a lot of support for - // editing Java strings, dealing with automatic localization - // etc. This will need to be done differently in ADT (and had hooks - // into a bunch of other parts of WindowBuilder we're not including) - // so this was all stripped down to a plain String editor. - - //////////////////////////////////////////////////////////////////////////// - // - // Final fields - // - //////////////////////////////////////////////////////////////////////////// - private final Property m_property; - - //////////////////////////////////////////////////////////////////////////// - // - // Constructor - // - //////////////////////////////////////////////////////////////////////////// - public StringPropertyDialog(Shell parentShell, Property property) throws Exception { - super(parentShell, DesignerPlugin.getDefault()); - m_property = property; - } - - //////////////////////////////////////////////////////////////////////////// - // - // GUI - // - //////////////////////////////////////////////////////////////////////////// - private Text m_valueText; - - @Override - public void create() { - super.create(); - m_valueText.selectAll(); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite area = (Composite) super.createDialogArea(parent); - // value - { - // BEGIN ADT MODIFICATIONS - if (isMultiLine()) { - // END ADT MODIFICATIONS - m_valueText = new Text(area, SWT.BORDER | SWT.MULTI | SWT.WRAP); - GridDataFactory.create(m_valueText).grab().hintC(80, 8).fill(); - // BEGIN ADT MODIFICATIONS - } else { - m_valueText = new Text(area, SWT.BORDER | SWT.SINGLE); - GridDataFactory.create(m_valueText).grab().hintC(50, 1).fill(); - } - // END ADT MODIFICATIONS - // initial value - ExecutionUtils.runLog(new RunnableEx() { - @Override - public void run() throws Exception { - Object value = m_property.getValue(); - if (value instanceof String) { - m_valueText.setText((String) value); - } - } - }); - // handle Ctrl+Enter as OK - m_valueText.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.stateMask == SWT.CTRL && e.keyCode == SWT.CR) { - okPressed(); - } - } - }); - } - - return area; - } - - // BEGIN ADT MODIFICATIONS - protected boolean isMultiLine() { - return true; - } - // END ADT MODIFICATIONS - - //////////////////////////////////////////////////////////////////////////// - // - // Shell - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(ModelMessages.StringPropertyDialog_title); - } - - @Override - protected void okPressed() { - final String value = m_valueText.getText(); - ExecutionUtils.runLog(new RunnableEx() { - @Override - public void run() throws Exception { - m_property.setValue(value); - } - }); - // close dialog - super.okPressed(); - } -} diff --git a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyEditor.java b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyEditor.java deleted file mode 100644 index 0202fe5..0000000 --- a/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyEditor.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Google, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Google, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.wb.internal.core.model.property.editor.string; - -import org.eclipse.wb.internal.core.model.property.Property; -import org.eclipse.wb.internal.core.model.property.editor.AbstractTextPropertyEditor; -import org.eclipse.wb.internal.core.model.property.editor.PropertyEditor; -import org.eclipse.wb.internal.core.model.property.editor.presentation.ButtonPropertyEditorPresentation; -import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation; -import org.eclipse.wb.internal.core.model.property.table.PropertyTable; - -import org.eclipse.jface.window.Window; - -/** - * The {@link PropertyEditor} for {@link String}. - * - * @author scheglov_ke - * @coverage core.model.property.editor - */ -public class StringPropertyEditor extends AbstractTextPropertyEditor { - //////////////////////////////////////////////////////////////////////////// - // - // Instance - // - //////////////////////////////////////////////////////////////////////////// - public static final PropertyEditor INSTANCE = new StringPropertyEditor(); - - private StringPropertyEditor() { - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - private final PropertyEditorPresentation m_presentation = new ButtonPropertyEditorPresentation() { - @Override - protected void onClick(PropertyTable propertyTable, Property property) throws Exception { - openDialog(propertyTable, property); - } - }; - - @Override - public PropertyEditorPresentation getPresentation() { - return m_presentation; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Presentation - // - //////////////////////////////////////////////////////////////////////////// - @Override - public String getText(Property property) throws Exception { - Object value = property.getValue(); - if (value instanceof String) { - return (String) value; - } - return null; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing - // - //////////////////////////////////////////////////////////////////////////// - @Override - protected String getEditorText(Property property) throws Exception { - return getText(property); - } - - @Override - protected boolean setEditorText(Property property, String text) throws Exception { - property.setValue(text); - return true; - } - - //////////////////////////////////////////////////////////////////////////// - // - // Editing in dialog - // - //////////////////////////////////////////////////////////////////////////// - /** - * Opens editing dialog. - */ - private void openDialog(PropertyTable propertyTable, Property property) throws Exception { - StringPropertyDialog dialog = new StringPropertyDialog(propertyTable.getShell(), property); - if (dialog.open() == Window.OK) { - } - } -} |