2 * Copyright (c) 2012 Intel Corporation. All rights reserved.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.tizen.web.simulator.launch;
\r
19 import org.eclipse.core.resources.IProject;
\r
20 import org.eclipse.core.resources.IResource;
\r
21 import org.eclipse.core.resources.ResourcesPlugin;
\r
22 import org.eclipse.core.runtime.CoreException;
\r
23 import org.eclipse.debug.core.ILaunchConfiguration;
\r
24 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
\r
25 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
\r
26 import org.eclipse.jface.viewers.ISelection;
\r
27 import org.eclipse.jface.viewers.IStructuredSelection;
\r
28 import org.eclipse.jface.window.Window;
\r
29 import org.eclipse.swt.SWT;
\r
30 import org.eclipse.swt.events.ModifyEvent;
\r
31 import org.eclipse.swt.events.ModifyListener;
\r
32 import org.eclipse.swt.events.SelectionAdapter;
\r
33 import org.eclipse.swt.events.SelectionEvent;
\r
34 import org.eclipse.swt.graphics.Image;
\r
35 import org.eclipse.swt.layout.GridData;
\r
36 import org.eclipse.swt.layout.GridLayout;
\r
37 import org.eclipse.swt.widgets.Button;
\r
38 import org.eclipse.swt.widgets.Composite;
\r
39 import org.eclipse.swt.widgets.Label;
\r
40 import org.eclipse.swt.widgets.Slider;
\r
41 import org.eclipse.swt.widgets.Text;
\r
42 import org.eclipse.ui.PlatformUI;
\r
43 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
\r
44 import org.eclipse.ui.model.WorkbenchLabelProvider;
\r
46 import org.tizen.common.util.ImageUtil;
\r
47 import org.tizen.web.common.CommonMessages;
\r
48 import org.tizen.web.simulator.Activator;
\r
50 import static org.tizen.web.simulator.launch.Constants.*;
\r
52 public class SimulatorMainTab extends AbstractLaunchConfigurationTab {
\r
53 public static final String PROJECT_NAME = "project_name"; //$NON-NLS-1$
\r
55 // Project UI widgets
\r
56 protected Label fProjLabel;
\r
57 protected Text fProjText;
\r
58 protected Button fProjButton;
\r
59 protected Slider fslider;
\r
60 protected Label fsliderLabel;
\r
63 public void createControl(Composite parent) {
\r
64 Composite comp = new Composite(parent, SWT.NONE);
\r
67 GridLayout topLayout = new GridLayout();
\r
68 comp.setLayout(topLayout);
\r
70 createVerticalSpacer(comp, 1);
\r
71 createProjectGroup(comp, 1);
\r
74 protected void createProjectGroup(Composite parent, int colSpan) {
\r
75 Composite projComp = new Composite(parent, SWT.NONE);
\r
76 GridLayout projLayout = new GridLayout();
\r
77 projLayout.numColumns = 2;
\r
78 projLayout.marginHeight = 0;
\r
79 projLayout.marginWidth = 0;
\r
80 projComp.setLayout(projLayout);
\r
81 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
\r
82 gd.horizontalSpan = colSpan;
\r
83 projComp.setLayoutData(gd);
\r
85 fProjLabel = new Label(projComp, SWT.NONE);
\r
86 fProjLabel.setText(LaunchMessages.PROJECT_NAME);
\r
87 gd = new GridData();
\r
88 gd.horizontalSpan = 2;
\r
89 fProjLabel.setLayoutData(gd);
\r
91 fProjText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
\r
92 gd = new GridData(GridData.FILL_HORIZONTAL);
\r
93 fProjText.setLayoutData(gd);
\r
94 fProjText.addModifyListener(new ModifyListener() {
\r
96 public void modifyText(ModifyEvent e) {
\r
97 updateLaunchConfigurationDialog();
\r
101 fProjButton = createPushButton(projComp, CommonMessages.Dialog_browse, null); //$NON-NLS-1$
\r
102 fProjButton.addSelectionListener(new SelectionAdapter() {
\r
103 public void widgetSelected(SelectionEvent evt) {
\r
104 handleProjectButtonSelected();
\r
105 updateLaunchConfigurationDialog();
\r
110 protected void handleProjectButtonSelected() {
\r
111 IProject project = chooseProject();
\r
112 if (project == null) {
\r
116 fProjText.setText(project.getName());
\r
119 private IProject chooseProject() {
\r
120 IProject projects[] = ResourcesPlugin.getWorkspace().getRoot().getProjects();
\r
122 ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new WorkbenchLabelProvider());
\r
123 dialog.setTitle(LaunchMessages.SimulatorMainTab_TITLE);
\r
124 dialog.setMessage(LaunchMessages.SimulatorMainTab_MESSAGE);
\r
125 dialog.setElements(projects);
\r
127 if (dialog.open() == Window.OK) {
\r
128 return (IProject) dialog.getFirstResult();
\r
134 public String getName() {
\r
135 return LaunchMessages.MAINTAB;
\r
139 public Image getImage() {
\r
140 return ImageUtil.getImage(Activator.getDefault(), "icons/tizen16.png"); //$NON-NLS-1$
\r
144 public void initializeFrom(ILaunchConfiguration configuration) {
\r
145 updateProjectFromConfig(configuration);
\r
148 protected void updateProjectFromConfig(ILaunchConfiguration config) {
\r
149 String projectName = EMPTY_STRING;
\r
151 projectName = config.getAttribute(ATTR_PROJECT_NAME, EMPTY_STRING);
\r
152 if(projectName.equals(EMPTY_STRING)) {
\r
153 ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
\r
154 if (selection instanceof IStructuredSelection) {
\r
155 IStructuredSelection sel = (IStructuredSelection) selection;
\r
156 Object res = sel.getFirstElement();
\r
157 if (res instanceof IResource) {
\r
158 projectName = ((IResource)res).getProject().getName();
\r
162 } catch (CoreException ce) {
\r
165 fProjText.setText(projectName);
\r
169 public boolean isValid(ILaunchConfiguration launchConfig) {
\r
170 setErrorMessage(null);
\r
173 String name = fProjText.getText().trim();
\r
174 if (name.length() == 0) {
\r
175 setErrorMessage(LaunchMessages.PROJECT_NOT_SPECIFIED);
\r
178 if (!ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists()) {
\r
179 setErrorMessage(CommonMessages.Project_does_not_exist);
\r
182 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
\r
183 if (!project.isOpen()) {
\r
184 setErrorMessage(LaunchMessages.PROJECT_MUST_BE_OPENED);
\r
191 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
\r
192 configuration.setAttribute(ATTR_PROJECT_NAME, fProjText.getText());
\r
196 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
\r
197 configuration.setAttribute(ATTR_PROJECT_NAME, EMPTY_STRING);
\r