Skip to content

Commit

Permalink
eclipse-m2e#280 rebased
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Dec 9, 2021
1 parent e13899b commit 89a9b39
Show file tree
Hide file tree
Showing 23 changed files with 1,287 additions and 89 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target/
bin/
src-gen/
.DS_Store
.polyglot*
.polyglot*
indexer-jars/
2 changes: 1 addition & 1 deletion org.eclipse.m2e.pde.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.19.0",
org.eclipse.m2e.maven.runtime,
org.eclipse.m2e.core,
org.eclipse.m2e.pde,
org.eclipse.pde;bundle-version="3.13.1200",
org.eclipse.pde;bundle-version="3.13.300",
org.eclipse.core.databinding;bundle-version="1.10.100",
org.eclipse.core.databinding.observable;bundle-version="1.10.0",
org.eclipse.jface.databinding;bundle-version="1.12.200",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Christoph Läubrich - adjust for m2e-pde usage
*******************************************************************************/

package org.eclipse.m2e.pde.ui.editor;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.internal.core.util.IdUtil;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.wizards.feature.FeatureData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

//derived from org.eclipse.pde.internal.ui.wizards.feature.AbstractFeatureSpecPage
@SuppressWarnings("restriction")
public abstract class AbstractFeatureSpecPage extends WizardPage {

protected Text fFeatureNameText;
protected Text fFeatureVersionText;
protected Text fLibraryText;
protected String fInitialId;
protected String fInitialName;

public AbstractFeatureSpecPage() {
super("specPage"); //$NON-NLS-1$
}

@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(GridLayoutFactory.fillDefaults().create());
setControl(comp);
createContents(comp);

initialize();
attachListeners();

Dialog.applyDialogFont(comp);
PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, getHelpId());
setPageComplete(validatePage());
}

protected abstract void createContents(Composite container);

protected abstract void initialize();

protected abstract void attachListeners(ModifyListener listener);

protected abstract String getHelpId();

protected abstract void saveSettings(IDialogSettings settings);

protected void createCommonInput(Composite common) {
Label label = new Label(common, SWT.NULL);
label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_name);
fFeatureNameText = new Text(common, SWT.BORDER);
fFeatureNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

label = new Label(common, SWT.NULL);
label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_version);
fFeatureVersionText = new Text(common, SWT.BORDER);
fFeatureVersionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}

protected void createInstallHandlerText(Composite parent) {
Label libraryLabel = new Label(parent, SWT.NULL);
libraryLabel.setText(PDEUIMessages.NewFeatureWizard_SpecPage_library);
fLibraryText = new Text(parent, SWT.SINGLE | SWT.BORDER);
fLibraryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}

protected boolean validatePage() {
if (!setValidationMessage(verifyIdRules()))
return false;
if (!setValidationMessage(verifyVersion()))
return false;
if (!setValidationMessage(validateContent()))
return false;

setPageComplete(true);
setErrorMessage(null);
return true;
}

private boolean setValidationMessage(String message) {
if (message == null)
return true;
setPageComplete(false);
setErrorMessage(message);
return false;
}

protected abstract String validateContent();

public String getInitialName() {
return fInitialName;
}

public void setInitialName(String initialName) {
fInitialName = initialName;
}

public void setInitialId(String initialId) {
fInitialId = initialId;
}

public String getInitialId() {
return fInitialId;
}

protected String verifyVersion() {
String value = fFeatureVersionText.getText();
if (VersionUtil.validateVersion(value).getSeverity() != IStatus.OK)
return PDEUIMessages.NewFeatureWizard_SpecPage_versionFormat;
return null;
}

protected abstract String getFeatureId();

protected String verifyIdRules() {
String id = getFeatureId();
if (id == null || id.length() == 0)
return PDEUIMessages.NewFeatureWizard_SpecPage_missing;
if (!IdUtil.isValidCompositeID(id)) {
return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId;
}
return null;
}

