Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2009-11-24 22:47:26 -0500
committerrelves2009-11-24 22:47:26 -0500
commit173d40086f013b834908cb3a828bb78547af243c (patch)
tree727a8a29b5d7327cea551c9db6b271a9b5052db0 /org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn
parentf9d18153b6157adebba197243b96bd651e200c1b (diff)
downloadorg.eclipse.mylyn.tasks-173d40086f013b834908cb3a828bb78547af243c.tar.gz
org.eclipse.mylyn.tasks-173d40086f013b834908cb3a828bb78547af243c.tar.xz
org.eclipse.mylyn.tasks-173d40086f013b834908cb3a828bb78547af243c.zip
NEW - bug 281711: produce Java API for OSLC CM 1.0
https://bugs.eclipse.org/bugs/show_bug.cgi?id=281711
Diffstat (limited to 'org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn')
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/Messages.java32
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcRepositorySettingsPage.java207
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryProvider.java162
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizard.java64
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardDialog.java27
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardPage.java108
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceLabelProvider.java55
-rw-r--r--org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/messages.properties5
8 files changed, 660 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/Messages.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/Messages.java
new file mode 100644
index 000000000..1c0739579
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/Messages.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 Tasktop Technologies.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Tasktop EULA
+ * which accompanies this distribution, and is available at
+ * http://tasktop.com/legal
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.mylyn.oslc.cm.internal.ui.messages"; //$NON-NLS-1$
+
+ public static String OslcRepositorySettingsPage_Enter_Base_Above_And_Validate;
+
+ public static String OslcRepositorySettingsPage_Enter_Base_Url_Above;
+
+ public static String OslcServiceDiscoveryWizardPage_Browse_Available_Services_Below;
+
+ public static String OslcServiceDiscoveryWizardPage_Serivce_Discovery;
+
+ public static String OslcServiceLabelProvider_Loading;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcRepositorySettingsPage.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcRepositorySettingsPage.java
new file mode 100644
index 000000000..afffb804d
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcRepositorySettingsPage.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.window.Window;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.oslc.core.IOslcConnector;
+import org.eclipse.mylyn.internal.oslc.core.IOslcCoreConstants;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Robert Elves
+ */
+public abstract class OslcRepositorySettingsPage extends AbstractRepositorySettingsPage {
+
+ private static final String OSLC_BASEURL = "oslc.baseurl"; //$NON-NLS-1$
+
+ private OslcServiceDescriptor descriptor;
+
+ protected Text baseText;
+
+ public OslcRepositorySettingsPage(String name, String desc, TaskRepository taskRepository) {
+ super(name, desc, taskRepository);
+ setNeedsAnonymousLogin(false);
+ setNeedsEncoding(false);
+ setNeedsTimeZone(false);
+ setNeedsHttpAuth(false);
+ }
+
+ public OslcServiceDescriptor getProvider() {
+ return descriptor;
+ }
+
+ public void setServiceDescriptor(OslcServiceDescriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ protected String getBaseUrl() {
+ return baseText.getText();
+ }
+
+ @Override
+ protected void createSettingControls(Composite parent) {
+
+ Label baseUrlLabel = new Label(parent, SWT.NONE);
+ baseUrlLabel.setText("Base URL:"); //$NON-NLS-1$
+ baseText = new Text(parent, SWT.BORDER);
+ if (repository != null) {
+ String base = repository.getProperty(OSLC_BASEURL);
+ if (base != null) {
+ baseText.setText(base);
+ }
+ }
+ baseText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ serverUrlCombo.setText(baseText.getText());
+ if (getWizard() != null) {
+ getWizard().getContainer().updateButtons();
+ }
+ }
+ });
+
+ GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).span(2, 1).grab(true, false).applyTo(baseText);
+
+ super.createSettingControls(parent);
+ if (serverUrlCombo.getText().length() == 0) {
+ serverUrlCombo.setText(Messages.OslcRepositorySettingsPage_Enter_Base_Url_Above);
+ }
+ serverUrlCombo.setEnabled(false);
+ }
+
+ @Override
+ public abstract String getConnectorKind();
+
+ @Override
+ protected Validator getValidator(TaskRepository repository) {
+ return new OslcValidator(createTaskRepository(), baseText.getText());
+ }
+
+ @Override
+ protected boolean isValidUrl(String url) {
+ if (url.startsWith(URL_PREFIX_HTTPS) || url.startsWith(URL_PREFIX_HTTP)) {
+ try {
+ new URL(url);
+ return true;
+ } catch (MalformedURLException e) {
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void applyTo(TaskRepository repository) {
+ repository.setProperty(OSLC_BASEURL, baseText.getText());
+ super.applyTo(repository);
+ };
+
+ @Override
+ protected void applyValidatorResult(Validator validator) {
+ OslcValidator cqValidator = (OslcValidator) validator;
+
+ if (!cqValidator.getProviders().isEmpty()) {
+ if (repository == null) {
+ repository = createTaskRepository();
+ }
+ OslcServiceDiscoveryWizard oslcWizard = new OslcServiceDiscoveryWizard(((IOslcConnector) connector),
+ cqValidator.getRepository(), cqValidator.getProviders());
+ OslcServiceDiscoveryWizardDialog dialog = new OslcServiceDiscoveryWizardDialog(getShell(), oslcWizard);
+ dialog.setBlockOnOpen(true);
+ dialog.create();
+ int result = dialog.open();
+
+ if (result == Window.OK && oslcWizard.getSelectedServiceDescriptor() != null) {
+ setUrl(oslcWizard.getSelectedServiceDescriptor().getAboutUrl());
+ setServiceDescriptor(oslcWizard.getSelectedServiceDescriptor());
+ } else {
+ cqValidator.setStatus(Status.CANCEL_STATUS);
+ }
+ }
+
+ super.applyValidatorResult(validator);
+ }
+
+ private class OslcValidator extends Validator {
+
+ final TaskRepository repository;
+
+ private List<OslcServiceProvider> providers = new ArrayList<OslcServiceProvider>();
+
+ private final String baseUrl;
+
+ public TaskRepository getRepository() {
+ return this.repository;
+ }
+
+ public OslcValidator(TaskRepository repository, String baseUrl) {
+ this.repository = repository;
+ this.baseUrl = baseUrl;
+ }
+
+ private String getBaseUrl() {
+ return baseUrl;
+ }
+
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ try {
+ new URL(getBaseUrl());
+
+ // TODO: if only one ServiceProviderCatalog/ServiceProvider found, use it
+ List<OslcServiceProvider> serviceProviders = ((IOslcConnector) connector).getAvailableServices(
+ repository, getBaseUrl(), monitor);
+ setProviders(serviceProviders);
+ } catch (MalformedURLException ex) {
+ throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN, IStatus.OK,
+ INVALID_REPOSITORY_URL, null));
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
+ "Error occurred during service discovery", e)); //$NON-NLS-1$
+ }
+
+ }
+
+ private void setProviders(List<OslcServiceProvider> providers) {
+ this.providers = providers;
+ }
+
+ public List<OslcServiceProvider> getProviders() {
+ return providers;
+ }
+
+ }
+
+ @Override
+ protected void createAdditionalControls(Composite parent) {
+ // ignore
+ }
+
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryProvider.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryProvider.java
new file mode 100644
index 000000000..0277ea251
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryProvider.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.oslc.core.IOslcConnector;
+import org.eclipse.mylyn.internal.oslc.core.IOslcCoreConstants;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProviderCatalog;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.ui.progress.DeferredTreeContentManager;
+import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
+import org.eclipse.ui.progress.IElementCollector;
+
+/**
+ * @author Robert Elves
+ */
+public class OslcServiceDiscoveryProvider implements ITreeContentProvider {
+
+ private final IOslcConnector connector;
+
+ private final TaskRepository repository;
+
+ private OslcServiceProvider selectedPovider;
+
+ private DeferredTreeContentManager manager;
+
+ OslcServiceDiscoveryProvider(IOslcConnector connector, TaskRepository repository, String base) {
+ this.connector = connector;
+ this.repository = repository;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return manager.getChildren(parentElement);
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public OslcServiceProvider getOSLServiceProvider() {
+ return selectedPovider;
+ }
+
+ public boolean hasChildren(Object element) {
+ return manager.mayHaveChildren(element);
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof List) {
+ List<OslcServiceProvider> rootProviders = ((List) inputElement);
+ Object[] result = new Object[rootProviders.size()];
+ for (int x = 0; x < rootProviders.size(); x++) {
+ result[x] = new ServiceProviderCatalogWrapper(rootProviders.get(x));
+ }
+ return result;
+ } else {
+ Object[] result = { inputElement };
+ return result;
+ }
+ }
+
+ public void dispose() {
+ // ignore
+ }
+
+ @SuppressWarnings("deprecation")
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (viewer instanceof AbstractTreeViewer) {
+ manager = new DeferredTreeContentManager(null, (AbstractTreeViewer) viewer);
+ }
+ }
+
+ protected class ServiceProviderCatalogWrapper implements IDeferredWorkbenchAdapter {
+ private final Object element;
+
+ public ServiceProviderCatalogWrapper(Object catalog) {
+ this.element = catalog;
+ }
+
+ public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) {
+ try {
+ monitor.beginTask("Loading...", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
+ ServiceProviderCatalogWrapper wrapper = (ServiceProviderCatalogWrapper) object;
+ Object parentElement = wrapper.getServiceObject();
+ if (parentElement instanceof OslcServiceProviderCatalog) {
+ OslcServiceProviderCatalog remoteFolder = (OslcServiceProviderCatalog) parentElement;
+ List<OslcServiceProvider> providers = connector.getAvailableServices(repository,
+ remoteFolder.getUrl(), monitor);
+ for (OslcServiceProvider oslcServiceProvider : providers) {
+ collector.add(new ServiceProviderCatalogWrapper(oslcServiceProvider), monitor);
+ }
+ } else if (parentElement instanceof OslcServiceProvider) {
+ selectedPovider = (OslcServiceProvider) parentElement;
+ OslcServiceDescriptor serviceDescriptor = connector.getServiceDescriptor(repository,
+ selectedPovider, monitor);
+ collector.add(new ServiceProviderCatalogWrapper(serviceDescriptor), monitor);
+// for (OslcCreationDialogDescriptor oslcRecordType : serviceDescriptor.getCreationDialogs()) {
+// collector.add(new ServiceProviderCatalogWrapper(oslcRecordType), monitor);
+// }
+ }
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
+ "Error occurred during service discovery", e)); //$NON-NLS-1$
+ } finally {
+ monitor.done();
+ }
+
+ }
+
+ public ISchedulingRule getRule(Object object) {
+ return null;
+ }
+
+ public boolean isContainer() {
+ return (element instanceof OslcServiceProviderCatalog || element instanceof OslcServiceProvider);
+ }
+
+ public Object[] getChildren(Object o) {
+ return null;
+ }
+
+ public ImageDescriptor getImageDescriptor(Object object) {
+ return null;
+ }
+
+ public String getLabel(Object o) {
+ return null;
+ }
+
+ public Object getParent(Object o) {
+ return null;
+ }
+
+ public Object getServiceObject() {
+ return element;
+ }
+
+ }
+
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizard.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizard.java
new file mode 100644
index 000000000..49c396c86
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizard.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import java.util.List;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.mylyn.internal.oslc.core.IOslcConnector;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+/**
+ * @author Robert Elves
+ */
+public class OslcServiceDiscoveryWizard extends Wizard {
+
+ private final IOslcConnector connector;
+
+ private final TaskRepository repository;
+
+ private OslcServiceDiscoveryWizardPage page;
+
+ private final List<OslcServiceProvider> providers;
+
+ public OslcServiceDiscoveryWizard(IOslcConnector connector, TaskRepository repository,
+ List<OslcServiceProvider> providers) {
+ setNeedsProgressMonitor(true);
+ this.connector = connector;
+ this.repository = repository;
+ this.providers = providers;
+ }
+
+ @Override
+ public boolean performFinish() {
+ return true;
+ }
+
+ @Override
+ public void addPages() {
+ page = new OslcServiceDiscoveryWizardPage(connector, repository);
+ page.setRootProviders(providers);
+ addPage(page);
+ }
+
+ @Override
+ public boolean canFinish() {
+ return (page.getSelectedServiceProvider() != null);
+ }
+
+ public OslcServiceDescriptor getSelectedServiceDescriptor() {
+ return page.getSelectedServiceProvider();
+ }
+
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardDialog.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardDialog.java
new file mode 100644
index 000000000..645abd9be
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardDialog.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author Robert Elves
+ */
+public class OslcServiceDiscoveryWizardDialog extends WizardDialog {
+
+ public OslcServiceDiscoveryWizardDialog(Shell parentShell, IWizard newWizard) {
+ super(parentShell, newWizard);
+ }
+
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardPage.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardPage.java
new file mode 100644
index 000000000..713aed688
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceDiscoveryWizardPage.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import java.util.List;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.mylyn.internal.oslc.core.IOslcConnector;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProviderCatalog;
+import org.eclipse.mylyn.internal.oslc.ui.OslcServiceDiscoveryProvider.ServiceProviderCatalogWrapper;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Robert Elves
+ */
+public class OslcServiceDiscoveryWizardPage extends WizardPage {
+
+ private static final String TITLE_SERVICE_DISCOVERY = Messages.OslcServiceDiscoveryWizardPage_Serivce_Discovery;
+
+ private TreeViewer v;
+
+ private OslcServiceDescriptor selectedServiceDescriptor;
+
+ private final TaskRepository repository;
+
+ private final OslcServiceDiscoveryProvider provider;
+
+ private List<OslcServiceProvider> rootProviders;
+
+ protected OslcServiceDiscoveryWizardPage(IOslcConnector connector, TaskRepository repository) {
+ super(TITLE_SERVICE_DISCOVERY, TITLE_SERVICE_DISCOVERY, TasksUiImages.BANNER_REPOSITORY);
+ this.repository = repository;
+ this.provider = new OslcServiceDiscoveryProvider(connector, repository, null);
+ setMessage(Messages.OslcServiceDiscoveryWizardPage_Browse_Available_Services_Below);
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1, true));
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
+
+ v = new TreeViewer(composite, SWT.VIRTUAL | SWT.BORDER);
+ v.setUseHashlookup(true);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(v.getTree());
+
+ v.setLabelProvider(new OslcServiceLabelProvider());
+ v.setContentProvider(provider);
+ v.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ TreeSelection selection = (TreeSelection) v.getSelection();
+ Object o = selection.getFirstElement();
+ if (o instanceof ServiceProviderCatalogWrapper) {
+ Object provObj = ((ServiceProviderCatalogWrapper) o).getServiceObject();
+ if (provObj instanceof OslcServiceProviderCatalog) {
+ setSelectedServiceDescriptor(null);
+ } else if (provObj instanceof OslcServiceProvider) {
+ setSelectedServiceDescriptor(null);
+ } else if (provObj instanceof OslcServiceDescriptor) {
+ setSelectedServiceDescriptor((OslcServiceDescriptor) provObj);
+ }
+ } else {
+ // TODO: disable OK button
+ }
+ }
+ });
+ if (rootProviders != null && !rootProviders.isEmpty()) {
+ v.setInput(rootProviders);
+ } else {
+ v.setInput(new OslcServiceProviderCatalog(repository.getRepositoryLabel(), repository.getUrl()));
+ }
+ setControl(composite);
+ }
+
+ private void setSelectedServiceDescriptor(OslcServiceDescriptor selectedServiceDescriptor) {
+ this.selectedServiceDescriptor = selectedServiceDescriptor;
+ setPageComplete(selectedServiceDescriptor != null);
+ }
+
+ public OslcServiceDescriptor getSelectedServiceProvider() {
+ return selectedServiceDescriptor;
+ }
+
+ public void setRootProviders(List<OslcServiceProvider> providers) {
+ this.rootProviders = providers;
+ }
+
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceLabelProvider.java b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceLabelProvider.java
new file mode 100644
index 000000000..7a53da4eb
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/OslcServiceLabelProvider.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.oslc.ui;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.mylyn.internal.oslc.core.OslcCreationDialogDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
+import org.eclipse.mylyn.internal.oslc.core.OslcServiceProviderCatalog;
+import org.eclipse.mylyn.internal.oslc.ui.OslcServiceDiscoveryProvider.ServiceProviderCatalogWrapper;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Robert Elves
+ */
+public class OslcServiceLabelProvider extends LabelProvider {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof OslcServiceProvider) {
+ return ((OslcServiceProvider) element).getName();
+ } else if (element instanceof OslcCreationDialogDescriptor) {
+ return ((OslcCreationDialogDescriptor) element).getTitle();
+ } else if (element instanceof OslcServiceDescriptor) {
+ return ((OslcServiceDescriptor) element).getDescription();
+ } else if (element instanceof ServiceProviderCatalogWrapper) {
+ return this.getText(((ServiceProviderCatalogWrapper) element).getServiceObject());
+ } else {
+ return Messages.OslcServiceLabelProvider_Loading;
+ }
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof OslcServiceProviderCatalog) {
+ return CommonImages.getImage(TasksUiImages.REPOSITORIES_VIEW);
+ } else if (element instanceof OslcServiceProvider) {
+ return CommonImages.getImage(TasksUiImages.REPOSITORY);
+ } else if (element instanceof ServiceProviderCatalogWrapper) {
+ return this.getImage(((ServiceProviderCatalogWrapper) element).getServiceObject());
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/messages.properties b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/messages.properties
new file mode 100644
index 000000000..f5cea0e68
--- /dev/null
+++ b/org.eclipse.mylyn.oslc.ui/src/org/eclipse/mylyn/internal/oslc/ui/messages.properties
@@ -0,0 +1,5 @@
+OslcRepositorySettingsPage_Enter_Base_Url_Above=Enter base url above and press Validate Settings
+OslcRepositorySettingsPage_Enter_Base_Above_And_Validate=Enter base url above and press Validate Settings
+OslcServiceDiscoveryWizardPage_Browse_Available_Services_Below=Browse the available services below.
+OslcServiceDiscoveryWizardPage_Serivce_Discovery=Service Discovery
+OslcServiceLabelProvider_Loading=Loading... \ No newline at end of file

Back to the top