diff options
Diffstat (limited to 'propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string')
2 files changed, 240 insertions, 0 deletions
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 new file mode 100644 index 0000000..2b0d47e --- /dev/null +++ b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyDialog.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * 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 new file mode 100644 index 0000000..0202fe5 --- /dev/null +++ b/propertysheet/src/org/eclipse/wb/internal/core/model/property/editor/string/StringPropertyEditor.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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) { + } + } +} |