diff options
author | mkersten | 2006-01-23 23:48:58 +0000 |
---|---|---|
committer | mkersten | 2006-01-23 23:48:58 +0000 |
commit | cf6ed73fc94793470e1455128903f26a55bc5d59 (patch) | |
tree | 68635ac67d4939ada8d3d72112edc3c77b92209d | |
parent | ffab9a5017303de1c0c34d07f74cd5199d09d0fc (diff) | |
download | org.eclipse.mylyn.tasks-cf6ed73fc94793470e1455128903f26a55bc5d59.tar.gz org.eclipse.mylyn.tasks-cf6ed73fc94793470e1455128903f26a55bc5d59.tar.xz org.eclipse.mylyn.tasks-cf6ed73fc94793470e1455128903f26a55bc5d59.zip |
Completed: Bug 124768: Back button broken in the add repository query wizard
https://bugs.eclipse.org/bugs/show_bug.cgi?id=124768
18 files changed, 428 insertions, 361 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/actions/CreateNewBugzillaTaskAction.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/actions/CreateNewBugzillaTaskAction.java index f446a6bef..d5c5d59a0 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/actions/CreateNewBugzillaTaskAction.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/actions/CreateNewBugzillaTaskAction.java @@ -13,22 +13,17 @@ package org.eclipse.mylar.bugzilla.ui.actions; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.mylar.bugzilla.ui.BugzillaUiPlugin; -import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask; +import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.ui.wizard.NewBugzillaReportWizard; import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; import org.eclipse.mylar.internal.tasklist.MylarTaskListPrefConstants; -import org.eclipse.mylar.internal.tasklist.TaskCategory; -import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager; -import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; -import org.eclipse.mylar.tasklist.ITask; -import org.eclipse.mylar.tasklist.ITaskHandler; +import org.eclipse.mylar.internal.tasklist.ui.wizards.MultiRepositoryAwareWizard; +import org.eclipse.mylar.internal.tasklist.ui.wizards.SelectRepositoryPage; +import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; @@ -58,69 +53,23 @@ public class CreateNewBugzillaTaskAction extends Action implements IViewActionDe } // TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getDefaultRepository(BugzillaPlugin.REPOSITORY_KIND); - NewBugzillaReportWizard wizard = new NewBugzillaReportWizard(true); + IWizard wizard = new MultiRepositoryAwareWizard(new SelectRepositoryPage(BugzillaPlugin.REPOSITORY_KIND) { + + @Override + protected IWizard createWizard(TaskRepository taskRepository) { + return new NewBugzillaReportWizard(taskRepository); + } + + }); + Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell(); if (wizard != null && shell != null && !shell.isDisposed()) { WizardDialog dialog = new WizardDialog(shell, wizard); - wizard.setForcePreviousAndNextButtons(true); - dialog.create(); - dialog.setTitle("New Bug Wizard"); +// dialog.setTitle("New Bug Wizard"); dialog.setBlockOnOpen(true); - if(dialog.open() == Dialog.CANCEL){ - dialog.close(); - return; - } - - String bugIdString = wizard.getId(); - int bugId = -1; - try { - if (bugIdString != null) { - bugId = Integer.parseInt(bugIdString); - } else { - return; - } - } catch (NumberFormatException nfe) { - // TODO handle error - return; - } - -// TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getDefaultRepository(BugzillaPlugin.REPOSITORY_KIND); - BugzillaTask newTask = new BugzillaTask( - TaskRepositoryManager.getHandle( - wizard.getRepository().getUrl().toExternalForm(), bugId), - "<bugzilla info>", true, true); - Object selectedObject = null; - if(TaskListView.getDefault() != null) - selectedObject = ((IStructuredSelection)TaskListView.getDefault().getViewer().getSelection()).getFirstElement(); - - ITaskHandler taskHandler = MylarTaskListPlugin.getDefault().getHandlerForElement(newTask); - if(taskHandler != null){ - ITask addedTask = taskHandler.addTaskToRegistry(newTask); - if(addedTask instanceof BugzillaTask){ - BugzillaTask newTask2 = (BugzillaTask)addedTask; - if(newTask2 != newTask){ - newTask = newTask2; - } - } - } + dialog.open(); - if (selectedObject instanceof TaskCategory) { - MylarTaskListPlugin.getTaskListManager().moveToCategory(((TaskCategory)selectedObject), newTask); -// ((TaskCategory)selectedObject).addTask(newTask); - } else { - MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask); - } - BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().addToBugzillaTaskRegistry((BugzillaTask)newTask); - newTask.openTaskInEditor(false); - - if(!newTask.isBugDownloaded()) - newTask.scheduleDownloadReport(); - - if(TaskListView.getDefault() != null) { - TaskListView.getDefault().getViewer().setSelection(new StructuredSelection(newTask)); - TaskListView.getDefault().getViewer().refresh(); - } } else { // TODO handle not good } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/search/BugzillaSearchPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/search/BugzillaSearchPage.java index 2d6ba86c5..3f5db9169 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/search/BugzillaSearchPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/search/BugzillaSearchPage.java @@ -131,6 +131,8 @@ public class BugzillaSearchPage extends DialogPage implements ISearchPage { Composite control = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; control.setLayout(layout); GridData gd = new GridData(GridData.FILL_BOTH); control.setLayoutData(gd); @@ -157,6 +159,7 @@ public class BugzillaSearchPage extends DialogPage implements ISearchPage { layout.numColumns = 1; group.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; group.setLayoutData(gd); repositoryCombo = new Combo(group, SWT.SINGLE | SWT.BORDER); diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/AddBugzillaQueryWizard.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/AddBugzillaQueryWizard.java new file mode 100644 index 000000000..7929c1720 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/AddBugzillaQueryWizard.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2006 University Of British Columbia 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: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.bugzilla.ui.tasklist; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.mylar.core.util.MylarStatusHandler; +import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; +import org.eclipse.mylar.internal.tasklist.MylarTaskListPrefConstants; +import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; +import org.eclipse.mylar.tasklist.TaskRepository; +import org.eclipse.ui.actions.WorkspaceModifyOperation; + +/** + * @author Brock Janiczak + */ +public class AddBugzillaQueryWizard extends Wizard { + + private final TaskRepository repository; + private BugzillaQueryWizardPage queryPage; + + public AddBugzillaQueryWizard(TaskRepository repository) { + this.repository = repository; + setNeedsProgressMonitor(true); + } + + @Override + public void addPages() { + queryPage = new BugzillaQueryWizardPage(repository); + addPage(queryPage); + } + + @Override + public boolean performFinish() { + queryPage.getQueryDialog().okPressed(); + final BugzillaQueryCategory queryCategory; + if(!queryPage.getQueryDialog().isCustom()){ + queryCategory = new BugzillaQueryCategory(repository.getUrl().toExternalForm(), queryPage.getQueryDialog().getUrl(), queryPage.getQueryDialog().getName(), queryPage.getQueryDialog().getMaxHits()); + } else { + queryCategory = new BugzillaCustomQueryCategory(repository.getUrl().toExternalForm(), queryPage.getQueryDialog().getName(), queryPage.getQueryDialog().getUrl(), queryPage.getQueryDialog().getMaxHits()); + } + MylarTaskListPlugin.getTaskListManager().addQuery(queryCategory); + boolean offline = MylarTaskListPlugin.getPrefs().getBoolean(MylarTaskListPrefConstants.WORK_OFFLINE); + if(!offline){ + WorkspaceModifyOperation op = new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) throws CoreException { + monitor.beginTask("Executing query", 50); + try { + queryCategory.refreshBugs(new SubProgressMonitor(monitor, 50)); + } finally { + monitor.done(); + } + } + }; + + try { + getContainer().run(true, false, op); + } catch (Exception e) { + MylarStatusHandler.log(e, "There was a problem executing the query refresh"); + } + } + if(TaskListView.getDefault() != null) { + // TODO: remove + TaskListView.getDefault().getViewer().refresh(); + } + + return true; + } + +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryCategory.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryCategory.java index 47649c53a..cf1511555 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryCategory.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryCategory.java @@ -19,6 +19,7 @@ import java.util.Map; import javax.security.auth.login.LoginException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; @@ -128,6 +129,10 @@ public class BugzillaQueryCategory implements IRepositoryQuery { } public void refreshBugs() { + refreshBugs(new NullProgressMonitor()); + } + + public void refreshBugs(IProgressMonitor monitor) { hits.clear(); // refresh the view to show that the results are gone Display.getDefault().asyncExec(new Runnable() { @@ -155,7 +160,7 @@ public class BugzillaQueryCategory implements IRepositoryQuery { try { // execute the search operation - catSearch.execute(new NullProgressMonitor()); + catSearch.execute(monitor); maxHitsReached = catSearch.isMaxReached(); // hasBeenRefreshed = true; lastRefresh = new Date(); diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryDialog.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryDialog.java index 03250ee54..f7721c98d 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryDialog.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryDialog.java @@ -79,7 +79,6 @@ public class BugzillaQueryDialog extends Dialog { title = "New Bugzilla Query"; } - public BugzillaQueryDialog(Shell parentShell) { super(parentShell); isNew = true; @@ -122,15 +121,21 @@ public class BugzillaQueryDialog extends Dialog { public boolean isCustom() { return isCustom; } - + + /* + * XXX This is being used to create the contents for a wizard page. Yuck! + * Visibility of this method has also been increased + */ @Override - protected Control createContents(Composite parent) { - searchOptionPage.createControl(parent); + public Control createDialogArea(Composite parent) { + Composite composite = (Composite)super.createDialogArea(parent); + + searchOptionPage.createControl(composite); searchOptionPage.setVisible(true); if (isNew) { - Group custom = new Group(parent, SWT.NONE); + Group custom = new Group(composite, SWT.NONE); GridLayout layout = new GridLayout(2, false); custom.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -178,7 +183,6 @@ public class BugzillaQueryDialog extends Dialog { }); } - Control control = super.createContents(parent); if (startingUrl != null) { try { searchOptionPage.updateDefaults(startingUrl, maxHits); @@ -187,7 +191,7 @@ public class BugzillaQueryDialog extends Dialog { } } - return control; + return composite; } @Override @@ -276,6 +280,7 @@ public class BugzillaQueryDialog extends Dialog { public void setSelectedWorkingSets(IWorkingSet[] workingSets) { } + }; } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryWizardPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryWizardPage.java index 196e95a6e..823014239 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryWizardPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaQueryWizardPage.java @@ -11,26 +11,15 @@ package org.eclipse.mylar.bugzilla.ui.tasklist; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.mylar.core.util.MylarStatusHandler; -import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; -import org.eclipse.mylar.internal.tasklist.MylarTaskListPrefConstants; -import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager; -import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; -import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractNewQueryPage; +import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.progress.IProgressService; +import org.eclipse.swt.widgets.Control; /** * @author Mik Kersten */ -public class BugzillaQueryWizardPage extends AbstractNewQueryPage { +public class BugzillaQueryWizardPage extends WizardPage { private static final String TITLE = "New Bugzilla Query"; @@ -46,46 +35,11 @@ public class BugzillaQueryWizardPage extends AbstractNewQueryPage { } public void createControl(Composite parent) { - queryDialog.createContents(parent); - setControl(parent); + Control control = queryDialog.createDialogArea(parent); + setControl(control); } - - @Override - public void addQuery() { - queryDialog.okPressed(); - - TaskRepository repository = queryDialog.getRepository(); - if (repository == null) { - MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Mylar Bugzilla Client", - TaskRepositoryManager.MESSAGE_NO_REPOSITORY); - return; - } - - final BugzillaQueryCategory queryCategory; - if(!queryDialog.isCustom()){ - queryCategory = new BugzillaQueryCategory(repository.getUrl().toExternalForm(), queryDialog.getUrl(), queryDialog.getName(), queryDialog.getMaxHits()); - } else { - queryCategory = new BugzillaCustomQueryCategory(repository.getUrl().toExternalForm(), queryDialog.getName(), queryDialog.getUrl(), queryDialog.getMaxHits()); - } - MylarTaskListPlugin.getTaskListManager().addQuery(queryCategory); - boolean offline = MylarTaskListPlugin.getPrefs().getBoolean(MylarTaskListPrefConstants.WORK_OFFLINE); - if(!offline){ - WorkspaceModifyOperation op = new WorkspaceModifyOperation() { - protected void execute(IProgressMonitor monitor) throws CoreException { - queryCategory.refreshBugs(); - } - }; - - IProgressService service = PlatformUI.getWorkbench().getProgressService(); - try { - service.run(true, true, op); - } catch (Exception e) { - MylarStatusHandler.log(e, "There was a problem executing the query refresh"); - } - } - if(TaskListView.getDefault() != null) { - // TODO: remove - TaskListView.getDefault().getViewer().refresh(); - } + + public BugzillaQueryDialog getQueryDialog() { + return queryDialog; } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskRepositoryClient.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskRepositoryClient.java index 74d3c731f..fdf681413 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskRepositoryClient.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/tasklist/BugzillaTaskRepositoryClient.java @@ -11,13 +11,15 @@ package org.eclipse.mylar.bugzilla.ui.tasklist; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.mylar.bugzilla.core.BugzillaPlugin; import org.eclipse.mylar.bugzilla.core.BugzillaRepositorySettingsPage; import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager; import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; -import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractNewQueryPage; +import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractAddExistingTaskWizard; import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage; +import org.eclipse.mylar.internal.tasklist.ui.wizards.ExistingTaskWizardPage; import org.eclipse.mylar.tasklist.ITask; import org.eclipse.mylar.tasklist.ITaskHandler; import org.eclipse.mylar.tasklist.ITaskRepositoryClient; @@ -75,11 +77,29 @@ public class BugzillaTaskRepositoryClient implements ITaskRepositoryClient { } else { ((BugzillaTask) newTask).scheduleDownloadReport(); } -// BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().addToBugzillaTaskRegistry((BugzillaTask) newTask); return newTask; } - public AbstractNewQueryPage getQueryPage(TaskRepository repository) { - return new BugzillaQueryWizardPage(repository); + public IWizard getQueryWizard(TaskRepository repository) { + return new AddBugzillaQueryWizard(repository); + } + + public IWizard getAddExistingTaskWizard(TaskRepository repository) { + + // TODO create a propper subclass for Bugzilla + return new AbstractAddExistingTaskWizard(repository) { + + private ExistingTaskWizardPage page; + + public void addPages() { + super.addPages(); + this.page = new ExistingTaskWizardPage(); + addPage(page); + } + + protected String getTaskId() { + return page.getTaskId(); + } + }; } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java index 28b4da8cd..d584c6f12 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/AbstractBugWizard.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; import org.eclipse.mylar.bugzilla.core.Attribute; import org.eclipse.mylar.bugzilla.core.BugReportPostHandler; import org.eclipse.mylar.bugzilla.core.BugzillaException; @@ -32,7 +33,6 @@ import org.eclipse.mylar.bugzilla.ui.WebBrowserDialog; import org.eclipse.mylar.bugzilla.ui.editor.AbstractBugEditor; import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput; import org.eclipse.mylar.core.util.MylarStatusHandler; -import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositoryWizard; import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.search.internal.ui.SearchMessages; import org.eclipse.search.internal.ui.util.ExceptionHandler; @@ -50,7 +50,7 @@ import org.eclipse.ui.progress.IProgressService; * @author Eric Booth * @author Mik Kersten (some hardening of prototype) */ -public abstract class AbstractBugWizard extends AbstractRepositoryWizard implements INewWizard { +public abstract class AbstractBugWizard extends Wizard implements INewWizard { /** The ID of the posted bug report. */ private String id; @@ -68,8 +68,11 @@ public abstract class AbstractBugWizard extends AbstractRepositoryWizard impleme /** The workbench instance */ protected IWorkbench workbenchInstance; - public AbstractBugWizard() { + private final TaskRepository repository; + + public AbstractBugWizard(TaskRepository repository) { super(); + this.repository = repository; model = new NewBugModel(); id = null; // Since there is no bug posted yet. super.setDefaultPageImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui", diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/BugzillaProductPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/BugzillaProductPage.java index b35430cd1..046149f69 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/BugzillaProductPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/BugzillaProductPage.java @@ -27,6 +27,7 @@ import org.eclipse.mylar.bugzilla.core.BugzillaRepositoryUtil; import org.eclipse.mylar.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.bugzilla.core.NewBugModel; import org.eclipse.mylar.core.util.MylarStatusHandler; +import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; @@ -63,6 +64,8 @@ public class BugzillaProductPage extends AbstractWizardListPage { */ private String prevProduct; + private final TaskRepository repository; + /** * Constructor for BugzillaProductPage * @@ -70,10 +73,12 @@ public class BugzillaProductPage extends AbstractWizardListPage { * The instance of the workbench * @param bugWiz * The bug wizard which created this page + * @param repository The repository the data is coming from */ - public BugzillaProductPage(IWorkbench workbench, NewBugzillaReportWizard bugWiz) { + public BugzillaProductPage(IWorkbench workbench, NewBugzillaReportWizard bugWiz, TaskRepository repository) { super("Page1", "New Bug Report", DESCRIPTION, workbench); this.bugWizard = bugWiz; + this.repository = repository; } protected ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(BugzillaPlugin.getDefault() @@ -98,11 +103,11 @@ public class BugzillaProductPage extends AbstractWizardListPage { monitor.beginTask("Updating search options...", 55); try { - BugzillaRepositoryUtil.updateQueryOptions(bugWizard.getRepository(), monitor); + BugzillaRepositoryUtil.updateQueryOptions(repository, monitor); products = new ArrayList<String>(); for (String product : BugzillaRepositoryUtil.getQueryOptions(IBugzillaConstants.VALUES_PRODUCT, - bugWizard.getRepository().getUrl().toExternalForm())) { + repository.getUrl().toExternalForm())) { products.add(product); } monitor.worked(1); @@ -127,7 +132,7 @@ public class BugzillaProductPage extends AbstractWizardListPage { private void initProducts() { // try to get the list of products from the server if (!bugWizard.model.hasParsedProducts()) { - String repositoryUrl = bugWizard.getRepository().getUrl().toExternalForm(); + String repositoryUrl = repository.getUrl().toExternalForm(); try { // ProductConfiguration productConfiguration = BugzillaPlugin.getDefault().getProductConfiguration(repositoryUrl); String[] storedProducts = BugzillaRepositoryUtil.getQueryOptions(IBugzillaConstants.VALUES_PRODUCT, @@ -194,7 +199,7 @@ public class BugzillaProductPage extends AbstractWizardListPage { // try to get the attributes from the bugzilla server try { if (!model.hasParsedAttributes() || !prevProduct.equals(model.getProduct())) { - String serverUrl = bugWizard.getRepository().getUrl().toExternalForm(); + String serverUrl = repository.getUrl().toExternalForm(); if (model.isConnected()) { BugzillaRepositoryUtil.setupNewBugAttributes(serverUrl, model, false); } else { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugzillaReportWizard.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugzillaReportWizard.java index 376e25ba0..74033a7e7 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugzillaReportWizard.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/bugzilla/ui/wizard/NewBugzillaReportWizard.java @@ -10,9 +10,18 @@ *******************************************************************************/ package org.eclipse.mylar.bugzilla.ui.wizard; -import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.mylar.bugzilla.ui.BugzillaUiPlugin; import org.eclipse.mylar.bugzilla.ui.OfflineView; -import org.eclipse.mylar.internal.tasklist.ui.wizards.SelectRepositoryPage; +import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaTask; +import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; +import org.eclipse.mylar.internal.tasklist.TaskCategory; +import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager; +import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; +import org.eclipse.mylar.tasklist.ITask; +import org.eclipse.mylar.tasklist.ITaskHandler; +import org.eclipse.mylar.tasklist.TaskRepository; /** * @author Mik Kersten @@ -24,27 +33,22 @@ public class NewBugzillaReportWizard extends AbstractBugWizard { * submitted */ private WizardAttributesPage attributePage; + private final TaskRepository repository; - public NewBugzillaReportWizard() { - this(false); + public NewBugzillaReportWizard(TaskRepository repository) { + this(false, repository); } - public NewBugzillaReportWizard(boolean fromDialog) { - super(); + public NewBugzillaReportWizard(boolean fromDialog, TaskRepository repository) { + super(repository); + this.repository = repository; this.fromDialog = fromDialog; } @Override public void addPages() { super.addPages(); - } - - @Override - public IWizardPage getNextPage(IWizardPage page) { - if (page instanceof SelectRepositoryPage) { - addPage(new BugzillaProductPage(workbenchInstance, this)); - } - return super.getNextPage(page); + addPage(new BugzillaProductPage(workbenchInstance, this, repository)); } @Override @@ -69,4 +73,59 @@ public class NewBugzillaReportWizard extends AbstractBugWizard { public void setAttributePage(WizardAttributesPage attributePage) { this.attributePage = attributePage; } + + @Override + public boolean performFinish() { + String bugIdString = this.getId(); + int bugId = -1; + try { + if (bugIdString != null) { + bugId = Integer.parseInt(bugIdString); + } else { + return false; + } + } catch (NumberFormatException nfe) { + // TODO handle error + return false; + } + +// TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getDefaultRepository(BugzillaPlugin.REPOSITORY_KIND); + BugzillaTask newTask = new BugzillaTask( + TaskRepositoryManager.getHandle( + repository.getUrl().toExternalForm(), bugId), + "<bugzilla info>", true, true); + Object selectedObject = null; + if(TaskListView.getDefault() != null) + selectedObject = ((IStructuredSelection)TaskListView.getDefault().getViewer().getSelection()).getFirstElement(); + + ITaskHandler taskHandler = MylarTaskListPlugin.getDefault().getHandlerForElement(newTask); + if(taskHandler != null){ + ITask addedTask = taskHandler.addTaskToRegistry(newTask); + if(addedTask instanceof BugzillaTask){ + BugzillaTask newTask2 = (BugzillaTask)addedTask; + if(newTask2 != newTask){ + newTask = newTask2; + } + } + } + + if (selectedObject instanceof TaskCategory) { + MylarTaskListPlugin.getTaskListManager().moveToCategory(((TaskCategory)selectedObject), newTask); +// ((TaskCategory)selectedObject).addTask(newTask); + } else { + MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask); + } + BugzillaUiPlugin.getDefault().getBugzillaTaskListManager().addToBugzillaTaskRegistry((BugzillaTask)newTask); + newTask.openTaskInEditor(false); + + if(!newTask.isBugDownloaded()) + newTask.scheduleDownloadReport(); + + if(TaskListView.getDefault() != null) { + TaskListView.getDefault().getViewer().setSelection(new StructuredSelection(newTask)); + TaskListView.getDefault().getViewer().refresh(); + } + + return true; + } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractAddExistingTaskWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractAddExistingTaskWizard.java new file mode 100644 index 000000000..28460bceb --- /dev/null +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractAddExistingTaskWizard.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2004 - 2005 University Of British Columbia 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: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylar.internal.tasklist.ui.wizards; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; +import org.eclipse.mylar.internal.tasklist.TaskCategory; +import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; +import org.eclipse.mylar.tasklist.ITask; +import org.eclipse.mylar.tasklist.ITaskRepositoryClient; +import org.eclipse.mylar.tasklist.TaskRepository; +import org.eclipse.ui.IWorkbench; + +/** + * @author Brock Janiczak + */ +public abstract class AbstractAddExistingTaskWizard extends Wizard { + + private final TaskRepository repository; + + public AbstractAddExistingTaskWizard(TaskRepository repository) { + this.repository = repository; + init(); + } + + @Override + public final boolean performFinish() { + ITaskRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(this.repository.getKind()); + ITask newTask = client.createTaskFromExistingId(repository, getTaskId()); + + if (newTask != null && TaskListView.getDefault() != null) { + Object selectedObject = ((IStructuredSelection) TaskListView.getDefault().getViewer().getSelection()).getFirstElement(); + + if (selectedObject instanceof TaskCategory) { + MylarTaskListPlugin.getTaskListManager().moveToCategory(((TaskCategory) selectedObject), newTask); + } else { + MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask); + } + if (TaskListView.getDefault() != null) { + TaskListView.getDefault().getViewer().setSelection(new StructuredSelection(newTask)); + } + } + + return true; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + private void init() { + super.setForcePreviousAndNextButtons(true); + } + + protected abstract String getTaskId(); +} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractNewQueryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractNewQueryPage.java deleted file mode 100644 index 65398324d..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractNewQueryPage.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.internal.tasklist.ui.wizards; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.widgets.Composite; - -/** - * @author Mik Kersten - */ -public abstract class AbstractNewQueryPage extends WizardPage { - - protected AbstractNewQueryPage(String pageName) { - super(pageName); - } - - public void createControl(Composite parent) { - // ignore - } - - public abstract void addQuery(); - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AddExistingTaskWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AddExistingTaskWizard.java index b8a720924..a19efc96c 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AddExistingTaskWizard.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AddExistingTaskWizard.java @@ -11,64 +11,27 @@ package org.eclipse.mylar.internal.tasklist.ui.wizards; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; -import org.eclipse.mylar.internal.tasklist.TaskCategory; -import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView; -import org.eclipse.mylar.tasklist.ITask; import org.eclipse.mylar.tasklist.ITaskRepositoryClient; -import org.eclipse.ui.IWorkbench; +import org.eclipse.mylar.tasklist.TaskRepository; /** * @author Mik Kersten + * @author Brock Janiczak */ -public class AddExistingTaskWizard extends AbstractRepositoryWizard { +public class AddExistingTaskWizard extends MultiRepositoryAwareWizard { - private ExistingTaskWizardPage existingTaskWizardPage = new ExistingTaskWizardPage(); - public AddExistingTaskWizard() { - super(); - init(); - } - - @Override - public boolean performFinish() { - String handle = existingTaskWizardPage.getTaskId(); - ITaskRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(super.repository.getKind()); - ITask newTask = client.createTaskFromExistingId(super.repository, handle); - - if (newTask != null && TaskListView.getDefault() != null) { - Object selectedObject = ((IStructuredSelection) TaskListView.getDefault().getViewer().getSelection()).getFirstElement(); + super(new SelectRepositoryPage() { - if (selectedObject instanceof TaskCategory) { - MylarTaskListPlugin.getTaskListManager().moveToCategory(((TaskCategory) selectedObject), newTask); - } else { - MylarTaskListPlugin.getTaskListManager().moveToRoot(newTask); - } - if (TaskListView.getDefault() != null) { - TaskListView.getDefault().getViewer().setSelection(new StructuredSelection(newTask)); + @Override + protected IWizard createWizard(TaskRepository taskRepository) { + ITaskRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient( + taskRepository.getKind()); + return client.getAddExistingTaskWizard(taskRepository); } - } - - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - } - - private void init() { - super.setForcePreviousAndNextButtons(true); - } - - @Override - public void addPages() { - super.addPages(); - addPage(existingTaskWizardPage); - } - @Override - public boolean canFinish() { - return super.canFinish() && existingTaskWizardPage.isPageComplete(); + }); } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositoryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/MultiRepositoryAwareWizard.java index d9e0d4214..0ebac92cd 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositoryWizard.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/MultiRepositoryAwareWizard.java @@ -11,39 +11,29 @@ package org.eclipse.mylar.internal.tasklist.ui.wizards; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; -import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; /** * @author Mik Kersten + * @author Brock Janiczak */ -public abstract class AbstractRepositoryWizard extends Wizard implements INewWizard { +public class MultiRepositoryAwareWizard extends Wizard implements INewWizard { private SelectRepositoryPage selectRepositoryPage; - protected TaskRepository repository; - - public AbstractRepositoryWizard() { - selectRepositoryPage = new SelectRepositoryPage(this); - } - - public AbstractRepositoryWizard(SelectRepositoryPage page) { + public MultiRepositoryAwareWizard(SelectRepositoryPage page) { selectRepositoryPage = page; + setForcePreviousAndNextButtons(true); + setNeedsProgressMonitor(true); } - public AbstractRepositoryWizard(String repositoryKind) { - selectRepositoryPage = new SelectRepositoryPage(this, repositoryKind); + public void init(IWorkbench workbench, IStructuredSelection selection) { + // ignore } - public void setRepository(TaskRepository taskRepository) { - this.repository = taskRepository; - } - - public TaskRepository getRepository() { - return repository; - } - @Override public void addPages() { addPage(selectRepositoryPage); @@ -51,10 +41,12 @@ public abstract class AbstractRepositoryWizard extends Wizard implements INewWiz @Override public boolean canFinish() { - return selectRepositoryPage.isPageComplete(); + return false; } - - public void setSelectRepositoryPage(SelectRepositoryPage selectRepositoryPage) { - this.selectRepositoryPage = selectRepositoryPage; + + @Override + public boolean performFinish() { + // Can't finish on the first page + return false; } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQuerySelectRepositoryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQuerySelectRepositoryPage.java deleted file mode 100644 index dd889e123..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQuerySelectRepositoryPage.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.internal.tasklist.ui.wizards; - -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; -import org.eclipse.mylar.tasklist.ITaskRepositoryClient; - -/** - * @author Mik Kersten - */ -public class NewQuerySelectRepositoryPage extends SelectRepositoryPage { - - private NewQueryWizard newQueryWizard; - - public NewQuerySelectRepositoryPage(NewQueryWizard newQueryWizard) { - super(newQueryWizard); - this.newQueryWizard = newQueryWizard; - } - - @Override - public IWizardPage getNextPage() { - if (isPageComplete()) { - ITaskRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(wizard.repository.getKind()); - AbstractNewQueryPage nextPage = client.getQueryPage(wizard.repository); - newQueryWizard.setQueryPage(nextPage); - nextPage.setWizard(newQueryWizard); - return nextPage; - } else { - return super.getNextPage(); - } - } -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQueryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQueryWizard.java index 42d207738..7305e1c04 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQueryWizard.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/NewQueryWizard.java @@ -11,48 +11,25 @@ package org.eclipse.mylar.internal.tasklist.ui.wizards; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbench; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; +import org.eclipse.mylar.tasklist.ITaskRepositoryClient; +import org.eclipse.mylar.tasklist.TaskRepository; /** * @author Mik Kersten */ -public class NewQueryWizard extends AbstractRepositoryWizard { +public class NewQueryWizard extends MultiRepositoryAwareWizard { - private AbstractNewQueryPage queryPage; - public NewQueryWizard() { - super(); - super.setSelectRepositoryPage(new NewQuerySelectRepositoryPage(this)); - init(); - } - - @Override - public boolean performFinish() { - if (canFinish()) { - queryPage.addQuery(); - } - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - } - - private void init() { - super.setForcePreviousAndNextButtons(true); - } - - @Override - public void addPages() { - super.addPages(); - } - - public void setQueryPage(AbstractNewQueryPage queryPage) { - this.queryPage = queryPage; - } - - @Override - public boolean canFinish() { - return super.canFinish() && queryPage != null && queryPage.isPageComplete(); + super(new SelectRepositoryPage() { + + @Override + protected IWizard createWizard(TaskRepository taskRepository) { + ITaskRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(taskRepository.getKind()); + return client.getQueryWizard(taskRepository); + } + + }); } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/SelectRepositoryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/SelectRepositoryPage.java index 333bcb5a6..7e3d883d0 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/SelectRepositoryPage.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/SelectRepositoryPage.java @@ -11,25 +11,31 @@ package org.eclipse.mylar.internal.tasklist.ui.wizards; +import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.jface.wizard.IWizardNode; +import org.eclipse.jface.wizard.WizardSelectionPage; import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin; import org.eclipse.mylar.internal.tasklist.ui.views.TaskRepositoryLabelProvider; import org.eclipse.mylar.tasklist.TaskRepository; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; /** * @author Mik Kersten + * @author Brock Janiczak */ -public class SelectRepositoryPage extends WizardPage { +public abstract class SelectRepositoryPage extends WizardSelectionPage { private static final String DESCRIPTION = "Select a repository, or add a new one using the Task Repositories view."; @@ -37,7 +43,7 @@ public class SelectRepositoryPage extends WizardPage { private TableViewer viewer; - protected AbstractRepositoryWizard wizard; + protected MultiRepositoryAwareWizard wizard; private String repositoryKind = null; @@ -58,24 +64,17 @@ public class SelectRepositoryPage extends WizardPage { } } - public SelectRepositoryPage(AbstractRepositoryWizard wizard) { + public SelectRepositoryPage() { super(TITLE); setTitle(TITLE); setDescription(DESCRIPTION); - this.wizard = wizard; - super.setWizard(wizard); } - public SelectRepositoryPage(AbstractRepositoryWizard wizard, String repositoryKind) { - this(wizard); + public SelectRepositoryPage(String repositoryKind) { + this(); this.repositoryKind = repositoryKind; } - @Override - public boolean canFlipToNextPage() { - return wizard.getRepository() != null; - } - public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); FillLayout layout = new FillLayout(); @@ -90,17 +89,20 @@ public class SelectRepositoryPage extends WizardPage { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection)event.getSelection(); if (selection.getFirstElement() instanceof TaskRepository) { - wizard.setRepository((TaskRepository)selection.getFirstElement()); - SelectRepositoryPage.this.setPageComplete(true); - try { - wizard.getContainer().updateButtons(); - } catch (NullPointerException npe) { - // ignore, back button couldn't be updated - // TODO: remove this catch block - } + setSelectedNode(new CustomWizardNode((TaskRepository)selection.getFirstElement())); + setPageComplete(true); } + setPageComplete(false); + } + }); + + viewer.addOpenListener(new IOpenListener() { + + public void open(OpenEvent event) { + getContainer().showPage(getNextPage()); } - }); + + }); viewer.getTable().setFocus(); TaskRepository defaultRepository = MylarTaskListPlugin.getRepositoryManager().getDefaultRepository(repositoryKind); if (defaultRepository != null) { @@ -109,4 +111,58 @@ public class SelectRepositoryPage extends WizardPage { setControl(container); } + + protected abstract IWizard createWizard(TaskRepository taskRepository); + + private class CustomWizardNode implements IWizardNode { + + private final TaskRepository repository; + private IWizard wizard; + + public CustomWizardNode(TaskRepository repository) { + this.repository = repository; + } + + public void dispose() { + if (wizard != null) { + wizard.dispose(); + } + } + + public Point getExtent() { + return new Point(-1, -1); + } + + public IWizard getWizard() { + if (wizard == null) { + wizard = SelectRepositoryPage.this.createWizard(repository); + } + + return wizard; + } + + public boolean isContentCreated() { + return wizard != null; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof CustomWizardNode)) { + return false; + } + CustomWizardNode that = (CustomWizardNode)obj; + if (this == that) { + return true; + } + + return this.repository.getKind().equals(that.repository.getKind()) && + this.repository.getUrl().equals(that.repository.getUrl()); + } + + @Override + public int hashCode() { + return 31 * this.repository.getUrl().hashCode() + this.repository.getKind().hashCode(); + } + + } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ITaskRepositoryClient.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ITaskRepositoryClient.java index 3f7c82204..6c9519db8 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ITaskRepositoryClient.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ITaskRepositoryClient.java @@ -11,12 +11,13 @@ package org.eclipse.mylar.tasklist; -import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractNewQueryPage; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage; /** * @author Mik Kersten + * @author Brock Janiczak */ public interface ITaskRepositoryClient { @@ -35,5 +36,7 @@ public interface ITaskRepositoryClient { public abstract AbstractRepositorySettingsPage getSettingsPage(); - public abstract AbstractNewQueryPage getQueryPage(TaskRepository repository); + public abstract IWizard getQueryWizard(TaskRepository repository); + + public abstract IWizard getAddExistingTaskWizard(TaskRepository repository); } |