View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.cms.ui.workbench.jcr;
17  
18  import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
19  import org.argeo.cms.ui.workbench.internal.jcr.parts.AbstractJcrQueryEditor;
20  import org.eclipse.swt.SWT;
21  import org.eclipse.swt.layout.GridData;
22  import org.eclipse.swt.layout.GridLayout;
23  import org.eclipse.swt.widgets.Button;
24  import org.eclipse.swt.widgets.Composite;
25  import org.eclipse.swt.widgets.Event;
26  import org.eclipse.swt.widgets.Listener;
27  import org.eclipse.swt.widgets.Text;
28  
29  /** Enables end user to type and execute any JCR query. */
30  public class GenericJcrQueryEditor extends AbstractJcrQueryEditor {
31  	public final static String ID = WorkbenchUiPlugin.PLUGIN_ID
32  			+ ".genericJcrQueryEditor";
33  
34  	private Text queryField;
35  
36  	@Override
37  	public void createQueryForm(Composite parent) {
38  		parent.setLayout(new GridLayout(1, false));
39  
40  		queryField = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP);
41  		queryField.setText(initialQuery);
42  		queryField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
43  
44  		Button execute = new Button(parent, SWT.PUSH);
45  		execute.setText("Execute");
46  
47  		Listener executeListener = new Listener() {
48  			private static final long serialVersionUID = -918256291554301699L;
49  
50  			public void handleEvent(Event event) {
51  				executeQuery(queryField.getText());
52  			}
53  		};
54  
55  		execute.addListener(SWT.Selection, executeListener);
56  		// queryField.addListener(SWT.DefaultSelection, executeListener);
57  	}
58  
59  	@Override
60  	public void setFocus() {
61  		queryField.setFocus();
62  	}
63  }