protected String getInstallHandlerLibrary() {
String library = fLibraryText.getText();
if (library == null || library.length() == 0)
return null;
if (!library.endsWith(".jar") && !library.endsWith("/") && !library.equals(".")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
library += "/"; //$NON-NLS-1$
return library;
}

private void attachListeners() {
ModifyListener listener = e -> {
setPageComplete(validatePage());
};
attachListeners(listener);
fFeatureNameText.addModifyListener(listener);
fFeatureVersionText.addModifyListener(listener);
fLibraryText.addModifyListener(listener);
}

public abstract FeatureData getFeatureData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Christoph Läubrich - adjust for m2e-pde usage
*******************************************************************************/

package org.eclipse.m2e.pde.ui.editor;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.m2e.pde.MavenTargetLocation;
import org.eclipse.pde.internal.core.ifeature.IFeature;
import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
import org.eclipse.pde.internal.core.ifeature.IFeatureInstallHandler;
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
import org.eclipse.pde.internal.ui.IHelpContextIds;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.wizards.BundleProviderHistoryUtil;
import org.eclipse.pde.internal.ui.wizards.feature.FeatureData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

// derived from org.eclipse.pde.internal.ui.wizards.feature.FeatureSpecPage
public class FeatureSpecPage extends AbstractFeatureSpecPage {

private Combo fFeatureProviderCombo;
private Text fFeatureIdText;
private MavenTargetLocation targetLocation;

public FeatureSpecPage(MavenTargetLocation targetLocation) {
super();
this.targetLocation = targetLocation;
setTitle(PDEUIMessages.NewFeatureWizard_SpecPage_title);
setDescription(PDEUIMessages.NewFeatureWizard_SpecPage_desc);
}

@Override
protected void initialize() {
fFeatureVersionText.setText("1.0.0.qualifier"); //$NON-NLS-1$
setMessage(PDEUIMessages.NewFeatureWizard_MainPage_desc);
}

@Override
public FeatureData getFeatureData() {
FeatureData data = new FeatureData();
data.id = fFeatureIdText.getText();
data.version = fFeatureVersionText.getText();
data.provider = fFeatureProviderCombo.getText();
data.name = fFeatureNameText.getText();
data.library = getInstallHandlerLibrary();
return data;
}

@Override
protected String validateContent() {
setMessage(null);
return null;
}

@Override
protected String getHelpId() {
return IHelpContextIds.NEW_FEATURE_DATA;
}

@Override
protected void createContents(Composite container) {
Composite group = new Composite(container, SWT.NULL);
group.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalIndent = 10;
group.setLayoutData(gd);

Label label = new Label(group, SWT.NULL);
label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id);
fFeatureIdText = new Text(group, SWT.BORDER);
fFeatureIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

createCommonInput(group);

label = new Label(group, SWT.NULL);
label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_provider);
fFeatureProviderCombo = new Combo(group, SWT.BORDER | SWT.DROP_DOWN);
fFeatureProviderCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
BundleProviderHistoryUtil.loadHistory(fFeatureProviderCombo, getDialogSettings());

createInstallHandlerText(group);
if (targetLocation != null) {
IFeature template = targetLocation.getFeatureTemplate();
if (template != null) {
fFeatureIdText.setText(template.getId());
fFeatureNameText.setText(template.getLabel());
fFeatureVersionText.setText(template.getVersion());
fFeatureProviderCombo.setText(template.getProviderName());
IFeatureInstallHandler handler = template.getInstallHandler();
if (handler != null) {
fLibraryText.setText(handler.getHandlerName());
}
}
}
}

@Override
protected void attachListeners(ModifyListener listener) {
fFeatureProviderCombo.addModifyListener(listener);
fFeatureIdText.addModifyListener(listener);
}

@Override
protected String getFeatureId() {
return fFeatureIdText.getText();
}

// derived from
// org.eclipse.pde.internal.ui.wizards.feature.AbstractCreateFeatureOperation.createFeature()
@SuppressWarnings("restriction")
public void update(IFeatureModel model, boolean createFeatureInfos) throws CoreException {
FeatureData featureData = getFeatureData();
IFeature feature = model.getFeature();
feature.setLabel(featureData.name);
feature.setId(featureData.id);
feature.setVersion(featureData.version);
feature.setProviderName(featureData.provider);
if (featureData.hasCustomHandler())
feature.setInstallHandler(model.getFactory().createInstallHandler());

IFeatureInstallHandler handler = feature.getInstallHandler();
if (handler != null)
handler.setLibrary(featureData.library);
if (createFeatureInfos) {
IFeatureInfo info = model.getFactory().createInfo(IFeature.INFO_COPYRIGHT);
feature.setFeatureInfo(info, IFeature.INFO_COPYRIGHT);
info.setURL("http://www.example.com/copyright"); //$NON-NLS-1$
info.setDescription(PDEUIMessages.NewFeatureWizard_sampleCopyrightDesc);

info = model.getFactory().createInfo(IFeature.INFO_LICENSE);
feature.setFeatureInfo(info, IFeature.INFO_LICENSE);
info.setURL("http://www.example.com/license"); //$NON-NLS-1$
info.setDescription(PDEUIMessages.NewFeatureWizard_sampleLicenseDesc);

info = model.getFactory().createInfo(IFeature.INFO_DESCRIPTION);
feature.setFeatureInfo(info, IFeature.INFO_DESCRIPTION);
info.setURL("http://www.example.com/description"); //$NON-NLS-1$
info.setDescription(PDEUIMessages.NewFeatureWizard_sampleDescriptionDesc);
}
}

@Override
protected void saveSettings(IDialogSettings settings) {
BundleProviderHistoryUtil.saveHistory(fFeatureProviderCombo, settings);
}
}
Loading

0 comments on commit 89a9b39

Please sign in to comment.