Skip to content

Commit

Permalink
Merge pull request #8 from arjantijms/EP-26-libraries
Browse files Browse the repository at this point in the history
EP-26 Implemented container properties and made it properly refresh
  • Loading branch information
arjantijms authored Apr 18, 2019
2 parents 6921de3 + 7f5155f commit 6dc5547
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 22 deletions.
11 changes: 10 additions & 1 deletion plugins/org.eclipse.payara.tools.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,16 @@
</extension>


<!--
<extension point="org.eclipse.jdt.ui.classpathContainerPage">
<classpathContainerPage
id="org.eclipse.payara.tools.lib.system"
name="Payara properties"
class="org.eclipse.payara.tools.ui.properties.ClasspathContainerPage">
</classpathContainerPage>
</extension>


<!--
This provides the dynamic nodes; the tree nodes that are inserted underneath
a running Payara / GlassFish server node in the Servers view.
-->
Expand Down
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ protected void performDefaults() {
serverWorkingCopy.setAttribute(ATTR_DEBUG_PORT, "");
serverWorkingCopy.setAttribute(PROP_RESTART_PATTERN.name(), "");



model.refresh();
}

Expand Down
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);
}
}
Loading

0 comments on commit 6dc5547

Please sign in to comment.