Method from org.apache.geronimo.st.ui.internal.GeronimoRuntimeWizardFragment Detail: |
protected void addDownloadServerSection(Composite composite) {
FormText downloadServerText = new FormText(composite, SWT.WRAP);
IRuntime runtime = getRuntimeDelegate().getRuntime();
String runtimeName = runtime.getRuntimeType().getName();
String text = "< form >"
+ Messages.bind(Messages.DownloadServerText,
Messages.DownloadServerURL, runtimeName) + "< /form >";
downloadServerText.setText(text, true, true);
GridData data = new GridData();
data.horizontalSpan = 3;
downloadServerText.setLayoutData(data);
downloadServerText.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent hyperlinkEvent) {
String url = hyperlinkEvent.getHref().toString();
Trace.trace(Trace.INFO, "Hyperlink " + url + ".");
try {
int style = IWorkbenchBrowserSupport.AS_EXTERNAL
| IWorkbenchBrowserSupport.STATUS;
IWebBrowser browser = WorkbenchBrowserSupport.getInstance()
.createBrowser(style, "download server",
"get server", "tool tip");
browser.openURL(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
}
|
protected void addInstallDirSection(Composite composite) {
Label label = new Label(composite, SWT.NONE);
label.setText(Messages.installDir);
GridData data = new GridData();
data.horizontalSpan = 3;
label.setLayoutData(data);
String tooltipLoc = Messages.bind(Messages.tooltipLoc, getRuntimeName());
label.setToolTipText(tooltipLoc);
installDir = new Text(composite, SWT.BORDER);
IPath currentLocation = getRuntimeDelegate().getRuntimeWorkingCopy().getLocation();
if (currentLocation != null) {
installDir.setText(currentLocation.toOSString());
}
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
installDir.setLayoutData(data);
installDir.setToolTipText(tooltipLoc);
installDir.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getRuntimeDelegate().getRuntimeWorkingCopy().setLocation(new Path(installDir.getText()));
validate();
}
});
final Composite browseComp = composite;
Button browse = SWTUtil.createButton(composite, Messages.browse);
browse.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
DirectoryDialog dialog = new DirectoryDialog(browseComp.getShell());
dialog.setMessage(Messages.installDir);
dialog.setFilterPath(installDir.getText());
String selectedDirectory = dialog.open();
if (selectedDirectory != null)
installDir.setText(selectedDirectory);
}
});
}
|
protected void addJRESelection(Composite composite) {
updateJREs();
Label label = new Label(composite, SWT.NONE);
label.setText(Messages.installedJRE);
label.setLayoutData(new GridData());
combo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
combo.setItems(jreNames);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
combo.setLayoutData(data);
combo.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
// if the first item in the list is selected, then pass null
// to setVMInstall to use the default JRE.
// otherwise the array list of JRE's is one off from what is
// in the combo; subtract 1 from the selection to get the
// correct JRE.
int sel = combo.getSelectionIndex();
IVMInstall vmInstall = null;
if (sel > 0) {
vmInstall = (IVMInstall) installedJREs.get(sel - 1);
}
getRuntimeDelegate().setVMInstall(vmInstall);
validate();
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
Button button = SWTUtil.createButton(composite, Messages.installedJREs);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String currentVM = combo.getText();
if (showPreferencePage(composite)) {
updateJREs();
combo.setItems(jreNames);
combo.setText(currentVM);
if (combo.getSelectionIndex() == -1)
combo.select(0);
}
}
});
if (getRuntimeDelegate() != null) {
if (getRuntimeDelegate().isUsingDefaultJRE()) {
combo.select(0);
} else {
combo.setText(getRuntimeDelegate().getVMInstall().getName());
}
}
}
|
protected void createChildFragments(List list) {
list.add(new GeronimoRuntimeSourceWizardFragment());
}
|
public Composite createComposite(Composite parent,
IWizardHandle handle) {
this.fWizard = handle;
Composite container = new Composite(parent, SWT.NONE);
GridLayout grid = new GridLayout(1, false);
grid.marginWidth = 0;
container.setLayout(grid);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
handle.setImageDescriptor(Activator.getImageDescriptor((Activator.IMG_WIZ_GERONIMO)));
handle.setTitle(Messages.bind(Messages.runtimeWizardTitle, getRuntimeName()));
String name = getGeronimoRuntime().getRuntime().getRuntimeType().getName();
//handle.setDescription(Messages.bind(Messages.runtimeWizardDescription, name));
createContent(container, handle);
return container;
}
|
public void createContent(Composite parent,
IWizardHandle handle) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(3, false);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
addJRESelection(composite);
addInstallDirSection(composite);
addDownloadServerSection(composite);
}
|
public void enter() {
if (getRuntimeDelegate() != null)
getRuntimeDelegate().getRuntimeWorkingCopy().setName(createName());
validate();
}
|
public void exit() {
validate();
}
|
protected GeronimoRuntimeDelegate getGeronimoRuntime() {
if (geronimoRuntime == null)
geronimoRuntime = (GeronimoRuntimeDelegate) getRuntimeDelegate().getRuntime().loadAdapter(
GeronimoRuntimeDelegate.class, null);
return geronimoRuntime;
}
|
protected String getRuntimeName() {
if (getRuntimeDelegate() != null && getRuntimeDelegate().getRuntime() != null)
return getRuntimeDelegate().getRuntime().getName();
return null;
}
|
public IWizardHandle getWizard() {
return fWizard;
}
|
public boolean hasComposite() {
return true;
}
|
public boolean isComplete() {
IRuntimeWorkingCopy runtimeWC = getRuntimeDelegate().getRuntimeWorkingCopy();
IStatus status = runtimeWC.validate(null);
return status == null || status.getSeverity() != IStatus.ERROR;
}
|
public static void main(String[] args) {
Pattern SERVER_NAME_VERSION_PATTERN = Pattern.compile("(.*-)((\\d+\\.\\d+)(\\.(\\d+))?)");
for (String path : args) {
StringBuffer installPath = new StringBuffer();
Matcher matcher = SERVER_NAME_VERSION_PATTERN.matcher(path);
if (matcher.find()) {
String serverName = matcher.group(1);
String serverVersion = matcher.group(2);
installPath = installPath.append(serverName + serverVersion);
System.out.println("path = " + path + ", serverVersion = " + serverVersion + ", installPath = "
+ installPath);
} else {
System.out.println("No version found in path = " + path);
}
}
}
Code for testing server name determination code in the
updateInstallDir(IPath) method of addInstallableRuntimeSection. |
protected boolean showPreferencePage(Composite composite) {
PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
IPreferenceNode node = manager.find("org.eclipse.jdt.ui.preferences.JavaBasePreferencePage").findSubNode(
"org.eclipse.jdt.debug.ui.preferences.VMPreferencePage");
PreferenceManager manager2 = new PreferenceManager();
manager2.addToRoot(node);
final PreferenceDialog dialog = new PreferenceDialog(composite.getShell(), manager2);
final boolean[] result = new boolean[] { false };
BusyIndicator.showWhile(composite.getDisplay(), new Runnable() {
public void run() {
dialog.create();
if (dialog.open() == Window.OK)
result[0] = true;
}
});
return result[0];
}
|
protected void updateJREs() {
installedJREs = new ArrayList< IVMInstall >();
IVMInstallType[] vmInstallTypes = JavaRuntime.getVMInstallTypes();
int size = vmInstallTypes.length;
for (int i = 0; i < size; i++) {
IVMInstall[] vmInstalls = vmInstallTypes[i].getVMInstalls();
int size2 = vmInstalls.length;
for (int j = 0; j < size2; j++) {
installedJREs.add(vmInstalls[j]);
}
}
// The Default JRE will always be the first item in the combo. This is
// an assumption that is made by the combo selection listener and that
// all
// other installed JREs are listed afterwards in the same order that
// they
// are found in the list of installed JREs
size = installedJREs.size();
jreNames = new String[size + 1];
jreNames[0] = Messages.runtimeDefaultJRE;
for (int i = 0; i < size; i++) {
IVMInstall vmInstall = (IVMInstall) installedJREs.get(i);
jreNames[i + 1] = vmInstall.getName();
}
}
|
protected void validate() {
IRuntime runtime = getRuntimeDelegate().getRuntime();
String runtimeName = runtime.getRuntimeType().getName();
IWizardHandle wizard = getWizard();
if (runtime == null) {
wizard.setMessage("", IMessageProvider.ERROR);
return;
}
IRuntimeWorkingCopy runtimeWC = getRuntimeDelegate().getRuntimeWorkingCopy();
getRuntimeDelegate().setInstanceProperty("serverRootDirectory", installDir.getText());
if (installDir.getText() == null || installDir.getText().length() == 0) {
// installDir field has not been entered
wizard.setMessage(Messages.bind(Messages.installDirInfo, runtimeName), IMessageProvider.NONE);
} else {
IStatus status = runtimeWC.validate(null);
if (status == null || status.isOK()) {
// a valid install found
wizard.setMessage(Messages.bind(Messages.serverDetected, runtimeName), IMessageProvider.NONE);
} else if (status.getCode() == GeronimoRuntimeDelegate.INCORRECT_VERSION) {
if (status.getSeverity() == IStatus.ERROR) {
wizard.setMessage(status.getMessage(), IMessageProvider.ERROR);
return;
}
wizard.setMessage(status.getMessage(), IMessageProvider.WARNING);
} else if (status.getCode() == GeronimoRuntimeDelegate.PARTIAL_IMAGE) {
wizard.setMessage(status.getMessage(), IMessageProvider.ERROR);
return;
} else {
File file = new Path(installDir.getText()).toFile();
if (file.isDirectory()) {
String message = file.canWrite() ? Messages.noImageFound : Messages.cannotInstallAtLocation;
message = Messages.bind(message, runtimeName);
wizard.setMessage(message, IMessageProvider.ERROR);
} else {
wizard.setMessage(Messages.noSuchDir, IMessageProvider.ERROR);
}
return;
}
if (!isValidVM()) {
wizard.setMessage(Messages.bind(Messages.jvmWarning, runtimeName), IMessageProvider.WARNING);
}
}
}
|