Author: dgeraskov
Date: 2010-12-10 08:29:43 -0500 (Fri, 10 Dec 2010)
New Revision: 27349
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/StringArrayDialogCellEditor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/StringListDialog.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties
Log:
https://issues.jboss.org/browse/JBIDE-7791
Query Parameters list value applied after focus lost
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java 2010-12-10
11:32:50 UTC (rev 27348)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.java 2010-12-10
13:29:43 UTC (rev 27349)
@@ -31,6 +31,13 @@
public static String AbstractConsoleConfigurationPreferences_unknown;
public static String
StandAloneConsoleConfigurationPreferences_could_not_resolve_classpaths;
public static String StandAloneConsoleConfigurationPreferences_errors_while_parsing;
+ public static String StringListDialog_Add;
+ public static String StringListDialog_Add_Element;
+ public static String StringListDialog_Elements;
+ public static String StringListDialog_Modify;
+ public static String StringListDialog_Modify_Element;
+ public static String StringListDialog_New_Element;
+ public static String StringListDialog_Remove;
public static String PluginFileAppender_missing_plugin_state_location;
public static String PluginLogAppender_missing_layout_for_appender;
static {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties 2010-12-10
11:32:50 UTC (rev 27348)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleMessages.properties 2010-12-10
13:29:43 UTC (rev 27349)
@@ -24,6 +24,13 @@
AbstractConsoleConfigurationPreferences_unknown=<unknown>
StandAloneConsoleConfigurationPreferences_could_not_resolve_classpaths=Could not resolve
classpaths
StandAloneConsoleConfigurationPreferences_errors_while_parsing=Errors while parsing
+StringListDialog_Add=Add
+StringListDialog_Add_Element=Add Element
+StringListDialog_Elements=Elements
+StringListDialog_Modify=Modify
+StringListDialog_Modify_Element=Modify Element
+StringListDialog_New_Element=New Element:
+StringListDialog_Remove=Remove
PluginFileAppender_missing_plugin_state_location=Missing Plugin State Location.
PluginLogAppender_missing_layout_for_appender=Missing layout for appender
ConsoleConfiguration_connection_profile_not_found=Connection profile not found:
''{0}''.
\ No newline at end of file
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/StringListDialog.java
(from rev 26997,
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ParametersListDialog.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/StringListDialog.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/StringListDialog.java 2010-12-10
13:29:43 UTC (rev 27349)
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.console;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class StringListDialog extends Dialog {
+
+ private ListViewer listViewer;
+
+ private String[] values;
+
+ /**
+ * @param parentShell
+ */
+ public StringListDialog(Shell parentShell, String[] initValue) {
+ super(parentShell);
+ values = initValue;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite container) {
+ Composite parent = (Composite) super.createDialogArea(container);
+ listViewer = new ListViewer(parent);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = convertHeightInCharsToPixels(15);
+ gd.widthHint = convertWidthInCharsToPixels(55);
+ org.eclipse.swt.widgets.List list = listViewer.getList();
+ list.setLayoutData(gd);
+ list.setFont(container.getFont());
+
+ if (values != null){
+ list.setItems(values);
+ }
+
+ if (list.getItemCount() > 0){
+ list.select(list.getItemCount() - 1);
+ }
+ addButtons(parent);
+ return parent;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(ConsoleMessages.StringListDialog_Elements);
+ }
+
+ private Button buttonAdd;
+ private Button buttonRemove;
+ private Button buttonModify;
+
+ private void addButtons(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
+ fillLayout.spacing = 2;
+
+ composite.setLayout(fillLayout);
+
+ buttonAdd = new Button(composite, SWT.PUSH);
+ buttonAdd.setText(ConsoleMessages.StringListDialog_Add);
+
+ buttonModify = new Button(composite, SWT.PUSH);
+ buttonModify.setText(ConsoleMessages.StringListDialog_Modify);
+
+ buttonRemove = new Button(composite, SWT.PUSH);
+ buttonRemove.setText(ConsoleMessages.StringListDialog_Remove);
+
+ buttonAdd.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ InputDialog inputDialog = new InputDialog(null,
ConsoleMessages.StringListDialog_Add_Element,
+ ConsoleMessages.StringListDialog_New_Element, "", null); //$NON-NLS-1$
+ if (inputDialog.open() == Window.OK) {
+ listViewer.getList().add(inputDialog.getValue());
+ }
+ }
+ });
+
+ buttonModify.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int line = listViewer.getList().getSelectionIndex();
+ if (line >=0 ){
+ InputDialog inputDialog = new InputDialog(null,
ConsoleMessages.StringListDialog_Modify_Element,
+ ConsoleMessages.StringListDialog_New_Element, listViewer.getList().getItem(line),
null);
+ if (inputDialog.open() == Window.OK) {
+ listViewer.getList().setItem(line, inputDialog.getValue());
+ }
+ }
+
+
+ }
+ });
+
+ buttonRemove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ int line = listViewer.getList().getSelectionIndex();
+ if (line < 0) {
+ return;
+ } else {
+ listViewer.getList().remove(line);
+ }
+ }
+ });
+ }
+
+ @Override
+ protected void okPressed() {
+ values = listViewer.getList().getItems();
+ super.okPressed();
+ }
+
+ public String[] getValue() {
+ return values;
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java 2010-12-10
11:32:50 UTC (rev 27348)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java 2010-12-10
13:29:43 UTC (rev 27349)
@@ -64,8 +64,8 @@
import org.eclipse.ui.part.Page;
import org.hibernate.console.ConsoleQueryParameter;
import org.hibernate.console.ImageConstants;
-import org.hibernate.console.ParametersListDialog;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.StringListDialog;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.QueryEditor;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -271,10 +271,6 @@
}
if ( VALUE_PROPERTY.equals( property ) ) {
return cqp.getStringValues();
- /*if (cqp.isArrayValue()){
- return cqp.convertValueToString(((Object[])cqp.getValue())[0]);
- }
- return cqp.convertValueToString(cqp.getValue());*/
}
if ( NULL_PROPERTY.equals( property )) {
return Boolean.valueOf(cqp.isNull());
@@ -315,34 +311,20 @@
CellEditor[] editors = new CellEditor[columnProperties.length];
editors[0] = new TextCellEditor( queryParametersTable );
editors[1] = new ComboBoxCellEditor( queryParametersTable, valueTypes );
- editors[2] = new TextDialogCellEditor(queryParametersTable) {
+ editors[2] = new StringArrayDialogCellEditor(queryParametersTable) {
private Button b;
- @Override
- protected Object openDialogBox(Control cellEditorWindow) {
- Object firstElement =
((IStructuredSelection)tableViewer.getSelection()).getFirstElement();
- if(firstElement instanceof ConsoleQueryParameter) {
- ParametersListDialog pld = new ParametersListDialog(null, (ConsoleQueryParameter)
firstElement);
- if (pld.open()==Window.OK){
- return pld.getValue();//String[]
- }
- }
- return getValue();//could be String or String[]
- }
-
public void activate() {
- Object param = ((IStructuredSelection)tableViewer.getSelection()).getFirstElement();
- if(param instanceof ConsoleQueryParameter) {
+ Object param = ((IStructuredSelection)
tableViewer.getSelection()).getFirstElement();
+ if (param instanceof ConsoleQueryParameter) {
try {
Integer.parseInt(((ConsoleQueryParameter) param).getName());
- /*
- * "ordered" parameter doesn't allow list value
- * see also HQLQueryPage#setupParameters()
- */
+ // "ordered" parameter doesn't allow list value
+ // see also HQLQueryPage#setupParameters()
b.setVisible(false);
- } catch(NumberFormatException nfe) {
- /*"named" parameter allows parameter list value*/
+ } catch (NumberFormatException nfe) {
+ // "named" parameter allows parameter list value
b.setVisible(true);
}
}
Copied:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/StringArrayDialogCellEditor.java
(from rev 26997,
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/TextDialogCellEditor.java)
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/StringArrayDialogCellEditor.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/StringArrayDialogCellEditor.java 2010-12-10
13:29:43 UTC (rev 27349)
@@ -0,0 +1,250 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.views;
+
+import java.text.MessageFormat;
+
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.window.Window;
+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.ModifyEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Text;
+import org.hibernate.console.StringListDialog;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class StringArrayDialogCellEditor extends TextCellEditor {
+
+ private Text text;
+
+ /**
+ * The button.
+ */
+ private Button button;
+
+ /**
+ * The editor control.
+ */
+ private Composite editor;
+
+ private String[] strValues = null;
+
+ private FocusListener buttonFocusListener;
+
+ protected StringArrayDialogCellEditor(Composite parent) {
+ super(parent);
+ }
+
+ @Override
+ protected Control createControl(Composite parent) {
+ Font font = parent.getFont();
+ Color bg = parent.getBackground();
+
+ editor = new Composite(parent, getStyle());
+ editor.setFont(font);
+ editor.setBackground(bg);
+ editor.setLayout(new DialogCellLayout());
+
+ text = (Text) super.createControl(editor);
+ updateContents(strValues);
+
+ button = createButton(editor);
+ button.setFont(font);
+
+ button.addKeyListener(new KeyAdapter() {
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
+ */
+ public void keyReleased(KeyEvent e) {
+ if (e.character == '\u001b') { // Escape
+ fireCancelEditor();
+ }
+ }
+ });
+
+ button.addFocusListener(getButtonFocusListener());
+
+ button.addSelectionListener(new SelectionAdapter() {
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent event) {
+ // Remove the button's focus listener since it's guaranteed
+ // to lose focus when the dialog opens
+ button.removeFocusListener(getButtonFocusListener());
+
+ Object newValue = openDialogBox(editor);
+
+ // Re-add the listener once the dialog closes
+ button.addFocusListener(getButtonFocusListener());
+
+ if (newValue != null) {
+ boolean newValidState = isCorrect(newValue);
+ if (newValidState) {
+ markDirty();
+ doSetValue(newValue);
+ } else {
+ // try to insert the current value into the error message.
+ setErrorMessage(MessageFormat.format(getErrorMessage(),
+ new Object[] { newValue.toString() }));
+ }
+ fireApplyEditorValue();
+ }
+ }
+
+
+ });
+
+ setValueValid(true);
+
+ return editor;
+ }
+
+ @Override
+ protected void focusLost() {
+ if (isActivated()) {
+ if (button != null && !button.isDisposed() &&
!button.isFocusControl()) {
+ if (text != null && !text.isDisposed() &&
!text.isFocusControl()){
+ fireApplyEditorValue();
+ deactivate();
+ }
+ }
+ }
+ }
+
+ protected Object openDialogBox(Control cellEditorWindow) {
+ String[] value = (String[]) getValue();
+ StringListDialog pld = new StringListDialog(null, value);
+ if (pld.open()==Window.OK){
+ return pld.getValue();//String[]
+ }
+ return null;
+ }
+
+ private FocusListener getButtonFocusListener() {
+ if (buttonFocusListener == null) {
+ buttonFocusListener = new FocusListener() {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
+ */
+ public void focusGained(FocusEvent e) {
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
+ */
+ public void focusLost(FocusEvent e) {
+ StringArrayDialogCellEditor.this.focusLost();
+ }
+ };
+ }
+
+ return buttonFocusListener;
+ }
+
+ protected Button createButton(Composite parent) {
+ Button result = new Button(parent, SWT.DOWN);
+ result.setText("..."); //$NON-NLS-1$
+ return result;
+ }
+
+ public void deactivate() {
+ if (button != null && !button.isDisposed()) {
+ button.removeFocusListener(getButtonFocusListener());
+ }
+
+ super.deactivate();
+ }
+
+ @Override
+ protected void editOccured(ModifyEvent e) {
+ String text = this.text.getText();
+ if (strValues == null || strValues.length == 0){
+ strValues = new String[]{text};
+ } else {
+ strValues[0] = text;
+ }
+ super.editOccured(e);
+ }
+
+ protected Object doGetValue() {
+ return strValues;
+ }
+
+ protected void doSetValue(Object value) {
+ if (value == null) {
+ this.strValues = new String[]{""}; //$NON-NLS-1$
+ } else if (value.getClass().isArray()){
+ this.strValues = (String[])value;
+ }
+ super.doSetValue(strValues.length > 0 ? strValues[0] : "");
//$NON-NLS-1$
+ }
+
+ protected void updateContents(String[] value) {
+ if (text == null) {
+ return;
+ }
+
+ String strVal = "";//$NON-NLS-1$
+ if (value != null && value.length > 0) {
+ strVal = value[0];
+ }
+ text.setText(strVal);
+ }
+
+ private class DialogCellLayout extends Layout {
+ public void layout(Composite editor, boolean force) {
+ Rectangle bounds = editor.getClientArea();
+ Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, force);
+ if (text != null) {
+ text.setBounds(0, 0, bounds.width - size.x, bounds.height);
+ }
+ button.setBounds(bounds.width - size.x, 0, size.x, bounds.height);
+ }
+
+ public Point computeSize(Composite editor, int wHint, int hHint,
+ boolean force) {
+ if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
+ return new Point(wHint, hHint);
+ }
+ Point contentsSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT,
+ force);
+ Point buttonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT,
+ force);
+ // Just return the button width to ensure the button is not clipped
+ // if the label is long.
+ // The label will just use whatever extra width there is
+ Point result = new Point(buttonSize.x, Math.max(contentsSize.y,
+ buttonSize.y));
+ return result;
+ }
+ }
+
+
+}
\ No newline at end of file