forked from eclipse/reddeer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Browse button for rd.config and screenshot dir. Fixes eclipse#1465
- Loading branch information
Showing
2 changed files
with
362 additions
and
40 deletions.
There are no files selected for viewing
290 changes: 290 additions & 0 deletions
290
plugins/org.jboss.reddeer.ui/src/org/jboss/reddeer/eclipse/ui/launcher/DialogTextEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 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 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package org.jboss.reddeer.eclipse.ui.launcher; | ||
|
||
import java.text.MessageFormat; | ||
|
||
import org.eclipse.core.runtime.Assert; | ||
import org.eclipse.jface.viewers.DialogCellEditor; | ||
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.ModifyEvent; | ||
import org.eclipse.swt.events.ModifyListener; | ||
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.widgets.Button; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.FileDialog; | ||
import org.eclipse.swt.widgets.Text; | ||
|
||
|
||
/** | ||
* Cell editor that combines functionality of DialogCellEditor and TextCellEditor | ||
* @author rawagner | ||
* | ||
*/ | ||
public class DialogTextEditor extends DialogCellEditor{ | ||
|
||
/** | ||
* State information for updating action enablement | ||
*/ | ||
private boolean isSelection = false; | ||
|
||
private boolean isDeleteable = false; | ||
|
||
private boolean isSelectable = false; | ||
|
||
private ModifyListener modifyListener; | ||
|
||
private Text text; | ||
|
||
public DialogTextEditor(Composite parent) { | ||
super(parent); | ||
} | ||
|
||
@Override | ||
protected Object openDialogBox(Control cellEditorWindow) { | ||
FileDialog dialog = new FileDialog(cellEditorWindow.getShell(), SWT.OPEN); | ||
return dialog.open(); | ||
} | ||
|
||
@Override | ||
protected Button createButton(Composite parent) { | ||
Button button = super.createButton(parent); | ||
button.setText("Browse..."); | ||
return button; | ||
} | ||
|
||
@Override | ||
protected Control createContents(Composite cell) { | ||
text = new Text(cell, getStyle()); | ||
text.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetDefaultSelected(SelectionEvent e) { | ||
handleDefaultSelection(e); | ||
} | ||
}); | ||
text.addKeyListener(new KeyAdapter() { | ||
// hook key pressed - see PR 14201 | ||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
keyReleaseOccured(e); | ||
|
||
// as a result of processing the above call, clients may have | ||
// disposed this cell editor | ||
if ((getControl() == null) || getControl().isDisposed()) { | ||
return; | ||
} | ||
checkSelection(); // see explanation below | ||
checkDeleteable(); | ||
checkSelectable(); | ||
} | ||
}); | ||
text.addTraverseListener(e -> { | ||
if (e.detail == SWT.TRAVERSE_ESCAPE | ||
|| e.detail == SWT.TRAVERSE_RETURN) { | ||
e.doit = false; | ||
} | ||
}); | ||
// We really want a selection listener but it is not supported so we | ||
// use a key listener and a mouse listener to know when selection changes | ||
// may have occurred | ||
text.addMouseListener(new MouseAdapter() { | ||
@Override | ||
public void mouseUp(MouseEvent e) { | ||
checkSelection(); | ||
checkDeleteable(); | ||
checkSelectable(); | ||
} | ||
}); | ||
text.addFocusListener(new FocusAdapter() { | ||
@Override | ||
public void focusLost(FocusEvent e) { | ||
doSetValue(text.getText()); | ||
} | ||
}); | ||
text.setFont(cell.getFont()); | ||
text.setBackground(cell.getBackground()); | ||
text.setText("");//$NON-NLS-1$ | ||
text.addModifyListener(getModifyListener()); | ||
return text; | ||
} | ||
|
||
@Override | ||
protected void doSetFocus() { | ||
if (text != null) { | ||
text.selectAll(); | ||
text.setFocus(); | ||
checkSelection(); | ||
checkDeleteable(); | ||
checkSelectable(); | ||
} | ||
} | ||
|
||
/** | ||
* Checks to see if the selection state (selection / | ||
* no selection) has changed and if so fire an | ||
* enablement changed notification. | ||
*/ | ||
private void checkSelection() { | ||
boolean oldIsSelection = isSelection; | ||
isSelection = text.getSelectionCount() > 0; | ||
if (oldIsSelection != isSelection) { | ||
fireEnablementChanged(COPY); | ||
fireEnablementChanged(CUT); | ||
} | ||
} | ||
|
||
/** | ||
* Checks to see if the "deletable" state (can delete/ | ||
* nothing to delete) has changed and if so fire an | ||
* enablement changed notification. | ||
*/ | ||
private void checkDeleteable() { | ||
boolean oldIsDeleteable = isDeleteable; | ||
isDeleteable = isDeleteEnabled(); | ||
if (oldIsDeleteable != isDeleteable) { | ||
fireEnablementChanged(DELETE); | ||
} | ||
} | ||
|
||
/** | ||
* Checks to see if the "selectable" state (can select) | ||
* has changed and if so fire an enablement changed notification. | ||
*/ | ||
private void checkSelectable() { | ||
boolean oldIsSelectable = isSelectable; | ||
isSelectable = isSelectAllEnabled(); | ||
if (oldIsSelectable != isSelectable) { | ||
fireEnablementChanged(SELECT_ALL); | ||
} | ||
} | ||
|
||
/** | ||
* Handles a default selection event from the text control by applying the editor | ||
* value and deactivating this cell editor. | ||
* | ||
* @param event the selection event | ||
* | ||
* @since 3.0 | ||
*/ | ||
protected void handleDefaultSelection(SelectionEvent event) { | ||
// same with enter-key handling code in keyReleaseOccured(e); | ||
fireApplyEditorValue(); | ||
deactivate(); | ||
} | ||
|
||
/** | ||
* Return the modify listener. | ||
*/ | ||
private ModifyListener getModifyListener() { | ||
if (modifyListener == null) { | ||
modifyListener = this::editOccured; | ||
} | ||
return modifyListener; | ||
} | ||
|
||
/** | ||
* Processes a modify event that occurred in this text cell editor. | ||
* This framework method performs validation and sets the error message | ||
* accordingly, and then reports a change via <code>fireEditorValueChanged</code>. | ||
* Subclasses should call this method at appropriate times. Subclasses | ||
* may extend or reimplement. | ||
* | ||
* @param e the SWT modify event | ||
*/ | ||
protected void editOccured(ModifyEvent e) { | ||
String value = text.getText(); | ||
if (value == null) { | ||
value = "";//$NON-NLS-1$ | ||
} | ||
Object typedValue = value; | ||
boolean oldValidState = isValueValid(); | ||
boolean newValidState = isCorrect(typedValue); | ||
if (!newValidState) { | ||
// try to insert the current value into the error message. | ||
setErrorMessage(MessageFormat.format(getErrorMessage(), | ||
new Object[] { value })); | ||
} | ||
valueChanged(oldValidState, newValidState); | ||
} | ||
|
||
/** | ||
* Processes a key release event that occurred in this cell editor. | ||
* <p> | ||
* The <code>TextCellEditor</code> implementation of this framework method | ||
* ignores when the RETURN key is pressed since this is handled in | ||
* <code>handleDefaultSelection</code>. | ||
* An exception is made for Ctrl+Enter for multi-line texts, since | ||
* a default selection event is not sent in this case. | ||
* </p> | ||
* | ||
* @param keyEvent the key event | ||
*/ | ||
@Override | ||
protected void keyReleaseOccured(KeyEvent keyEvent) { | ||
if (keyEvent.character == '\r') { // Return key | ||
// Enter is handled in handleDefaultSelection. | ||
// Do not apply the editor value in response to an Enter key event | ||
// since this can be received from the IME when the intent is -not- | ||
// to apply the value. | ||
// See bug 39074 [CellEditors] [DBCS] canna input mode fires bogus event from Text Control | ||
// | ||
// An exception is made for Ctrl+Enter for multi-line texts, since | ||
// a default selection event is not sent in this case. | ||
if (text != null && !text.isDisposed() | ||
&& (text.getStyle() & SWT.MULTI) != 0) { | ||
if ((keyEvent.stateMask & SWT.CTRL) != 0) { | ||
super.keyReleaseOccured(keyEvent); | ||
} | ||
} | ||
return; | ||
} | ||
super.keyReleaseOccured(keyEvent); | ||
} | ||
|
||
/** | ||
* Updates the controls showing the value of this cell editor. | ||
* <p> | ||
* The default implementation of this framework method just converts | ||
* the passed object to a string using <code>toString</code> and | ||
* sets this as the text of the label widget. | ||
* </p> | ||
* <p> | ||
* Subclasses may reimplement. If you reimplement this method, you | ||
* should also reimplement <code>createContents</code>. | ||
* </p> | ||
* | ||
* @param value the new value of this cell editor | ||
*/ | ||
protected void updateContents(Object value) { | ||
if (text == null) { | ||
return; | ||
} | ||
|
||
String val = "";//$NON-NLS-1$ | ||
if (value != null) { | ||
val = value.toString(); | ||
} | ||
text.setText(val); | ||
Assert.isTrue(text != null && (val instanceof String)); | ||
text.removeModifyListener(getModifyListener()); | ||
text.setText((String) val); | ||
text.addModifyListener(getModifyListener()); | ||
} | ||
|
||
} |
Oops, something went wrong.