Skip to content

Commit

Permalink
Adapt template classes to PDE codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 17, 2024
1 parent c26035b commit 205982c
Show file tree
Hide file tree
Showing 34 changed files with 566 additions and 417 deletions.
23 changes: 18 additions & 5 deletions ui/org.eclipse.pde.bnd.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,32 @@ Import-Package: aQute.bnd.build;version="4.5.0",
aQute.bnd.build.model.clauses;version="2.5.0",
aQute.bnd.exceptions;version="3.0.0",
aQute.bnd.header;version="2.6.0",
aQute.bnd.osgi,
aQute.bnd.http;version="2.0.0",
aQute.bnd.osgi;version="[7.0.0,8.0.0)",
aQute.bnd.osgi.resource;version="[5.0.0,6)",
aQute.bnd.repository.osgi;version="[1.1.1,2)",
aQute.bnd.result;version="2.0.0",
jakarta.xml.bind;version="4.0.1",
jakarta.xml.bind.annotation;version="4.0.1"
aQute.bnd.service;version="4.8.0",
aQute.service.reporter;version="[1.2.0,2.0.0)",
jakarta.xml.bind;version="[4.0.0,5.0.0)",
jakarta.xml.bind.annotation;version="[4.0.0,5.0.0)",
org.bndtools.templating;version="[2.0.0,3.0.0)",
org.bndtools.templating.util;version="[1.0.0,2.0.0)",
org.osgi.service.metatype;version="[1.4.1,2)",
org.osgi.service.repository;version="[1.1.0,2.0.0)",
org.osgi.util.function;version="[1.2.0,2)",
org.osgi.util.promise;version="[1.3.0,2.0.0)"
Require-Bundle: org.eclipse.jdt.ui,
org.eclipse.jdt.core,
org.eclipse.core.resources,
org.eclipse.core.runtime;bundle-version="3.30.0",
org.eclipse.jface.text,
org.eclipse.swt,
org.eclipse.jface
org.eclipse.jface,
org.eclipse.ui.workbench
Automatic-Module-Name: org.eclipse.pde.bnd.ui
Bundle-Activator: org.eclipse.pde.bnd.ui.Resources
Bundle-RequiredExecutionEnvironment: JavaSE-17
Service-Component: OSGI-INF/org.eclipse.pde.bnd.ui.internal.Auxiliary.xml
Service-Component: OSGI-INF/org.bndtools.templating.repos.xml,
OSGI-INF/org.eclipse.pde.bnd.ui.internal.Auxiliary.xml
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package org.bndtools.utils.swt;
package org.eclipse.pde.bnd.ui;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package org.bndtools.utils.jface;
package org.eclipse.pde.bnd.ui;

import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.ColorRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package bndtools.shared;
package org.eclipse.pde.bnd.ui;

import org.eclipse.jface.viewers.StyledString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ public void stop(BundleContext context) throws Exception {
disposeResources();
}

