Author: dgeraskov
Date: 2010-12-10 08:30:16 -0500 (Fri, 10 Dec 2010)
New Revision: 27350
Removed:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/TextDialogCellEditor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ParametersListDialog.java
Log:
https://issues.jboss.org/browse/JBIDE-7791
Query Parameters list value applied after focus lost
Deleted:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ParametersListDialog.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ParametersListDialog.java 2010-12-10
13:29:43 UTC (rev 27349)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ParametersListDialog.java 2010-12-10
13:30:16 UTC (rev 27350)
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * 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 ParametersListDialog extends Dialog {
-
- private ListViewer listViewer;
-
- private ConsoleQueryParameter cqp;
-
- private String[] values;
-
- /**
- * @param parentShell
- */
- public ParametersListDialog(Shell parentShell, ConsoleQueryParameter cqp) {
- super(parentShell);
- this.cqp = cqp;
-
- }
-
- @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());
- /*List<String> input = new ArrayList<String>();
- Object value = cqp.getValue();
- if (value != null) {
- if (cqp.isArrayValue()) {
- Object[] values = (Object[]) value;
- for (Object object : values) {
- input.add(cqp.convertValueToString(object));
- }
- } else {
- input.add(cqp.convertValueToString(value));
- }
- }*/
- if (!cqp.isNull()){
- list.setItems(cqp.getStringValues());
- }
- if (list.getItemCount() > 0){
- list.select(list.getItemCount() - 1);
- }
- addButtons(parent);
- return parent;
- }
-
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText("Parameter Values"); //$NON-NLS-1$
- }
-
- 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("Add"); //$NON-NLS-1$
-
- buttonModify = new Button(composite, SWT.PUSH);
- buttonModify.setText("Modify"); //$NON-NLS-1$
-
- buttonRemove = new Button(composite, SWT.PUSH);
- buttonRemove.setText("Remove"); //$NON-NLS-1$
-
- buttonAdd.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- InputDialog inputDialog = new InputDialog(null, "Add Element",
//$NON-NLS-1$
- "New parameter: ", "", null); //$NON-NLS-1$ //$NON-NLS-2$
- 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, "Add Element",
//$NON-NLS-1$
- "New parameter: ", listViewer.getList().getItem(line), null);
//$NON-NLS-1$
- 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;
- }
-
-}
Deleted:
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/TextDialogCellEditor.java 2010-12-10
13:29:43 UTC (rev 27349)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/TextDialogCellEditor.java 2010-12-10
13:30:16 UTC (rev 27350)
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * 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.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;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public abstract class TextDialogCellEditor extends TextCellEditor {
-
- private Text text;
-
- /**
- * The button.
- */
- private Button button;
-
- /**
- * The editor control.
- */
- private Composite editor;
-
- private String[] strValues = null;
-
- private FocusListener buttonFocusListener;
-
- protected TextDialogCellEditor(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 abstract Object openDialogBox(Control cellEditorWindow);
-
- 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) {
- TextDialogCellEditor.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) {
- value = "";
- this.strValues = new String[]{""};
- } else if (value.getClass().isArray()){
- this.strValues = (String[])value;
- value = this.strValues[0];
- }
- super.doSetValue(value);
- }
-
- 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