1
/*******************************************************************************
2
* Copyright (C) 2003-2006, 2013, Guillaume Brocker
4
* All rights reserved. This program and the accompanying materials
5
* are made available under the terms of the Eclipse Public License v1.0
6
* which accompanies this distribution, and is available at
7
* http://www.eclipse.org/legal/epl-v10.html
10
* Guillaume Brocker - Initial API and implementation
12
******************************************************************************/
14
package eclox.ui.editor.editors;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Button;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.forms.widgets.FormToolkit;
24
public class FileEditor extends TextEditor {
26
* the push button for browsing the file system
28
private Button browseFileSystemButton;
31
* Implements the selection listener attached to the push buttons.
33
class MySelectionListener implements SelectionListener {
36
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
38
public void widgetDefaultSelected(SelectionEvent e) {
39
if( e.widget == browseFileSystemButton ) {
45
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
47
public void widgetSelected(SelectionEvent e) {
48
if( e.widget == browseFileSystemButton ) {
55
public void createContent(Composite parent, FormToolkit formToolkit) {
56
super.createContent(parent, formToolkit);
58
// Create controls and their associated layout data.
59
SelectionListener selectionListener = new MySelectionListener();
60
GridLayout layout = (GridLayout) parent.getLayout();
62
layout.numColumns = 2;
64
browseFileSystemButton = formToolkit.createButton( parent, "Browse...", 0 );
65
browseFileSystemButton.addSelectionListener( selectionListener );
69
* @see eclox.ui.editor.editors.TextEditor#dispose()
71
public void dispose() {
73
browseFileSystemButton.dispose();
80
* Browses the file system for a path and updates the managed text field.
82
private void browseFileSystem() {
84
result = Convenience.browseFileSystemForFile( text.getShell(), getInput().getOwner(), getInput().getValue() );
86
super.text.setText( result );
91
* @see eclox.ui.editor.editors.TextEditor#setEnabled(boolean)
93
public void setEnabled(boolean enabled) {
94
assert browseFileSystemButton != null;
96
browseFileSystemButton.setEnabled(enabled);
97
super.setEnabled(enabled);