/* * Copyright (c) 2013, the Dart project authors. * * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.dart.tools.debug.ui.internal.browser; import com.google.dart.tools.core.model.DartSdkManager; import com.google.dart.tools.debug.core.DartLaunchConfigWrapper; import com.google.dart.tools.debug.ui.internal.DartDebugUIPlugin; import com.google.dart.tools.debug.ui.internal.util.LaunchTargetComposite; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; /** * Main launch tab for Browser launch configurations */ public class BrowserMainTab extends AbstractLaunchConfigurationTab { private LaunchTargetComposite launchTargetGroup; private Text pubArgsText; @Override public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayoutFactory.swtDefaults().spacing(1, 3).applyTo(composite); launchTargetGroup = new LaunchTargetComposite(composite, SWT.NONE); launchTargetGroup.addListener(SWT.Modify, new Listener() { @Override public void handleEvent(Event event) { notifyPanelChanged(); } }); // pub serve setting Group group = new Group(composite, SWT.NONE); group.setText("Pub settings"); GridDataFactory.fillDefaults().grab(true, false).applyTo(group); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(group); ((GridLayout) group.getLayout()).marginBottom = 5; // pub serve arguments Label pubArgsLabel = new Label(group, SWT.NONE); pubArgsLabel.setText("Pub serve arguments:"); pubArgsText = new Text(group, SWT.BORDER | SWT.SINGLE); GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo( pubArgsText); setControl(composite); } @Override public void dispose() { Control control = getControl(); if (control != null) { control.dispose(); setControl(null); } } @Override public String getErrorMessage() { if (performSdkCheck() != null) { return performSdkCheck(); } return launchTargetGroup.getErrorMessage(); } /** * Answer the image to show in the configuration tab or <code>null</code> if none */ @Override public Image getImage() { return DartDebugUIPlugin.getImage("obj16/globe_dark.png"); //$NON-NLS-1$ } @Override public String getMessage() { return Messages.BrowserMainTab_Description; } /** * Answer the name to show in the configuration tab */ @Override public String getName() { return Messages.BrowserMainTab_Name; } /** * Initialize the UI from the specified configuration */ @Override public void initializeFrom(ILaunchConfiguration config) { DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(config); launchTargetGroup.setHtmlTextValue(wrapper.appendQueryParams(wrapper.getApplicationName())); launchTargetGroup.setUrlTextValue(wrapper.getUrl()); launchTargetGroup.setSourceDirectoryTextValue(wrapper.getSourceDirectoryName()); if (wrapper.getShouldLaunchFile()) { launchTargetGroup.setHtmlButtonSelection(true); } else { launchTargetGroup.setHtmlButtonSelection(false); } pubArgsText.setText(wrapper.getPubServeArguments()); pubArgsText.setEnabled(wrapper.getShouldLaunchFile()); } /** * Store the value specified in the UI into the launch configuration */ @Override public void performApply(ILaunchConfigurationWorkingCopy config) { DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(config); wrapper.setShouldLaunchFile(launchTargetGroup.getHtmlButtonSelection()); String fileUrl = launchTargetGroup.getHtmlFileName(); if (fileUrl.indexOf('?') == -1) { wrapper.setApplicationName(fileUrl); wrapper.setUrlQueryParams(""); } else { int index = fileUrl.indexOf('?'); wrapper.setApplicationName(fileUrl.substring(0, index)); wrapper.setUrlQueryParams(fileUrl.substring(index + 1)); } wrapper.setUrl(launchTargetGroup.getUrlString()); wrapper.setSourceDirectoryName(launchTargetGroup.getSourceDirectory()); wrapper.setPubServeArguments(pubArgsText.getText().trim()); } @Override public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(configuration); wrapper.setShouldLaunchFile(true); wrapper.setApplicationName(""); //$NON-NLS-1$ } private void notifyPanelChanged() { setDirty(true); pubArgsText.setEnabled(launchTargetGroup.getHtmlButtonSelection()); updateLaunchConfigurationDialog(); } private String performSdkCheck() { if (!DartSdkManager.getManager().hasSdk()) { return "Dart2js is not installed (" + DartSdkManager.getManager().getSdk().getDart2JsExecutable() + ")"; } else { return null; } } }