/*
* $Id: RunJettyRunTab.java 39 2009-05-03 22:38:57Z james.synge@gmail.com $
* $HeadURL: https://run-jetty-run.googlecode.com/svn/trunk/plugin/src/runjettyrun/RunJettyRunTab.java $
*
* ==============================================================================
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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 runjettyrun;
import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchTab;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
/**
* Launch tab for the RunJettyRun plugin.
*
* @author hillenius, James Synge
*/
public class RunJettyRunTab extends JavaLaunchTab {
private static abstract class ButtonListener implements SelectionListener {
public void widgetDefaultSelected(SelectionEvent e) {
}
}
private Text fProjText;
private Button fProjButton;
private Text fPortText;
private Text fSSLPortText;
private Text fKeystoreText;
private Button fKeystoreButton;
private Text fKeyPasswordText;
private Text fPasswordText;
private Text fContextText;
private Text fWebAppDirText;
private Button fWebappDirButton;
/**
* Construct.
*/
public RunJettyRunTab() {
}
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setFont(parent.getFont());
GridData gd = new GridData(1);
gd.horizontalSpan = GridData.FILL_BOTH;
comp.setLayoutData(gd);
GridLayout layout = new GridLayout(1, false);
layout.verticalSpacing = 0;
comp.setLayout(layout);
createProjectEditor(comp);
createVerticalSpacer(comp, 1);
createPortEditor(comp);
createVerticalSpacer(comp, 1);
createJettyOptionsEditor(comp);
createVerticalSpacer(comp, 1);
setControl(comp);
// PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
// IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
return;
}
/**
* Creates the widgets for specifying a main type.
*
* @param parent
* the parent composite
*/
private void createProjectEditor(Composite parent) {
Font font = parent.getFont();
Group group = new Group(parent, SWT.NONE);
group.setText("Project");
GridData gd = createHFillGridData();
group.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
group.setLayout(layout);
group.setFont(font);
fProjText = new Text(group, SWT.SINGLE | SWT.BORDER);
gd = createHFillGridData();
fProjText.setLayoutData(gd);
fProjText.setFont(font);
fProjText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
});
fProjButton = createPushButton(group, "&Browse...", null);
fProjButton.addSelectionListener(new ButtonListener() {
public void widgetSelected(SelectionEvent e) {
handleProjectButtonSelected();
}
});
}
private GridData createHFillGridData() {
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
return gd;
}
/**
* Creates the widgets for specifying the ports:
*
* HTTP Port: Text....... HTTPS Port: Text.......
* Keystore: Text.................. Browse Button
* Store Password: Text.. Key Password: Text.....
*
* @param parent
* the parent composite
*/
private void createPortEditor(Composite parent) {
// Create group, container for widgets
Font font = parent.getFont();
Group group = new Group(parent, SWT.NONE);
group.setText("Ports");
GridData gd = createHFillGridData();
group.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
group.setLayout(layout);
group.setFont(font);
// HTTP and HTTPS ports
new Label(group, SWT.LEFT).setText("HTTP");
fPortText = new Text(group, SWT.SINGLE | SWT.BORDER);
fPortText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
});
gd = createHFillGridData();
fPortText.setLayoutData(gd);
fPortText.setFont(font);
fPortText.setTextLimit(5);
setWidthForSampleText(fPortText, " 65535 ");
Label lbl = new Label(group, SWT.LEFT);
lbl.setText("HTTPS");
gd = new GridData();
gd.horizontalAlignment = SWT.RIGHT;
lbl.setLayoutData(gd);
fSSLPortText = new Text(group, SWT.SINGLE | SWT.BORDER);
fSSLPortText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (fSSLPortText.getText().trim().length() == 0) {
setKeystoreEnabled(false);
}
else {
setKeystoreEnabled(true);
}
updateLaunchConfigurationDialog();
}
});
gd = createHFillGridData();
fSSLPortText.setLayoutData(gd);
fSSLPortText.setFont(font);
// keystore
new Label(group, SWT.LEFT).setText("Keystore");
fKeystoreText = new Text(group, SWT.SINGLE | SWT.BORDER);
fKeystoreText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
});
gd = createHFillGridData();
gd.horizontalSpan = 2;
fKeystoreText.setLayoutData(gd);
fKeystoreText.setFont(font);
fKeystoreText.setEnabled(false);
fKeystoreButton = createPushButton(group, "&Browse...", null);
fKeystoreButton.addSelectionListener(new ButtonListener() {
public void widgetSelected(SelectionEvent e) {
handleBrowseFileSystem();
}
});