public synchronized static Image getImage(String key) {
public synchronized static ImageDescriptor getImageDescriptor(String key) {
ImageRegistry registry = getImageRegistry();
if (registry.getDescriptor(key) == null) {
registry.put(key, ImageDescriptor.createFromURL(Resources.class.getResource(key)));
ImageDescriptor descriptor = registry.getDescriptor(key);
if (descriptor == null) {
ImageDescriptor fromURL = ImageDescriptor.createFromURL(Resources.class.getResource(key));
registry.put(key, fromURL);
return fromURL;
}
return descriptor;
}

public synchronized static Image getImage(String key) {
ImageRegistry registry = getImageRegistry();
getImageDescriptor(key); // make sure the descriptor is added!
return registry.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Neil Bartlett <[email protected]> - ongoing enhancements
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package bndtools.shared;
package org.eclipse.pde.bnd.ui;

import java.io.File;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2021 bndtools project and others.
* Copyright (c) 2010, 2023 bndtools project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,22 +12,19 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
* Peter Kriens <[email protected]> - ongoing enhancements
* Christoph Läubrich - adapt to PDE code base
*******************************************************************************/
package bndtools.shared;
package org.eclipse.pde.bnd.ui;

import org.bndtools.core.ui.icons.Icons;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;

public class URLLabelProvider extends StyledCellLabelProvider {

private final static Image linkImg = Icons.image("link");
private final static Image fileImg = Icons.image("file");

public URLLabelProvider(Device display) {}
private final static Image linkImg = Resources.getImage("/icons/link.png");
private final static Image fileImg = Resources.getImage("/icon/file.png");

@Override
public void update(ViewerCell cell) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich 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:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.bnd.ui.preferences;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public interface ReposPreference {

public static final String KEY_TEMPLATE_REPO_URI_LIST = "templateRepoUriList";

public static final boolean DEF_ENABLE_TEMPLATE_REPOSITORIES = false;

public static final String KEY_ENABLE_TEMPLATE_REPOSITORIES = "enableTemplateRepositories";

public static final String TEMPLATE_LOADER_NODE = "repoTemplateLoader";

public static final Function<String, List<String>> TEMPLATE_REPOSITORIES_PARSER = s -> s == null || s.isBlank()
? List.of()
: Arrays.asList(s.split("\\s"));
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2019 bndtools project and others.
* Copyright (c) 2015, 2023 bndtools project and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,22 +12,28 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* Sean Bright <[email protected]> - ongoing enhancements
* BJ Hargrave <[email protected]> - ongoing enhancements
* Christoph Läubrich - adapt to PDE code base
*******************************************************************************/
package bndtools.preferences.ui;
package org.eclipse.pde.bnd.ui.preferences;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.bndtools.utils.swt.AddRemoveButtonBarPart;
import org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.pde.bnd.ui.AddRemoveButtonBarPart;
import org.eclipse.pde.bnd.ui.AddRemoveButtonBarPart.AddRemoveListener;
import org.eclipse.pde.bnd.ui.URLDialog;
import org.eclipse.pde.bnd.ui.URLLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
Expand All @@ -43,23 +49,26 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.prefs.BackingStoreException;

import bndtools.preferences.BndPreferences;
import bndtools.shared.URLDialog;
import bndtools.shared.URLLabelProvider;

public class ReposPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
public class ReposPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ReposPreference {

private static final String REPO_DEFAULT = "https://raw.githubusercontent.com/bndtools/bundle-hub/master/index.xml.gz";
private boolean enableTemplateRepo;
private List<String> templateRepos;
private TableViewer vwrRepos;
private IEclipsePreferences preferences;

@Override
public void init(IWorkbench workbench) {
BndPreferences prefs = new BndPreferences();

enableTemplateRepo = prefs.getEnableTemplateRepo();
templateRepos = new ArrayList<>(prefs.getTemplateRepoUriList());
preferences = (IEclipsePreferences) InstanceScope.INSTANCE
.getNode(FrameworkUtil.getBundle(ReposPreferencePage.class).getSymbolicName())
.node(TEMPLATE_LOADER_NODE);
enableTemplateRepo = preferences.getBoolean(KEY_ENABLE_TEMPLATE_REPOSITORIES, DEF_ENABLE_TEMPLATE_REPOSITORIES);
templateRepos = TEMPLATE_REPOSITORIES_PARSER.apply(preferences.get(KEY_TEMPLATE_REPO_URI_LIST,
REPO_DEFAULT));
}

@Override
Expand Down Expand Up @@ -96,7 +105,7 @@ protected Control createContents(Composite parent) {
final Table tblRepos = new Table(group, SWT.BORDER | SWT.MULTI);
vwrRepos = new TableViewer(tblRepos);
vwrRepos.setContentProvider(ArrayContentProvider.getInstance());
vwrRepos.setLabelProvider(new URLLabelProvider(tblRepos.getDisplay()));
vwrRepos.setLabelProvider(new URLLabelProvider());
vwrRepos.setInput(templateRepos);

GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
Expand Down Expand Up @@ -185,11 +194,22 @@ private void validate() {

@Override
public boolean performOk() {
BndPreferences prefs = new BndPreferences();

prefs.setEnableTemplateRepo(enableTemplateRepo);
prefs.setTemplateRepoUriList(templateRepos);

String repoList = templateRepos.stream().collect(Collectors.joining("\t"));
if (enableTemplateRepo == DEF_ENABLE_TEMPLATE_REPOSITORIES) {
preferences.remove(KEY_ENABLE_TEMPLATE_REPOSITORIES);
if (REPO_DEFAULT.equals(repoList)) {
preferences.remove(KEY_TEMPLATE_REPO_URI_LIST);
} else {
preferences.put(KEY_TEMPLATE_REPO_URI_LIST, repoList);
}
} else {
preferences.putBoolean(KEY_ENABLE_TEMPLATE_REPOSITORIES, enableTemplateRepo);
preferences.put(KEY_TEMPLATE_REPO_URI_LIST, repoList);
}
try {
preferences.flush();
} catch (BackingStoreException e) {
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* Scott Lewis <[email protected]> - initial API and implementation
*******************************************************************************/
package org.bndtools.core.ui.wizards.shared;
package org.eclipse.pde.bnd.ui.templating;

import java.net.URL;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package org.bndtools.core.ui.wizards.shared;
package org.eclipse.pde.bnd.ui.templating;

import java.io.IOException;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Neil Bartlett <[email protected]> - initial API and implementation
* BJ Hargrave <[email protected]> - ongoing enhancements
*******************************************************************************/
package org.bndtools.core.templating.repobased;
package org.eclipse.pde.bnd.ui.templating;

import java.io.File;
import java.net.URI;
Expand Down
Loading

0 comments on commit 205982c

Please sign in to comment.