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.slc.client.ui.dist.editors;
17  
18  import javax.jcr.Node;
19  
20  import org.argeo.slc.SlcException;
21  import org.argeo.slc.SlcNames;
22  import org.eclipse.swt.SWT;
23  import org.eclipse.swt.events.SelectionAdapter;
24  import org.eclipse.swt.events.SelectionEvent;
25  import org.eclipse.swt.layout.GridData;
26  import org.eclipse.swt.layout.GridLayout;
27  import org.eclipse.swt.widgets.Button;
28  import org.eclipse.swt.widgets.Composite;
29  import org.eclipse.swt.widgets.Text;
30  import org.eclipse.ui.forms.IManagedForm;
31  import org.eclipse.ui.forms.editor.FormEditor;
32  import org.eclipse.ui.forms.editor.FormPage;
33  import org.eclipse.ui.forms.widgets.FormToolkit;
34  import org.eclipse.ui.forms.widgets.ScrolledForm;
35  
36  /**
37   * Enable launch of the current distribution in a separate osgi run time.
38   * Display also a console to interract with the launched runtime
39   */
40  public class RunInOsgiPage extends FormPage implements SlcNames {
41  
42  	final static String PAGE_ID = "RunInOsgiPage";
43  
44  	// Business Objects
45  	private Node modularDistribution;
46  
47  	// This page widgets
48  	private Button launchBtn;
49  	private Text consoleTxt;
50  
51  	private FormToolkit tk;
52  
53  	public RunInOsgiPage(FormEditor formEditor, String title,
54  			Node modularDistribution) {
55  		super(formEditor, PAGE_ID, title);
56  		this.modularDistribution = modularDistribution;
57  	}
58  
59  	@Override
60  	protected void createFormContent(IManagedForm managedForm) {
61  		ScrolledForm form = managedForm.getForm();
62  		tk = managedForm.getToolkit();
63  		// Main Layout
64  		Composite body = form.getBody();
65  		GridLayout layout = new GridLayout();
66  		layout.marginTop = layout.marginWidth = 0;
67  		body.setLayout(layout);
68  
69  		// The header
70  		Composite header = tk.createComposite(body);
71  		header.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
72  		createHeaderPart(header);
73  
74  		// The console
75  		Composite console = tk.createComposite(body);
76  		console.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
77  		createConsolePart(console);
78  		body.layout();
79  	}
80  
81  	private void createHeaderPart(Composite parent) {
82  		GridLayout layout = new GridLayout();
83  		parent.setLayout(layout);
84  
85  		// Text Area to filter
86  		launchBtn = tk.createButton(parent, " Launch ", SWT.PUSH);
87  		launchBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
88  
89  		launchBtn.addSelectionListener(new SelectionAdapter() {
90  			private static final long serialVersionUID = -1633658484882130602L;
91  
92  			@Override
93  			public void widgetSelected(SelectionEvent e) {
94  				super.widgetSelected(e);
95  				throw new SlcException("Implement this");
96  			}
97  		});
98  	}
99  
100 	private void createConsolePart(Composite parent) {
101 		parent.setLayout(new GridLayout());
102 		consoleTxt = tk.createText(parent, "OSGi > ", SWT.MULTI | SWT.WRAP
103 				| SWT.BORDER);
104 		consoleTxt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
105 	}
106 
107 	@Override
108 	public void setFocus() {
109 		launchBtn.setFocus();
110 	}
111 }