KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > console > views > HQLEditorView


1 package org.hibernate.eclipse.console.views;
2
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IToolBarManager;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.custom.StyledText;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.layout.GridLayout;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.ui.IActionBars;
11 import org.eclipse.ui.part.ViewPart;
12 import org.hibernate.console.ImageConstants;
13 import org.hibernate.eclipse.console.actions.ExecuteHQLAction;
14 import org.hibernate.eclipse.console.editors.HQLEditor;
15 import org.hibernate.eclipse.console.utils.EclipseImages;
16
17 public class HQLEditorView extends ViewPart {
18     
19     private class ClearAction extends Action {
20         
21         public ClearAction() {
22             setImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.CLEAR));
23             setToolTipText("Clear editor");
24             //setText("Clear");
25
}
26
27         public void run() {
28             setQuery("");
29         }
30     }
31     
32     
33     private ExecuteHQLAction executeAction;
34     private StyledText viewer;
35     
36     public HQLEditorView() {
37         super();
38     }
39
40     public void createPartControl(Composite parent) {
41         
42         
43         GridLayout layout = new GridLayout(1, false);
44         layout.horizontalSpacing = 0;
45         layout.verticalSpacing = 0;
46         layout.marginHeight = 0;
47         layout.marginWidth = 0;
48         parent.setLayout(layout);
49         parent.setLayoutData(new GridData(GridData.FILL_BOTH));
50         
51         viewer = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
52         viewer.setEditable(true);
53         viewer.setLayoutData(new GridData(GridData.FILL_BOTH));
54
55         initActions();
56     }
57
58     
59     private void initActions() {
60
61         IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
62
63         executeAction = new ExecuteHQLAction(this);
64         toolBar.add(this.executeAction);
65         toolBar.add(new ClearAction());
66         
67         IActionBars actionBars = getViewSite().getActionBars();
68         
69         }
70
71     /**
72      * Returns the query to be executed. The query is either 1) the
73      * text currently highlighted/selected in the editor or 2) all of
74      * the text in the editor.
75      * @return query string to be executed
76      */

77     public String JavaDoc getQuery() {
78         String JavaDoc query;
79         
80         if (viewer.getSelectionText().length() > 0)
81             query = viewer.getSelectionText();
82         else
83             query = viewer.getText();
84         
85         return query;
86     }
87     
88     public void setQuery(String JavaDoc text) {
89         viewer.setText(text);
90     }
91     
92     
93     public void setFocus() {
94     }
95     
96 }
Popular Tags