Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 110475 Details for
Bug 244653
[api] extension for repository properties wizard page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
a first draft of an extension point and implementation
mylyn.tasksui.extensible-task-repository-settings.patch (text/plain), 36.95 KB, created by
David Green
on 2008-08-20 13:40:24 EDT
(
hide
)
Description:
a first draft of an extension point and implementation
Filename:
MIME Type:
Creator:
David Green
Created:
2008-08-20 13:40:24 EDT
Size:
36.95 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.tasks.ui >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java,v >retrieving revision 1.31 >diff -u -r1.31 EditRepositoryWizard.java >--- src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java 15 May 2008 06:53:13 -0000 1.31 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java 20 Aug 2008 17:35:41 -0000 >@@ -15,6 +15,7 @@ > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.wizard.Wizard; > import org.eclipse.mylyn.commons.core.StatusHandler; >+import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector; > import org.eclipse.mylyn.internal.tasks.ui.RefactorRepositoryUrlOperation; > import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; > import org.eclipse.mylyn.tasks.core.TaskRepository; >@@ -68,7 +69,9 @@ > > repository.flushAuthenticationCredentials(); > >- repository.setRepositoryUrl(newUrl); >+ if (!repository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND)) { >+ repository.setRepositoryUrl(newUrl); >+ } > settingsPage.applyTo(repository); > if (oldUrl != null && newUrl != null && !oldUrl.equals(newUrl)) { > TasksUiPlugin.getRepositoryManager().notifyRepositoryUrlChanged(repository, oldUrl); >@@ -86,7 +89,7 @@ > @Override > public void addPages() { > AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(repository.getConnectorKind()); >- settingsPage = connectorUi.getSettingsPage(null); >+ settingsPage = connectorUi.getSettingsPage(repository); > if (settingsPage instanceof AbstractRepositorySettingsPage) { > ((AbstractRepositorySettingsPage) settingsPage).setRepository(repository); > ((AbstractRepositorySettingsPage) settingsPage).setVersion(repository.getVersion()); >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/plugin.xml,v >retrieving revision 1.338 >diff -u -r1.338 plugin.xml >--- plugin.xml 11 Aug 2008 23:22:48 -0000 1.338 >+++ plugin.xml 20 Aug 2008 17:35:41 -0000 >@@ -7,6 +7,7 @@ > <extension-point id="projectLinkProviders" name="Linking Provider from Project to the Task Repository" schema="schema/projectLinkProviders.exsd"/> > <extension-point id="duplicateDetectors" name="duplicateDetectors" schema="schema/duplicateDetectors.exsd"/> > <extension-point id="presentations" name="presentations" schema="schema/presentations.exsd"/> >+ <extension-point id="taskRepositoryPageContributor" name="Task Repository Page Contributor" schema="schema/taskRepositoryPageContributor.exsd"/> > > <extension > point="org.eclipse.mylyn.context.core.bridges"> >Index: src/org/eclipse/mylyn/internal/tasks/ui/LocalRepositoryConnectorUi.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/LocalRepositoryConnectorUi.java,v >retrieving revision 1.1 >diff -u -r1.1 LocalRepositoryConnectorUi.java >--- src/org/eclipse/mylyn/internal/tasks/ui/LocalRepositoryConnectorUi.java 26 May 2008 20:38:20 -0000 1.1 >+++ src/org/eclipse/mylyn/internal/tasks/ui/LocalRepositoryConnectorUi.java 20 Aug 2008 17:35:41 -0000 >@@ -11,6 +11,7 @@ > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.wizard.IWizard; > import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector; >+import org.eclipse.mylyn.internal.tasks.ui.wizards.LocalRepositorySettingsPage; > import org.eclipse.mylyn.internal.tasks.ui.wizards.NewLocalTaskWizard; > import org.eclipse.mylyn.tasks.core.IRepositoryQuery; > import org.eclipse.mylyn.tasks.core.ITask; >@@ -47,7 +48,7 @@ > > @Override > public ITaskRepositoryPage getSettingsPage(TaskRepository taskRepository) { >- return null; >+ return new LocalRepositorySettingsPage(taskRepository); > } > > @Override >Index: src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContributor.java >=================================================================== >RCS file: src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContributor.java >diff -N src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContributor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContributor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.tasks.ui.wizards; >+ >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+ >+/** >+ * Implementors are capable of contributing to the settings page for a task repository. >+ * >+ * @author David Green >+ */ >+public interface ITaskRepositoryPageContributor { >+ /** >+ * create a contribution to a task repository >+ * >+ * @param repository >+ * the repository for which contributions are desired >+ * >+ * @return the contribution, or null if the contributor should not contribute to the given repository >+ */ >+ ITaskRepositoryPageContribution createContribution(TaskRepository repository); >+} >Index: src/org/eclipse/mylyn/tasks/ui/wizards/AbstractTaskRepositoryPageContribution.java >=================================================================== >RCS file: src/org/eclipse/mylyn/tasks/ui/wizards/AbstractTaskRepositoryPageContribution.java >diff -N src/org/eclipse/mylyn/tasks/ui/wizards/AbstractTaskRepositoryPageContribution.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/tasks/ui/wizards/AbstractTaskRepositoryPageContribution.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.tasks.ui.wizards; >+ >+import java.util.List; >+import java.util.concurrent.CopyOnWriteArrayList; >+ >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+ >+public abstract class AbstractTaskRepositoryPageContribution implements ITaskRepositoryPageContribution { >+ >+ private final List<Listener> listeners = new CopyOnWriteArrayList<Listener>(); >+ >+ private final String title; >+ >+ private final String description; >+ >+ protected final TaskRepository repository; >+ >+ protected AbstractTaskRepositoryPageContribution(String title, String description, TaskRepository repository) { >+ this.title = title; >+ this.description = description; >+ this.repository = repository; >+ } >+ >+ public void addListener(Listener listener) { >+ listeners.add(listener); >+ } >+ >+ public String getDescription() { >+ return description; >+ } >+ >+ public String getTitle() { >+ return title; >+ } >+ >+ public void removeListener(Listener listener) { >+ listeners.remove(listener); >+ } >+ >+ protected void fireValidationRequired() { >+ for (Listener l : listeners) { >+ l.validationRequired(this); >+ } >+ } >+} >Index: src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContribution.java >=================================================================== >RCS file: src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContribution.java >diff -N src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContribution.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPageContribution.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,99 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.tasks.ui.wizards; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jface.dialogs.IDialogPage; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.ui.forms.widgets.FormToolkit; >+ >+/** >+ * A contribution to a {@link ITaskRepositoryPage} >+ * >+ * @see ITaskRepositoryPageContributor >+ * >+ * @author David Green >+ */ >+public interface ITaskRepositoryPageContribution { >+ /** >+ * a listener interface that should be implemented by classes wishing to be notified of changes that occur within >+ * the contribution >+ */ >+ public interface Listener { >+ /** >+ * Called when the state of the contribution changes such that validation should be performed >+ * >+ * @param contribution >+ * the contribution that changed >+ * >+ * @see ITaskRepositoryPageContribution#validate(IProgressMonitor) >+ */ >+ public void validationRequired(ITaskRepositoryPageContribution contribution); >+ } >+ >+ /** >+ * add a listener to this contribution. The contribution must notify the listener at the appropriate times >+ * >+ * @see #removeListener(Listener) >+ */ >+ public void addListener(Listener listener); >+ >+ /** >+ * remove a listener from this contribution. >+ * >+ * @see #addListener(Listener) >+ */ >+ public void removeListener(Listener listener); >+ >+ /** >+ * @see IDialogPage#createControl(Composite) >+ */ >+ public void createControl(Composite parent, FormToolkit toolkit); >+ >+ /** >+ * @see IDialogPage#getTitle() >+ */ >+ public String getTitle(); >+ >+ /** >+ * @see IDialogPage#getDescription() >+ */ >+ public String getDescription(); >+ >+ /** >+ * @see IWizardPage#isPageComplete() >+ */ >+ public boolean isPageComplete(); >+ >+ /** >+ * @see IWizardPage#canFlipToNextPage() >+ */ >+ public boolean canFlipToNextPage(); >+ >+ /** >+ * Validate the settings of the contribution. Contributions should expect this method to be called often and should >+ * thus return quickly. >+ * >+ * @return a list of errors on the contribution, or null if there are none >+ */ >+ public IStatus[] validate(IProgressMonitor monitor); >+ >+ /** >+ * Apply the settings in the contribution to the given repository. >+ * >+ * @param repository >+ * the repository to which settings should be applied >+ * >+ * @see ITaskRepositoryPage#applyTo(TaskRepository) >+ */ >+ public void applyTo(TaskRepository repository); >+} >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/LocalRepositorySettingsPage.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/wizards/LocalRepositorySettingsPage.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/wizards/LocalRepositorySettingsPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/LocalRepositorySettingsPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.tasks.ui.wizards; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.swt.widgets.Composite; >+ >+public class LocalRepositorySettingsPage extends AbstractExtensibleRepositorySettingsPage { >+ >+ public LocalRepositorySettingsPage(TaskRepository taskRepository) { >+ super("Local Repository Settings", "Configure the local repository", taskRepository); >+ } >+ >+ public String getRepositoryUrl() { >+ return null; >+ } >+ >+ @Override >+ protected void applyPageSettingsTo(TaskRepository repository) { >+ // nothing to do >+ } >+ >+ @Override >+ protected void createSettingControls(Composite parent) { >+ // nothing to do >+ } >+ >+ @Override >+ protected IStatus[] validate(IProgressMonitor monitor) { >+ // nothing to do >+ return null; >+ } >+ >+} >Index: schema/taskRepositoryPageContributor.exsd >=================================================================== >RCS file: schema/taskRepositoryPageContributor.exsd >diff -N schema/taskRepositoryPageContributor.exsd >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ schema/taskRepositoryPageContributor.exsd 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.mylyn.tasks.ui" xmlns="http://www.w3.org/2001/XMLSchema"> >+<annotation> >+ <appinfo> >+ <meta.schema plugin="org.eclipse.mylyn.tasks.ui" id="taskRepositoryPageContributor" name="Task Repository Page Contributor"/> >+ </appinfo> >+ <documentation> >+ [Enter description of this extension point.] >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <annotation> >+ <appinfo> >+ <meta.element /> >+ </appinfo> >+ </annotation> >+ <complexType> >+ <sequence> >+ <element ref="taskRepositoryPageContributor" minOccurs="1" maxOccurs="unbounded"/> >+ </sequence> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appinfo> >+ <meta.attribute translatable="true"/> >+ </appinfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="taskRepositoryPageContributor"> >+ <complexType> >+ <attribute name="class" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appinfo> >+ <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContributor"/> >+ </appinfo> >+ </annotation> >+ </attribute> >+ <attribute name="connectorKind" type="string" use="required"> >+ <annotation> >+ <documentation> >+ the kind of repository connector for which this contributor should be used, or "*" if it applies to all connectors >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="since"/> >+ </appinfo> >+ <documentation> >+ [Enter the first release in which this extension point appears.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="examples"/> >+ </appinfo> >+ <documentation> >+ [Enter extension point usage example here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="apiinfo"/> >+ </appinfo> >+ <documentation> >+ [Enter API information here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appinfo> >+ <meta.section type="implementation"/> >+ </appinfo> >+ <documentation> >+ [Enter information about supplied implementation of this extension point.] >+ </documentation> >+ </annotation> >+ >+ >+</schema> >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractExtensibleRepositorySettingsPage.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractExtensibleRepositorySettingsPage.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractExtensibleRepositorySettingsPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractExtensibleRepositorySettingsPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,327 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.tasks.ui.wizards; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.Comparator; >+import java.util.List; >+ >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtension; >+import org.eclipse.core.runtime.IExtensionPoint; >+import org.eclipse.core.runtime.IExtensionRegistry; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jface.dialogs.IMessageProvider; >+import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.mylyn.commons.core.StatusHandler; >+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContribution; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContributor; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContribution.Listener; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.ui.forms.events.ExpansionAdapter; >+import org.eclipse.ui.forms.events.ExpansionEvent; >+import org.eclipse.ui.forms.widgets.ExpandableComposite; >+import org.eclipse.ui.forms.widgets.FormToolkit; >+ >+public abstract class AbstractExtensibleRepositorySettingsPage extends WizardPage implements ITaskRepositoryPage { >+ >+ private static final String KIND = "connectorKind"; >+ >+ private static final String TASK_REPOSITORY_PAGE_CONTRIBUTOR = "taskRepositoryPageContributor"; >+ >+ private static final String TASK_REPOSITORY_PAGE_CONTRIBUTOR_EXTENSION = "org.eclipse.mylyn.tasks.ui.taskRepositoryPageContributor"; >+ >+ private static final Comparator<ITaskRepositoryPageContribution> CONTRIBUTION_COMPARATOR = new ContributionComparator(); >+ >+ protected final TaskRepository repository; >+ >+ private final List<ITaskRepositoryPageContribution> contributions = new ArrayList<ITaskRepositoryPageContribution>(); >+ >+ protected FormToolkit toolkit; >+ >+ protected Composite compositeContainer; >+ >+ private final Listener contributionListener = new ITaskRepositoryPageContribution.Listener() { >+ public void validationRequired(ITaskRepositoryPageContribution contribution) { >+ validateSettings(); >+ } >+ }; >+ >+ public AbstractExtensibleRepositorySettingsPage(String title, String description, TaskRepository repository) { >+ super(title); >+ this.repository = repository; >+ setTitle(title); >+ setDescription(description); >+ } >+ >+ public void createControl(Composite parent) { >+ toolkit = new FormToolkit(TasksUiPlugin.getDefault().getFormColors(parent.getDisplay())); >+ >+ compositeContainer = new Composite(parent, SWT.NULL); >+ GridLayout layout = new GridLayout(1, true); >+ compositeContainer.setLayout(layout); >+ >+ createSettingControls(compositeContainer); >+ >+ addContributions(compositeContainer); >+ >+ setControl(compositeContainer); >+ } >+ >+ /** >+ * create the controls of this page >+ */ >+ protected abstract void createSettingControls(Composite parent); >+ >+ @Override >+ public boolean isPageComplete() { >+ return super.isPageComplete() && conributionsIsPageComplete(); >+ } >+ >+ @Override >+ public boolean canFlipToNextPage() { >+ return super.canFlipToNextPage() && contributionsCanFlipToNextPage(); >+ } >+ >+ private boolean contributionsCanFlipToNextPage() { >+ for (ITaskRepositoryPageContribution contribution : contributions) { >+ if (!contribution.canFlipToNextPage()) { >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ private boolean conributionsIsPageComplete() { >+ for (ITaskRepositoryPageContribution contribution : contributions) { >+ if (!contribution.isPageComplete()) { >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ protected void addContributions(Composite parentControl) { >+ List<ITaskRepositoryPageContributor> contributors = findApplicableContributors(); >+ for (ITaskRepositoryPageContributor contributor : contributors) { >+ ITaskRepositoryPageContribution contribution = contributor.createContribution(repository); >+ if (contribution != null) { >+ contributions.add(contribution); >+ contribution.addListener(contributionListener); >+ } >+ } >+ if (!contributions.isEmpty()) { >+ Collections.sort(contributions, CONTRIBUTION_COMPARATOR); >+ >+ for (ITaskRepositoryPageContribution contribution : contributions) { >+ >+ ExpandableComposite section = toolkit.createExpandableComposite(compositeContainer, >+ ExpandableComposite.COMPACT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); >+ section.clientVerticalSpacing = 0; >+ section.setBackground(parentControl.getBackground()); >+ section.setFont(parentControl.getFont()); >+ section.addExpansionListener(new ExpansionAdapter() { >+ @Override >+ public void expansionStateChanged(ExpansionEvent e) { >+ getControl().getShell().pack(); >+ } >+ }); >+ section.setText(contribution.getTitle()); >+ section.setToolTipText(contribution.getDescription()); >+ >+ GridDataFactory.fillDefaults().grab(true, false).applyTo(section); >+ >+ Composite sectionContentsContainer = toolkit.createComposite(section); >+ sectionContentsContainer.setBackground(parentControl.getBackground()); >+ contribution.createControl(sectionContentsContainer, toolkit); >+ >+ section.setClient(sectionContentsContainer); >+ } >+ } >+ } >+ >+ /** >+ * Validate the settings of this page, not including contributions. This method should not be called directly by >+ * page implementations >+ * >+ * @return an array of statuses, or null if there are no messages. >+ * >+ * @see #validateSettings() >+ */ >+ protected abstract IStatus[] validate(IProgressMonitor monitor); >+ >+ public final void applyTo(TaskRepository repository) { >+ applyPageSettingsTo(repository); >+ applyContributionSettingsTo(repository); >+ } >+ >+ private void applyContributionSettingsTo(TaskRepository repository) { >+ for (ITaskRepositoryPageContribution contribution : contributions) { >+ contribution.applyTo(repository); >+ } >+ } >+ >+ /** >+ * apply the page settings to the repository. >+ * >+ * @see ITaskRepositoryPage#applyTo(TaskRepository) >+ */ >+ protected abstract void applyPageSettingsTo(TaskRepository repository); >+ >+ private IStatus[] computeValidation(IProgressMonitor monitor) { >+ int factor = 100; >+ monitor.beginTask("Validating settings", (contributions.size() + 1) * factor); >+ >+ List<IStatus> statuses = null; >+ >+ // validate the page >+ { >+ SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, factor); >+ IStatus[] result = validate(subMonitor); >+ if (result != null && result.length > 0) { >+ if (statuses == null) { >+ statuses = new ArrayList<IStatus>(result.length); >+ } >+ statuses.addAll(Arrays.asList(result)); >+ } >+ subMonitor.done(); >+ } >+ >+ // validate contributions >+ for (ITaskRepositoryPageContribution contribution : contributions) { >+ SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, factor); >+ IStatus[] result = contribution.validate(subMonitor); >+ if (result != null && result.length > 0) { >+ if (statuses == null) { >+ statuses = new ArrayList<IStatus>(result.length); >+ } >+ statuses.addAll(Arrays.asList(result)); >+ } >+ subMonitor.done(); >+ } >+ monitor.done(); >+ return statuses == null ? null : statuses.toArray(new IStatus[statuses.size()]); >+ } >+ >+ /** >+ * Validate all settings in the page including contributions. This method should be called whenever a setting is >+ * changed on the page. >+ * >+ * @see #validate(IProgressMonitor) >+ */ >+ protected void validateSettings() { >+ final Object[] result = new Object[1]; >+ try { >+ getWizard().getContainer().run(true, true, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >+ result[0] = computeValidation(monitor); >+ } >+ }); >+ } catch (InvocationTargetException e) { >+ StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, >+ "Internal error validating repository", e.getCause())); >+ return; >+ } catch (InterruptedException e) { >+ // canceled >+ return; >+ } >+ applyValidationResult((IStatus[]) result[0]); >+ getWizard().getContainer().updateButtons(); >+ } >+ >+ protected void applyValidationResult(IStatus[] statuses) { >+ if (statuses == null || statuses.length == 0) { >+ setMessage(null, IMessageProvider.INFORMATION); >+ setErrorMessage(null); >+ } else { >+ // find the most severe status >+ IStatus status = statuses[0]; >+ for (IStatus s : statuses) { >+ if (status == null || s.getSeverity() > status.getSeverity()) { >+ status = s; >+ } >+ } >+ int messageType; >+ switch (status.getSeverity()) { >+ case IStatus.OK: >+ case IStatus.INFO: >+ messageType = IMessageProvider.INFORMATION; >+ break; >+ case IStatus.WARNING: >+ messageType = IMessageProvider.WARNING; >+ break; >+ case IStatus.ERROR: >+ default: >+ messageType = IMessageProvider.ERROR; >+ break; >+ } >+ setErrorMessage(null); >+ setMessage(status.getMessage(), messageType); >+ } >+ } >+ >+ private List<ITaskRepositoryPageContributor> findApplicableContributors() { >+ List<ITaskRepositoryPageContributor> contributors = new ArrayList<ITaskRepositoryPageContributor>(); >+ >+ IExtensionRegistry registry = Platform.getExtensionRegistry(); >+ >+ IExtensionPoint editorExtensionPoint = registry.getExtensionPoint(TASK_REPOSITORY_PAGE_CONTRIBUTOR_EXTENSION); >+ IExtension[] editorExtensions = editorExtensionPoint.getExtensions(); >+ for (IExtension extension : editorExtensions) { >+ IConfigurationElement[] elements = extension.getConfigurationElements(); >+ for (IConfigurationElement element : elements) { >+ if (element.getName().equals(TASK_REPOSITORY_PAGE_CONTRIBUTOR)) { >+ String kind = element.getAttribute(KIND); >+ if ("*".equals(kind) || repository.getConnectorKind().equals(kind)) { >+ try { >+ Object contributor = element.createExecutableExtension("class"); >+ contributors.add((ITaskRepositoryPageContributor) contributor); >+ } catch (Exception e) { >+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not load " >+ + TASK_REPOSITORY_PAGE_CONTRIBUTOR, e)); >+ } >+ } >+ } >+ } >+ } >+ >+ return contributors; >+ } >+ >+ private static class ContributionComparator implements Comparator<ITaskRepositoryPageContribution> { >+ >+ public int compare(ITaskRepositoryPageContribution o1, ITaskRepositoryPageContribution o2) { >+ if (o1 == o2) { >+ return 0; >+ } >+ String s1 = o1.getTitle(); >+ String s2 = o2.getTitle(); >+ int i = s1.compareTo(s2); >+ if (i == 0) { >+ i = new Integer(System.identityHashCode(s1)).compareTo(System.identityHashCode(s2)); >+ } >+ return i; >+ } >+ >+ } >+} >#P org.eclipse.mylyn.sandbox.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/sandbox/org.eclipse.mylyn.sandbox.ui/plugin.xml,v >retrieving revision 1.91 >diff -u -r1.91 plugin.xml >--- plugin.xml 12 Aug 2008 07:24:50 -0000 1.91 >+++ plugin.xml 20 Aug 2008 17:35:42 -0000 >@@ -450,6 +450,13 @@ > name="View Source"> > </command> > </extension> >+ <extension >+ point="org.eclipse.mylyn.tasks.ui.taskRepositoryPageContributor"> >+ <taskRepositoryPageContributor >+ class="org.eclipse.mylyn.internal.sandbox.ui.wizards.TaskEditorExtensionSettingsContributor" >+ connectorKind="*"> >+ </taskRepositoryPageContributor> >+ </extension> > <!-- > <extension point="org.eclipse.mylyn.tasks.ui.presentations"> > <presentation >Index: src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContributor.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContributor.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContributor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContributor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2008 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.wizards; >+ >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContribution; >+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPageContributor; >+ >+/** >+ * A contributor that adds {@link TaskEditorExtensionSettingsContribution} to all repositories >+ * >+ * @see TaskEditorExtensionSettingsContribution >+ * >+ * @author David Green >+ */ >+public class TaskEditorExtensionSettingsContributor implements ITaskRepositoryPageContributor { >+ >+ public TaskEditorExtensionSettingsContributor() { >+ } >+ >+ public ITaskRepositoryPageContribution createContribution(TaskRepository repository) { >+ return new TaskEditorExtensionSettingsContribution(repository); >+ } >+ >+} >Index: src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContribution.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContribution.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContribution.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/wizards/TaskEditorExtensionSettingsContribution.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,155 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers 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 >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.wizards; >+ >+import java.util.SortedSet; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jface.resource.FontRegistry; >+import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.mylyn.internal.sandbox.ui.editors.TaskEditorExtensions; >+import org.eclipse.mylyn.internal.sandbox.ui.editors.TaskEditorExtensions.RegisteredTaskEditorExtension; >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.mylyn.tasks.ui.wizards.AbstractTaskRepositoryPageContribution; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Widget; >+import org.eclipse.ui.forms.widgets.FormToolkit; >+ >+/** >+ * A contribution that adds a section for 'Task Editor Extension'. >+ * >+ * @author David Green >+ */ >+public class TaskEditorExtensionSettingsContribution extends AbstractTaskRepositoryPageContribution { >+ >+ private static final String LABEL_NONE = "None"; >+ >+ private static final String LABEL_DEFAULT_SUFFIX = " (default)"; >+ >+ private static final String DATA_EDITOR_EXTENSION = "editorExtension"; >+ >+ private final SelectionListener listener = new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ selectedExtensionId = (String) ((Widget) e.getSource()).getData(DATA_EDITOR_EXTENSION); >+ fireValidationRequired(); >+ } >+ }; >+ >+ private String selectedExtensionId = null; >+ >+ public TaskEditorExtensionSettingsContribution(TaskRepository repository) { >+ super("Task Editor Extension", "Select an extension to the task editor", repository); >+ } >+ >+ public void applyTo(TaskRepository repository) { >+ TaskEditorExtensions.setTaskEditorExtensionId(repository, selectedExtensionId == null ? "none" >+ : selectedExtensionId); >+ } >+ >+ public boolean canFlipToNextPage() { >+ return true; >+ } >+ >+ public boolean isPageComplete() { >+ return true; >+ } >+ >+ public void createControl(Composite parent, FormToolkit toolkit) { >+ parent.setLayout(new GridLayout(1, true)); >+ >+ selectedExtensionId = TaskEditorExtensions.getTaskEditorExtensionId(repository); >+ String defaultExtensionId = TaskEditorExtensions.getDefaultTaskEditorExtensionId(repository); >+ >+ Button noneButton; >+ { // configure a 'none' button >+ String noneTitle = LABEL_NONE; >+ >+ boolean isDefault = defaultExtensionId == null || defaultExtensionId.length() == 0; >+ if (isDefault) { >+ noneTitle += LABEL_DEFAULT_SUFFIX; >+ } >+ noneButton = toolkit.createButton(parent, noneTitle, SWT.RADIO); >+ if (isDefault) { >+ adjustForDefault(noneButton); >+ } >+ >+ noneButton.addSelectionListener(listener); >+ } >+ >+ boolean foundSelection = false; >+ >+ // now add selection buttons for all registered extensions >+ SortedSet<RegisteredTaskEditorExtension> allEditorExtensions = TaskEditorExtensions.getTaskEditorExtensions(); >+ for (RegisteredTaskEditorExtension editorExtension : allEditorExtensions) { >+ String name = editorExtension.getName(); >+ >+ boolean isDefault = editorExtension.getId().equals(defaultExtensionId); >+ if (isDefault) { >+ name += LABEL_DEFAULT_SUFFIX; >+ } >+ Button button = toolkit.createButton(parent, name, SWT.RADIO); >+ if (isDefault) { >+ adjustForDefault(button); >+ } >+ >+ if (editorExtension.getId().equals(selectedExtensionId)) { >+ foundSelection = true; >+ button.setSelection(true); >+ } >+ button.setText(name); >+ button.setData(DATA_EDITOR_EXTENSION, editorExtension.getId()); >+ button.addSelectionListener(listener); >+ } >+ if (!foundSelection) { >+ noneButton.setSelection(true); >+ } >+ } >+ >+ private void adjustForDefault(Button button) { >+ Font font = button.getFont(); >+ button.setFont(getBold(font)); >+ } >+ >+ private Font getBold(Font font) { >+ FontData[] originalFontData = font.getFontData(); >+ FontData fontData = originalFontData[0]; >+ if ((fontData.getStyle() & SWT.BOLD) != 0) { >+ return font; >+ } >+ >+ FontRegistry fontRegistry = JFaceResources.getFontRegistry(); >+ String key = fontData.getName() + '-' + fontData.getHeight() + "-" + fontData.getLocale() + "-" >+ + fontData.getStyle() + "-bold"; >+ >+ if (!fontRegistry.hasValueFor(key)) { >+ FontData[] boldFontDatas = new FontData[originalFontData.length]; >+ int index = -1; >+ for (FontData fd : originalFontData) { >+ boldFontDatas[++index] = new FontData(fd.getName(), fd.getHeight(), fd.getStyle() | SWT.BOLD); >+ } >+ fontRegistry.put(key, boldFontDatas); >+ } >+ return fontRegistry.get(key); >+ } >+ >+ public IStatus[] validate(IProgressMonitor monitor) { >+ return null; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 244653
: 110475 |
110476
|
110514
|
110515
|
110516
|
110517
|
110730
|
110731
|
112848
|
112849
|
112850
|
115338
|
115339
|
116062
|
116063
|
116387
|
116778
|
116865
|
116890
|
117734