~ubuntu-branches/ubuntu/utopic/eclipse-eclox/utopic

« back to all changes in this revision

Viewing changes to eclox.ui/src/eclox/ui/editor/editors/FileEditor.java

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-07 20:33:10 UTC
  • Revision ID: package-import@ubuntu.com-20130707203310-a44yw80gqtc2s9ob
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (C) 2003-2006, 2013, Guillaume Brocker
 
3
 * 
 
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
 
8
 *
 
9
 * Contributors:
 
10
 *     Guillaume Brocker - Initial API and implementation
 
11
 *
 
12
 ******************************************************************************/ 
 
13
 
 
14
package eclox.ui.editor.editors;
 
15
 
 
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;
 
22
 
 
23
 
 
24
public class FileEditor extends TextEditor {
 
25
        /**
 
26
         * the push button for browsing the file system
 
27
         */
 
28
        private Button  browseFileSystemButton;
 
29
        
 
30
        /**
 
31
         * Implements the selection listener attached to the push buttons.
 
32
         */
 
33
        class MySelectionListener implements SelectionListener {
 
34
 
 
35
                /**
 
36
                 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
 
37
                 */
 
38
                public void widgetDefaultSelected(SelectionEvent e) {
 
39
                        if( e.widget == browseFileSystemButton ) {
 
40
                                browseFileSystem();
 
41
                        }
 
42
                }
 
43
 
 
44
                /**
 
45
                 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
 
46
                 */
 
47
                public void widgetSelected(SelectionEvent e) {
 
48
                        if( e.widget == browseFileSystemButton ) {
 
49
                                browseFileSystem();
 
50
                        }
 
51
                }
 
52
                
 
53
        }
 
54
        
 
55
        public void createContent(Composite parent, FormToolkit formToolkit) {
 
56
                super.createContent(parent, formToolkit);
 
57
                
 
58
                // Create controls and their associated layout data.
 
59
                SelectionListener       selectionListener = new MySelectionListener();
 
60
                GridLayout                      layout                          = (GridLayout) parent.getLayout();
 
61
                
 
62
                layout.numColumns = 2;
 
63
                
 
64
                browseFileSystemButton = formToolkit.createButton( parent, "Browse...", 0 );
 
65
                browseFileSystemButton.addSelectionListener( selectionListener );
 
66
        }
 
67
 
 
68
        /**
 
69
         * @see eclox.ui.editor.editors.TextEditor#dispose()
 
70
         */
 
71
        public void dispose() {
 
72
                // Local cleaning.
 
73
                browseFileSystemButton.dispose();
 
74
                
 
75
                // Default cleaning.
 
76
                super.dispose();
 
77
        }
 
78
        
 
79
        /**
 
80
         * Browses the file system for a path and updates the managed text field.
 
81
         */
 
82
        private void browseFileSystem() {
 
83
                String  result;
 
84
                result = Convenience.browseFileSystemForFile( text.getShell(), getInput().getOwner(), getInput().getValue() );
 
85
                if( result!= null ) {
 
86
                        super.text.setText( result );
 
87
                }
 
88
        }
 
89
 
 
90
        /**
 
91
         * @see eclox.ui.editor.editors.TextEditor#setEnabled(boolean)
 
92
         */
 
93
        public void setEnabled(boolean enabled) {
 
94
                assert browseFileSystemButton != null;
 
95
                
 
96
                browseFileSystemButton.setEnabled(enabled);
 
97
                super.setEnabled(enabled);
 
98
        }
 
99
        
 
100
        
 
101
 
 
102
}