Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryTextDialog.java')
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryTextDialog.java138
1 files changed, 138 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryTextDialog.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryTextDialog.java
new file mode 100644
index 0000000000..558e7ab402
--- /dev/null
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/widgets/HistoryTextDialog.java
@@ -0,0 +1,138 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.ui.widgets;
+
+import org.eclipse.net4j.util.collection.IHistory;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * TODO extend BaseDialog
+ *
+ * @author Eike Stepper
+ */
+public class HistoryTextDialog extends InputDialog
+{
+ private static final String EMPTY = "";
+
+ private IHistory<String> history;
+
+ private String value = EMPTY;
+
+ private HistoryText historyText;
+
+ public HistoryTextDialog(Shell parentShell, String dialogTitle, String dialogMessage, IHistory<String> history,
+ IInputValidator validator)
+ {
+ super(parentShell, dialogTitle, dialogMessage, history.getMostRecent(), validator);
+ this.history = history;
+ value = super.getValue();
+ }
+
+ public IHistory<String> getHistory()
+ {
+ return history;
+ }
+
+ public HistoryText getHistoryText()
+ {
+ return historyText;
+ }
+
+ @Override
+ public String getValue()
+ {
+ return value;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ Text text = getText();
+ text.setVisible(false);
+ text.setEnabled(false);
+
+ historyText = new HistoryText(composite, SWT.BORDER, history);
+ historyText.moveAbove(text);
+ historyText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+ historyText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ validateInput();
+ }
+ });
+
+ text.addFocusListener(new FocusAdapter()
+ {
+ @Override
+ public void focusGained(FocusEvent e)
+ {
+ historyText.setFocus();
+ }
+ });
+
+ composite.getShell().layout(true); // XXX
+ return composite;
+ }
+
+ @Override
+ protected void buttonPressed(int buttonId)
+ {
+ if (IDialogConstants.OK_ID == buttonId)
+ {
+ value = historyText.getText();
+ okPressed();
+ }
+ else if (IDialogConstants.CANCEL_ID == buttonId)
+ {
+ value = null;
+ cancelPressed();
+ }
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ super.createButtonsForButtonBar(parent);
+ historyText.setFocus();
+ if (value != null)
+ {
+ historyText.setText(value);
+ }
+ }
+
+ @Override
+ protected void validateInput()
+ {
+ String errorMessage = null;
+ if (getValidator() != null)
+ {
+ errorMessage = getValidator().isValid(historyText.getText());
+ }
+ // Bug 16256: important not to treat "" (blank error) the same as null
+ // (no error)
+ setErrorMessage(errorMessage);
+ }
+}

Back to the top