-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from arjantijms/EP-26-libraries
EP-26 Implemented container properties and made it properly refresh
- Loading branch information
Showing
7 changed files
with
371 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...se.payara.tools.ui/src/org/eclipse/payara/tools/ui/properties/ClasspathContainerPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2019 Payara Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
|
||
package org.eclipse.payara.tools.ui.properties; | ||
|
||
import static org.eclipse.swt.layout.GridData.FILL_BOTH; | ||
import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; | ||
|
||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.jdt.core.IClasspathEntry; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; | ||
import org.eclipse.jface.wizard.WizardPage; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
|
||
/** | ||
* This class implements the properties that are shown when Payara is set as a target runtime for a project | ||
* and the corresponding library container is right clicked and then <code>properties</code> are selected. | ||
* | ||
* <p> | ||
* For instance in an Eclipse project that would typically be | ||
* | ||
* <p> | ||
* <verbatim> | ||
* <code> | ||
* Project explorer - [project name] - Java Resources - Libraries - Payara System Libraries - (right click) - Properties | ||
* </code> | ||
* </verbatim> | ||
* | ||
* <p> | ||
* The properties this dialog implements are the choice between the default libraries for a Payara version that are targeted | ||
* at application developers, and all the available libraries in Payara. | ||
* | ||
* @author Arjan Tijms | ||
* | ||
*/ | ||
public class ClasspathContainerPage extends WizardPage implements IClasspathContainerPage { | ||
private final static String PAGE_NAME = ClasspathContainerPage.class.getName(); | ||
|
||
private IClasspathEntry selection; | ||
|
||
public ClasspathContainerPage() { | ||
super(PAGE_NAME); | ||
} | ||
|
||
@Override | ||
public void createControl(Composite parent) { | ||
setTitle("Payara System Library"); | ||
setDescription("Select system library variant for the project build path."); | ||
setMessage("Select system library variant for the project build path."); | ||
|
||
Composite composite = newComposite(parent); | ||
|
||
SystemLibrariesVariantBlock libraryChoice = newLibraryChoiceBlock(composite, "System library variant"); | ||
|
||
libraryChoice.addPropertyChangeListener(event -> { | ||
IStatus status = libraryChoice.getStatus(); | ||
if (status.isOK()) { | ||
setErrorMessage(null); | ||
|
||
IPath containerPath = | ||
new Path( | ||
selection.getPath() | ||
.segments()[0]) | ||
.append((String)event.getNewValue()); | ||
|
||
selection = JavaCore.newContainerEntry( | ||
containerPath, | ||
selection.getAccessRules(), | ||
selection.getExtraAttributes(), | ||
selection.isExported()); | ||
} else { | ||
setErrorMessage(status.getMessage()); | ||
} | ||
}); | ||
|
||
setControl(composite); | ||
} | ||
|
||
SystemLibrariesVariantBlock newLibraryChoiceBlock(Composite parent, String title) { | ||
SystemLibrariesVariantBlock libraryChoice = new SystemLibrariesVariantBlock(selection); | ||
libraryChoice.setTitle(title); | ||
libraryChoice.createControl(parent); | ||
libraryChoice.getControl().setLayoutData(new GridData(FILL_HORIZONTAL)); | ||
|
||
return libraryChoice; | ||
} | ||
|
||
public static Composite newComposite(Composite parent) { | ||
return newComposite(parent, 1); | ||
} | ||
|
||
public static Composite newComposite(Composite parent, int columns) { | ||
Composite composite = new Composite(parent, NONE); | ||
composite.setLayout(new GridLayout(columns, false)); | ||
composite.setFont(parent.getFont()); | ||
|
||
GridData gridData = new GridData(FILL_BOTH); | ||
gridData.horizontalSpan = 1; | ||
composite.setLayoutData(gridData); | ||
|
||
return composite; | ||
} | ||
|
||
@Override | ||
public boolean finish() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public IClasspathEntry getSelection() { | ||
return selection; | ||
} | ||
|
||
@Override | ||
public void setSelection(IClasspathEntry containerEntry) { | ||
this.selection = containerEntry; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
...yara.tools.ui/src/org/eclipse/payara/tools/ui/properties/SystemLibrariesVariantBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2018-2019 Payara Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
|
||
package org.eclipse.payara.tools.ui.properties; | ||
|
||
import static java.lang.Math.max; | ||
import static org.eclipse.jface.dialogs.IDialogConstants.BUTTON_WIDTH; | ||
import static org.eclipse.payara.tools.ui.properties.ClasspathContainerPage.newComposite; | ||
import static org.eclipse.payara.tools.utils.PayaraLocationUtils.ALL_LIBRARIES; | ||
import static org.eclipse.payara.tools.utils.PayaraLocationUtils.DEFAULT_LIBRARIES; | ||
import static org.eclipse.swt.SWT.DEFAULT; | ||
import static org.eclipse.swt.SWT.NONE; | ||
import static org.eclipse.swt.SWT.RADIO; | ||
import static org.eclipse.swt.layout.GridData.BEGINNING; | ||
import static org.eclipse.swt.layout.GridData.FILL; | ||
import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL; | ||
|
||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.ListenerList; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.jdt.core.IClasspathEntry; | ||
import org.eclipse.jface.layout.PixelConverter; | ||
import org.eclipse.jface.util.IPropertyChangeListener; | ||
import org.eclipse.jface.util.PropertyChangeEvent; | ||
import org.eclipse.swt.events.SelectionAdapter; | ||
import org.eclipse.swt.events.SelectionEvent; | ||
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.Control; | ||
import org.eclipse.swt.widgets.Group; | ||
|
||
/** | ||
* This class implements the visual radio buttons on the properties page for {@link ClasspathContainerPage}. | ||
* | ||
* @author Arjan Tijms | ||
*/ | ||
public class SystemLibrariesVariantBlock { | ||
|
||
private Composite control; | ||
private final ListenerList<IPropertyChangeListener> changeListeners = new ListenerList<>(); | ||
|
||
private IClasspathEntry selection; | ||
private String title; | ||
|
||
private Button defaultButton; | ||
private Button allButton; | ||
|
||
private IStatus status = OK_STATUS; | ||
private static IStatus OK_STATUS = new Status(IStatus.OK, "SystemLibrariesVariantBlock", 0, "", null); | ||
|
||
public SystemLibrariesVariantBlock(IClasspathEntry selection) { | ||
this.selection = selection; | ||
} | ||
|
||
/** | ||
* Creates this block's control in the given control. | ||
* | ||
* @param anscestor containing control | ||
*/ | ||
public void createControl(Composite ancestor) { | ||
control = newComposite(ancestor); | ||
|
||
Composite composite = newComposite(newGroup(control, title), 3); | ||
createDefaultButton(composite, 3); | ||
createAllButton(composite, 3); | ||
|
||
IPath containerPath = selection.getPath(); | ||
String libraryGroup = DEFAULT_LIBRARIES; | ||
if (containerPath.segmentCount() > 1) { | ||
libraryGroup = containerPath.segment(1); | ||
} | ||
|
||
if (DEFAULT_LIBRARIES.equals(libraryGroup)) { | ||
defaultButton.setSelection(true); | ||
} else { | ||
allButton.setSelection(true); | ||
} | ||
} | ||
|
||
public void addPropertyChangeListener(IPropertyChangeListener listener) { | ||
changeListeners.add(listener); | ||
} | ||
|
||
public void removePropertyChangeListener(IPropertyChangeListener listener) { | ||
changeListeners.remove(listener); | ||
} | ||
|
||
public Control getControl() { | ||
return control; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String selection() { | ||
if (defaultButton.getSelection()) { | ||
return DEFAULT_LIBRARIES; | ||
} | ||
|
||
return ALL_LIBRARIES; | ||
} | ||
|
||
public IStatus getStatus() { | ||
return status; | ||
} | ||
|
||
private void setStatus(IStatus status) { | ||
this.status = status; | ||
} | ||
|
||
private void createDefaultButton(Composite composite, int horizontalSpan) { | ||
defaultButton = createRadioButton(composite, "Libraries for current version", horizontalSpan); | ||
defaultButton.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent e) { | ||
if (defaultButton.getSelection()) { | ||
setStatus(OK_STATUS); | ||
firePropertyChange(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void createAllButton(Composite composite, int horizontalSpan) { | ||
allButton = createRadioButton(composite, "All libraries in entire server", horizontalSpan); | ||
allButton.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent e) { | ||
if (allButton.getSelection()) { | ||
setStatus(OK_STATUS); | ||
firePropertyChange(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void firePropertyChange() { | ||
PropertyChangeEvent event = new PropertyChangeEvent(this, "Payara library selection", null, selection()); | ||
for (IPropertyChangeListener listener : changeListeners) { | ||
listener.propertyChange(event); | ||
} | ||
} | ||
|
||
private static Group newGroup(Composite parent, String text) { | ||
Group group = new Group(parent, NONE); | ||
group.setLayout(new GridLayout(1, false)); | ||
group.setText(text); | ||
group.setFont(parent.getFont()); | ||
|
||
GridData gridData = new GridData(FILL_HORIZONTAL); | ||
gridData.horizontalSpan = 1; | ||
group.setLayoutData(gridData); | ||
|
||
return group; | ||
} | ||
|
||
private static Button createRadioButton(Composite parent, String label, int horizontalSpan) { | ||
Button button = new Button(parent, RADIO); | ||
button.setFont(parent.getFont()); | ||
button.setText(label); | ||
|
||
GridData gridData = new GridData(BEGINNING); | ||
gridData.horizontalSpan = 3; | ||
gridData.horizontalAlignment = FILL; | ||
gridData.widthHint= computeWidth(button); | ||
button.setLayoutData(gridData); | ||
|
||
return button; | ||
} | ||
|
||
private static int computeWidth(Button button) { | ||
return max( | ||
new PixelConverter(button).convertHorizontalDLUsToPixels(BUTTON_WIDTH), | ||
button.computeSize(DEFAULT, DEFAULT, true).x); | ||
} | ||
} |
Oops, something went wrong.