diff options
author | relves | 2007-06-11 21:50:29 +0000 |
---|---|---|
committer | relves | 2007-06-11 21:50:29 +0000 |
commit | 10024a18536588106096a991aa4733617e3a310c (patch) | |
tree | 17947e82a763592c3bdd16abb8d5ed8d943caac0 | |
parent | 954464194afb507e0487a5d2be84187b5deae5e0 (diff) | |
download | org.eclipse.mylyn.tasks-10024a18536588106096a991aa4733617e3a310c.tar.gz org.eclipse.mylyn.tasks-10024a18536588106096a991aa4733617e3a310c.tar.xz org.eclipse.mylyn.tasks-10024a18536588106096a991aa4733617e3a310c.zip |
NEW - bug 179254: [api] AbstractRepositoryTaskEditor needs to be decomposed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=179254
5 files changed, 306 insertions, 421 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java index 24cdff90f..fbd881fcd 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java @@ -124,7 +124,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { if (attribute != null && !attribute.isReadOnly()) { Label label = createLabel(composite, attribute); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label); - Composite textFieldComposite = toolkit.createComposite(composite); + Composite textFieldComposite = getManagedForm().getToolkit().createComposite(composite); GridLayout textLayout = new GridLayout(); textLayout.marginWidth = 1; textLayout.marginHeight = 3; @@ -136,14 +136,14 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { final Text text = createTextField(textFieldComposite, attribute, SWT.FLAT); text.setLayoutData(textData); - toolkit.paintBordersFor(textFieldComposite); + getManagedForm().getToolkit().paintBordersFor(textFieldComposite); } attribute = this.taskData.getAttribute(BugzillaReportElement.BLOCKED.getKeyString()); if (attribute != null && !attribute.isReadOnly()) { Label label = createLabel(composite, attribute); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label); - Composite textFieldComposite = toolkit.createComposite(composite); + Composite textFieldComposite = getManagedForm().getToolkit().createComposite(composite); GridLayout textLayout = new GridLayout(); textLayout.marginWidth = 1; textLayout.marginHeight = 3; @@ -154,7 +154,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { textData.widthHint = 135; final Text text = createTextField(textFieldComposite, attribute, SWT.FLAT); text.setLayoutData(textData); - toolkit.paintBordersFor(textFieldComposite); + getManagedForm().getToolkit().paintBordersFor(textFieldComposite); } String dependson = taskData.getAttributeValue(BugzillaReportElement.DEPENDSON.getKeyString()); @@ -177,7 +177,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { // }); if (addHyperlinks) { - toolkit.createLabel(composite, ""); + getManagedForm().getToolkit().createLabel(composite, ""); addBugHyperlinks(composite, BugzillaReportElement.DEPENDSON.getKeyString()); } @@ -196,7 +196,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { // }); if (addHyperlinks) { - toolkit.createLabel(composite, ""); + getManagedForm().getToolkit().createLabel(composite, ""); addBugHyperlinks(composite, BugzillaReportElement.BLOCKED.getKeyString()); } @@ -236,7 +236,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } if (taskData.getAttribute(BugzillaReportElement.ESTIMATED_TIME.getKeyString()) != null) - addBugzillaTimeTracker(toolkit, composite); + addBugzillaTimeTracker(getManagedForm().getToolkit(), composite); } @@ -267,7 +267,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } private void addBugHyperlinks(Composite composite, String key) { - Composite hyperlinksComposite = toolkit.createComposite(composite); + Composite hyperlinksComposite = getManagedForm().getToolkit().createComposite(composite); RowLayout rowLayout = new RowLayout(); rowLayout.marginBottom = 0; rowLayout.marginLeft = 0; @@ -280,7 +280,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { if (values != null && values.length() > 0) { for (String bugNumber : values.split(",")) { final String bugId = bugNumber.trim(); - Hyperlink hyperlink = toolkit.createHyperlink(hyperlinksComposite, bugId, SWT.NONE); + Hyperlink hyperlink = getManagedForm().getToolkit().createHyperlink(hyperlinksComposite, bugId, SWT.NONE); final ITask task = TasksUiPlugin.getTaskListManager().getTaskList().getTask(repository.getUrl(), bugId); if (task != null) { hyperlink.setToolTipText(task.getSummary()); @@ -301,7 +301,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } protected void addRoles(Composite parent) { - Section rolesSection = toolkit.createSection(parent, ExpandableComposite.SHORT_TITLE_BAR); + Section rolesSection = getManagedForm().getToolkit().createSection(parent, ExpandableComposite.SHORT_TITLE_BAR); rolesSection.setText("Users in the roles selected below can always view this bug"); rolesSection .setDescription("(The assignee can always see a bug, and this section does not take effect unless the bug is restricted to at least one group.)"); @@ -311,7 +311,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { rolesSection.setLayout(gl); rolesSection.setLayoutData(gd); - Composite rolesComposite = toolkit.createComposite(rolesSection); + Composite rolesComposite = getManagedForm().getToolkit().createComposite(rolesSection); GridLayout attributesLayout = new GridLayout(); attributesLayout.numColumns = 4; attributesLayout.horizontalSpacing = 5; @@ -331,7 +331,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } Button button = addButtonField(rolesComposite, attribute, SWT.CHECK); if (hasChanged(attribute)) { - button.setBackground(backgroundIncoming); + button.setBackground(getBackgroundIncoming()); } attribute = null; @@ -342,7 +342,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } button = addButtonField(rolesComposite, attribute, SWT.CHECK); if (hasChanged(attribute)) { - button.setBackground(backgroundIncoming); + button.setBackground(getBackgroundIncoming()); } } @@ -377,7 +377,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { name += "*"; } - final Button button = toolkit.createButton(rolesComposite, name, style); + final Button button = getManagedForm().getToolkit().createButton(rolesComposite, name, style); if (!attribute.isReadOnly()) { button.setData(attribute); button.setSelection(attribute.getValue().equals("1")); @@ -484,7 +484,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { deadlinePicker.setFont(TEXT_FONT); deadlinePicker.setDatePattern("yyyy-MM-dd"); if (hasChanged(attribute)) { - deadlinePicker.setBackground(backgroundIncoming); + deadlinePicker.setBackground(getBackgroundIncoming()); } deadlinePicker.addPickerSelectionListener(new SelectionListener() { @@ -596,10 +596,10 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } protected void addVoting(Composite attributesComposite) { - Label label = toolkit.createLabel(attributesComposite, "Votes:"); - label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); + Label label = getManagedForm().getToolkit().createLabel(attributesComposite, "Votes:"); + label.setForeground(getManagedForm().getToolkit().getColors().getColor(IFormColors.TITLE)); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label); - Composite votingComposite = toolkit.createComposite(attributesComposite); + Composite votingComposite = getManagedForm().getToolkit().createComposite(attributesComposite); GridLayout layout = new GridLayout(3, false); layout.marginHeight = 0; layout.marginWidth = 0; @@ -618,7 +618,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } votesText.setEditable(false); - Hyperlink showVotesHyperlink = toolkit.createHyperlink(votingComposite, "Show votes", SWT.NONE); + Hyperlink showVotesHyperlink = getManagedForm().getToolkit().createHyperlink(votingComposite, "Show votes", SWT.NONE); showVotesHyperlink.addHyperlinkListener(new HyperlinkAdapter() { @Override public void linkActivated(HyperlinkEvent e) { @@ -630,7 +630,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor { } }); - Hyperlink voteHyperlink = toolkit.createHyperlink(votingComposite, "Vote", SWT.NONE); + Hyperlink voteHyperlink = getManagedForm().getToolkit().createHyperlink(votingComposite, "Vote", SWT.NONE); voteHyperlink.addHyperlinkListener(new HyperlinkAdapter() { @Override public void linkActivated(HyperlinkEvent e) { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugzillaTaskEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugzillaTaskEditor.java index e298bebe3..aa1d16e86 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugzillaTaskEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugzillaTaskEditor.java @@ -12,6 +12,7 @@ package org.eclipse.mylyn.internal.bugzilla.ui.editor; import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.layout.GridDataFactory; @@ -34,8 +35,7 @@ import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; /** - * An editor used to view a locally created bug that does not yet exist on a - * repository. + * An editor used to view a locally created bug that does not yet exist on a repository. * * @author Rob Elves */ @@ -50,17 +50,18 @@ public class NewBugzillaTaskEditor extends AbstractNewRepositoryTaskEditor { @Override public void init(IEditorSite site, IEditorInput input) { super.init(site, input); - expandedStateAttributes = true; + + setExpandAttributeSection(true); } @Override - protected void updateTask() { + protected void saveTaskOffline(IProgressMonitor progressMonitor) { String text = descriptionTextViewer.getTextWidget().getText(); if (repository.getVersion().startsWith("2.18")) { text = formatTextToLineWrap(text, true); descriptionTextViewer.getTextWidget().setText(text); } - super.updateTask(); + super.saveTaskOffline(progressMonitor); } @Override diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SpellingDialog.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SpellingDialog.java index d8a2314cf..1eecc2f19 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SpellingDialog.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/SpellingDialog.java @@ -14,7 +14,6 @@ package org.eclipse.mylyn.internal.tasks.ui.editors; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -66,7 +65,7 @@ public class SpellingDialog extends Dialog { suggestions = new List(spellingComposite, SWT.BORDER); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 150; - gd.heightHint = AbstractRepositoryTaskEditor.RADIO_OPTION_WIDTH; + gd.heightHint = 120; suggestions.setLayoutData(gd); return c; diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractNewRepositoryTaskEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractNewRepositoryTaskEditor.java index d0be529d6..a1ebef189 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractNewRepositoryTaskEditor.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractNewRepositoryTaskEditor.java @@ -13,13 +13,13 @@ package org.eclipse.mylyn.tasks.ui.editors; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; @@ -42,6 +42,8 @@ import org.eclipse.mylyn.tasks.ui.search.SearchHitCollector; import org.eclipse.search.ui.NewSearchUI; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; @@ -71,6 +73,8 @@ import org.eclipse.ui.themes.IThemeManager; */ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepositoryTaskEditor { + private static final int DESCRIPTION_WIDTH = 79 * 7; // 500; + private static final int DEFAULT_FIELD_WIDTH = 150; private static final int DEFAULT_ESTIMATED_TIME = 1; @@ -105,17 +109,14 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository @Override public void init(IEditorSite site, IEditorInput input) { - NewTaskEditorInput ei = (NewTaskEditorInput) input; - setSite(site); - setInput(input); - editorInput = ei; - changedAttributes = new HashSet<RepositoryTaskAttribute>(); - taskData = ei.getTaskData(); - taskOutlineModel = RepositoryTaskOutlineNode.parseBugReport(taskData, false); + if (!(input instanceof NewTaskEditorInput)) { + return; + } + + initTaskEditor(site, (RepositoryTaskEditorInput) input); + + setTaskOutlineModel(RepositoryTaskOutlineNode.parseBugReport(taskData, false)); newSummary = taskData.getSummary(); - repository = editorInput.getRepository(); - connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind()); - isDirty = false; } @Override @@ -149,14 +150,8 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository } @Override - protected void createReportHeaderLayout(Composite comp) { - addSummaryText(comp); - } - - @Override - protected void addSummaryText(Composite attributesComposite) { - - Composite summaryComposite = toolkit.createComposite(attributesComposite); + protected void createSummaryLayout(Composite composite) { + Composite summaryComposite = getManagedForm().getToolkit().createComposite(composite); GridLayout summaryLayout = new GridLayout(2, false); summaryLayout.verticalSpacing = 0; summaryLayout.marginHeight = 2; @@ -174,11 +169,53 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository summaryText.setFont(summaryFont); GridDataFactory.fillDefaults().grab(true, false).hint(DESCRIPTION_WIDTH, SWT.DEFAULT).applyTo(summaryText); - summaryText.addListener(SWT.KeyUp, new SummaryListener()); + summaryText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String sel = summaryText.getText(); + if (!(newSummary.equals(sel))) { + newSummary = sel; + markDirty(true); + } + } + }); } - toolkit.paintBordersFor(summaryComposite); + getManagedForm().getToolkit().paintBordersFor(summaryComposite); } +// @Override +// protected void addSummaryText(Composite attributesComposite) { +// +// Composite summaryComposite = getManagedForm().getToolkit().createComposite(attributesComposite); +// GridLayout summaryLayout = new GridLayout(2, false); +// summaryLayout.verticalSpacing = 0; +// summaryLayout.marginHeight = 2; +// summaryComposite.setLayout(summaryLayout); +// GridDataFactory.fillDefaults().grab(true, false).applyTo(summaryComposite); +// +// RepositoryTaskAttribute attribute = taskData.getAttribute(RepositoryTaskAttribute.SUMMARY); +// if (attribute != null) { +// createLabel(summaryComposite, attribute); +// summaryText = createTextField(summaryComposite, attribute, SWT.FLAT); +// summaryText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); +// IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); +// Font summaryFont = themeManager.getCurrentTheme().getFontRegistry().get( +// TaskListColorsAndFonts.TASK_EDITOR_FONT); +// summaryText.setFont(summaryFont); +// +// GridDataFactory.fillDefaults().grab(true, false).hint(DESCRIPTION_WIDTH, SWT.DEFAULT).applyTo(summaryText); +// summaryText.addModifyListener(new ModifyListener() { +// public void modifyText(ModifyEvent e) { +// String sel = summaryText.getText(); +// if (!(newSummary.equals(sel))) { +// newSummary = sel; +// markDirty(true); +// } +// } +// }); +// } +// getManagedForm().getToolkit().paintBordersFor(summaryComposite); +// } + @Override protected void createAttachmentLayout(Composite comp) { // currently can't attach while creating new bug @@ -200,7 +237,7 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); section.setExpanded(true); - Composite sectionClient = toolkit.createComposite(section); + Composite sectionClient = getManagedForm().getToolkit().createComposite(section); section.setClient(sectionClient); GridLayout layout = new GridLayout(); layout.numColumns = 7; @@ -210,7 +247,7 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository sectionClient.setLayoutData(clientDataLayout); // Reminder - toolkit.createLabel(sectionClient, "Scheduled for:"); + getManagedForm().getToolkit().createLabel(sectionClient, "Scheduled for:"); // label.setForeground(toolkit.getColors().getColor(FormColors.TITLE)); scheduledForDate = new DatePicker(sectionClient, SWT.NONE, DatePicker.LABEL_CHOOSE); scheduledForDate.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); @@ -225,7 +262,7 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository TasksUiPlugin.getTaskListManager().setScheduledEndOfDay(newTaskSchedule); } scheduledForDate.setDate(newTaskSchedule); - Button removeReminder = toolkit.createButton(sectionClient, "Clear", SWT.PUSH | SWT.CENTER); + Button removeReminder = getManagedForm().getToolkit().createButton(sectionClient, "Clear", SWT.PUSH | SWT.CENTER); removeReminder.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -234,14 +271,14 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository }); // 1 Blank column after Reminder clear button - Label dummy = toolkit.createLabel(sectionClient, ""); + Label dummy = getManagedForm().getToolkit().createLabel(sectionClient, ""); GridData dummyLabelDataLayout = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); dummyLabelDataLayout.horizontalSpan = 1; dummyLabelDataLayout.widthHint = 30; dummy.setLayoutData(dummyLabelDataLayout); // Estimated time - toolkit.createLabel(sectionClient, "Estimated time:"); + getManagedForm().getToolkit().createLabel(sectionClient, "Estimated time:"); // label.setForeground(toolkit.getColors().getColor(FormColors.TITLE)); estimatedTime = new Spinner(sectionClient, SWT.NONE); estimatedTime.setDigits(0); @@ -253,10 +290,10 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository GridData estimatedDataLayout = new GridData(); estimatedDataLayout.widthHint = 110; estimatedTime.setLayoutData(estimatedDataLayout); - toolkit.createLabel(sectionClient, "hours "); + getManagedForm().getToolkit().createLabel(sectionClient, "hours "); // label.setForeground(toolkit.getColors().getColor(FormColors.TITLE)); - toolkit.paintBordersFor(sectionClient); + getManagedForm().getToolkit().paintBordersFor(sectionClient); } @Override @@ -271,10 +308,10 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository } @Override - protected void updateTask() { + protected void saveTaskOffline(IProgressMonitor progressMonitor) { taskData.setSummary(newSummary); taskData.setDescription(descriptionTextViewer.getTextWidget().getText()); - super.updateTask(); + updateEditorTitle(); } /** @@ -289,15 +326,6 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository } @Override - public void handleSummaryEvent() { - String sel = summaryText.getText(); - if (!(newSummary.equals(sel))) { - newSummary = sel; - markDirty(true); - } - } - - @Override protected void validateInput() { // ignore } @@ -318,22 +346,22 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository */ @Override protected void createActionsLayout(Composite formComposite) { - Section section = toolkit.createSection(formComposite, ExpandableComposite.TITLE_BAR); + Section section = getManagedForm().getToolkit().createSection(formComposite, ExpandableComposite.TITLE_BAR); section.setText(getSectionLabel(SECTION_NAME.ACTIONS_SECTION)); section.setExpanded(true); section.setLayout(new GridLayout()); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, true).applyTo(section); - Composite buttonComposite = toolkit.createComposite(section); + Composite buttonComposite = getManagedForm().getToolkit().createComposite(section); buttonComposite.setLayout(new GridLayout(4, false)); buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); section.setClient(buttonComposite); - addToCategory = toolkit.createButton(buttonComposite, "Add to Category", SWT.CHECK); + addToCategory = getManagedForm().getToolkit().createButton(buttonComposite, "Add to Category", SWT.CHECK); categoryChooser = new CCombo(buttonComposite, SWT.FLAT | SWT.READ_ONLY); categoryChooser.setLayoutData(GridDataFactory.swtDefaults().hint(150, SWT.DEFAULT).create()); - toolkit.adapt(categoryChooser, true, true); + getManagedForm().getToolkit().adapt(categoryChooser, true, true); categoryChooser.setFont(TEXT_FONT); TaskList taskList = TasksUiPlugin.getTaskListManager().getTaskList(); List<AbstractTaskContainer> categories = taskList.getUserCategories(); @@ -365,7 +393,7 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository addActionButtons(buttonComposite); - toolkit.paintBordersFor(buttonComposite); + getManagedForm().getToolkit().paintBordersFor(buttonComposite); } /** @@ -481,9 +509,9 @@ public abstract class AbstractNewRepositoryTaskEditor extends AbstractRepository String duplicateDetectorName = duplicateDetectorChooser.getItem(duplicateDetectorChooser.getSelectionIndex()); - // updatetask() needs to be called so that the description text is save before we + // called so that the description text is set on taskData before we // search for duplicates - this.updateTask(); + this.saveTaskOffline(new NullProgressMonitor()); SearchHitCollector collector = getDuplicateSearchCollector(duplicateDetectorName); if (collector != null) { diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java index 97d440512..d37c6952d 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.CoreException; @@ -111,7 +110,6 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; @@ -136,7 +134,6 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.RetargetAction; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; import org.eclipse.ui.forms.IFormColors; import org.eclipse.ui.forms.IManagedForm; @@ -171,9 +168,9 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { private static final String LABEL_REPLY = "Reply"; - public static final String LABEL_JOB_SUBMIT = "Submitting to repository"; + private static final String LABEL_JOB_SUBMIT = "Submitting to repository"; - protected static final String HEADER_DATE_FORMAT = "yyyy-MM-dd HH:mm"; + private static final String HEADER_DATE_FORMAT = "yyyy-MM-dd HH:mm"; private static final String ATTACHMENT_DEFAULT_NAME = "attachment"; @@ -193,108 +190,61 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { protected static final String CONTEXT_MENU_ID = "#MylarRepositoryEditor"; - public static final String HYPERLINK_TYPE_TASK = "task"; - - public static final String HYPERLINK_TYPE_JAVA = "java"; - - protected FormToolkit toolkit; + private FormToolkit toolkit; private ScrolledForm form; protected TaskRepository repository; - public static final int RADIO_OPTION_WIDTH = 120; - - protected Display display; - - public static final Font TITLE_FONT = JFaceResources.getBannerFont(); - - public static final Font TEXT_FONT = JFaceResources.getDefaultFont(); + private static final int RADIO_OPTION_WIDTH = 120; - public static final Font HEADER_FONT = JFaceResources.getDefaultFont(); + private static final Font TITLE_FONT = JFaceResources.getBannerFont(); - public static final int DESCRIPTION_WIDTH = 79 * 7; // 500; + protected static final Font TEXT_FONT = JFaceResources.getDefaultFont(); - public static final int DESCRIPTION_HEIGHT = 10 * 14; + private static final int DESCRIPTION_WIDTH = 79 * 7; // 500; -// private static final String REASSIGN_BUG_TO = "Reassign to"; + private static final int DESCRIPTION_HEIGHT = 10 * 14; private static final String LABEL_BUTTON_SUBMIT = "Submit"; private static final String LABEL_COPY_TO_CLIPBOARD = "Copy to Clipboard"; - protected RepositoryTaskEditorInput editorInput; + private RepositoryTaskEditorInput editorInput; private TaskEditor parentEditor = null; - protected RepositoryTaskOutlineNode taskOutlineModel = null; - - protected boolean expandedStateAttributes = false; - - private AbstractRepositoryTask modifiedTask; - - /** - * Style option for function <code>newLayout</code>. This will create a - * plain-styled, selectable text label. - */ - protected final String VALUE = "VALUE"; - - /** - * Style option for function <code>newLayout</code>. This will create a - * bolded, selectable header. It will also have an arrow image before the - * text (simply for decoration). - */ - protected final String HEADER = "HEADER"; - - /** - * Style option for function <code>newLayout</code>. This will create a - * bolded, unselectable label. - */ - protected final String PROPERTY = "PROPERTY"; + private RepositoryTaskOutlineNode taskOutlineModel = null; - protected final int HORZ_INDENT = 0; + private boolean expandedStateAttributes = false; protected Text summaryText; protected Button submitButton; - protected Table attachmentsTable; - - protected TableViewer attachmentsTableViewer; - - protected String[] attachmentsColumns = { "Description", "Type", "Creator", "Created" }; - - protected int[] attachmentsColumnWidths = { 200, 100, 100, 200 }; - - protected int scrollIncrement; + private Table attachmentsTable; - protected int scrollVertPageIncrement; + private TableViewer attachmentsTableViewer; - protected int scrollHorzPageIncrement; + private String[] attachmentsColumns = { "Description", "Type", "Creator", "Created" }; - protected StyledText currentSelectedText; + private int[] attachmentsColumnWidths = { 200, 100, 100, 200 }; - protected RetargetAction cutAction; + private Composite editorComposite; - protected RetargetAction pasteAction; + private TextViewer newCommentTextViewer; - protected Composite editorComposite; - - protected TextViewer newCommentTextViewer; - - protected org.eclipse.swt.widgets.List ccList; - - protected Text ccText; + private org.eclipse.swt.widgets.List ccList; private Section commentsSection; - protected Color backgroundIncoming; + private Color colorIncoming; - protected boolean hasAttributeChanges = false; + private boolean hasAttributeChanges = false; - protected boolean showAttachments = true; + private boolean showAttachments = true; - protected boolean attachContext = true; + private boolean attachContextEnabled = true; protected enum SECTION_NAME { ATTRIBTUES_SECTION("Attributes"), ATTACHMENTS_SECTION("Attachments"), DESCRIPTION_SECTION("Description"), COMMENTS_SECTION( @@ -321,8 +271,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } public ISelection getSelection() { - return new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), taskData - .getRepositoryKind(), "", true, taskData.getSummary()); + return new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), + taskData.getRepositoryKind(), "", true, taskData.getSummary()); } public void removeSelectionChangedListener(ISelectionChangedListener listener) { @@ -389,16 +339,14 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } }; - protected List<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); - - protected HashMap<CCombo, RepositoryTaskAttribute> comboListenerMap = new HashMap<CCombo, RepositoryTaskAttribute>(); + private List<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); private IRepositoryTaskSelection lastSelected = null; /** * Focuses on form widgets when an item in the outline is selected. */ - protected final ISelectionListener selectionListener = new ISelectionListener() { + private final ISelectionListener selectionListener = new ISelectionListener() { public void selectionChanged(IWorkbenchPart part, ISelection selection) { if ((part instanceof ContentOutline) && (selection instanceof StructuredSelection)) { Object select = ((StructuredSelection) selection).getFirstElement(); @@ -435,9 +383,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { private AbstractRepositoryTask repositoryTask; - protected Set<RepositoryTaskAttribute> changedAttributes; - - protected Map<SECTION_NAME, String> alternateSectionLabels = new HashMap<SECTION_NAME, String>(); + private Set<RepositoryTaskAttribute> changedAttributes; private Menu menu; @@ -447,26 +393,6 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { private Action historyAction; - protected class ComboSelectionListener extends SelectionAdapter { - - private CCombo combo; - - public ComboSelectionListener(CCombo combo) { - this.combo = combo; - } - - public void widgetSelected(SelectionEvent event) { - if (comboListenerMap.containsKey(combo)) { - if (combo.getSelectionIndex() > -1) { - String sel = combo.getItem(combo.getSelectionIndex()); - RepositoryTaskAttribute attribute = comboListenerMap.get(combo); - attribute.setValue(sel); - attributeChanged(attribute); - } - } - } - } - /** * Call upon change to attribute value * @@ -489,29 +415,38 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { return; } + initTaskEditor(site, (RepositoryTaskEditorInput) input); + + if (taskData != null) { + editorInput.setToolTipText(taskData.getLabel()); + taskOutlineModel = RepositoryTaskOutlineNode.parseBugReport(taskData); + } + hasAttributeChanges = hasVisibleAttributeChanges(); + TasksUiPlugin.getTaskListManager().getTaskList().addChangeListener(TASKLIST_CHANGE_LISTENER); + } + + protected void initTaskEditor(IEditorSite site, RepositoryTaskEditorInput input) { changedAttributes = new HashSet<RepositoryTaskAttribute>(); - editorInput = (RepositoryTaskEditorInput) input; + editorInput = input; repositoryTask = editorInput.getRepositoryTask(); repository = editorInput.getRepository(); taskData = editorInput.getTaskData(); connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind()); + setSite(site); setInput(input); - if (taskData != null) { - editorInput.setToolTipText(taskData.getLabel()); - taskOutlineModel = RepositoryTaskOutlineNode.parseBugReport(taskData); - } - hasAttributeChanges = hasVisibleAttributeChanges(); isDirty = false; - TasksUiPlugin.getTaskListManager().getTaskList().addChangeListener(TASKLIST_CHANGE_LISTENER); - } public AbstractRepositoryTask getRepositoryTask() { return repositoryTask; } + public Color getBackgroundIncoming() { + return colorIncoming; + } + // @Override // public void markDirty(boolean dirty) { // if (repositoryTask != null) { @@ -520,48 +455,35 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { // super.markDirty(dirty); // } - /** - * Update task state - */ - protected void updateTask() { - if (taskData == null) - return; - if (repositoryTask != null) { - TasksUiPlugin.getSynchronizationManager().saveOutgoing(repositoryTask, changedAttributes); - } - if (parentEditor != null) { - parentEditor.notifyTaskChanged(); - } - markDirty(false); - } +// /** +// * Update task state +// */ +// protected void updateTask() { +// if (taskData == null) +// return; +// if (repositoryTask != null) { +// TasksUiPlugin.getSynchronizationManager().saveOutgoing(repositoryTask, changedAttributes); +// } +// if (parentEditor != null) { +// parentEditor.notifyTaskChanged(); +// } +// markDirty(false); +// } protected abstract void validateInput(); /** - * Creates a new <code>AbstractRepositoryTaskEditor</code>. Sets up the - * default fonts and cut/copy/paste actions. + * Creates a new <code>AbstractRepositoryTaskEditor</code>. Sets up the default fonts and cut/copy/paste actions. */ public AbstractRepositoryTaskEditor(FormEditor editor) { // set the scroll increments so the editor scrolls normally with the // scroll wheel super(editor, "id", "label"); //$NON-NLS-1$ //$NON-NLS-2$ - FontData[] fd = TEXT_FONT.getFontData(); - int cushion = 4; - scrollIncrement = fd[0].getHeight() + cushion; - scrollVertPageIncrement = 0; - scrollHorzPageIncrement = 0; - } - - public String getNewCommentText() { - return addCommentsTextBox.getText(); } - /** - * - */ protected void createFormContent(final IManagedForm managedForm) { IThemeManager themeManager = getSite().getWorkbenchWindow().getWorkbench().getThemeManager(); - backgroundIncoming = themeManager.getCurrentTheme().getColorRegistry().get( + colorIncoming = themeManager.getCurrentTheme().getColorRegistry().get( TaskListColorsAndFonts.THEME_COLOR_TASKS_INCOMING_BACKGROUND); super.createFormContent(managedForm); @@ -630,7 +552,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { // } // } - protected void addHeaderControls() { + private void addHeaderControls() { ControlContribution repositoryLabelControl = new ControlContribution("Title") { //$NON-NLS-1$ protected Control createControl(Composite parent) { Composite composite = toolkit.createComposite(parent); @@ -718,8 +640,9 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { // } } - protected void createSections() { - createReportHeaderLayout(editorComposite); + private void createSections() { + + createSummaryLayout(editorComposite); Section attributesSection = createSection(editorComposite, getSectionLabel(SECTION_NAME.ATTRIBTUES_SECTION)); attributesSection.setExpanded(expandedStateAttributes || hasAttributeChanges); @@ -768,7 +691,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { getSite().setSelectionProvider(selectionProvider); } - protected void removeSections() { + private void removeSections() { menu = editorComposite.getMenu(); setMenu(editorComposite, null); for (Control control : editorComposite.getChildren()) { @@ -776,7 +699,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } } - protected void createReportHeaderLayout(Composite composite) { + protected void createSummaryLayout(Composite composite) { + addSummaryText(composite); Composite headerInfoComposite = toolkit.createComposite(composite); @@ -856,8 +780,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Utility method to create text field sets background to - * TaskListColorsAndFonts.COLOR_ATTRIBUTE_CHANGED if attribute has changed. + * Utility method to create text field sets background to TaskListColorsAndFonts.COLOR_ATTRIBUTE_CHANGED if + * attribute has changed. * * @param composite * @param attribute @@ -893,7 +817,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { }); } if (hasChanged(attribute)) { - text.setBackground(backgroundIncoming); + text.setBackground(colorIncoming); } return text; } @@ -911,40 +835,34 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } public String getSectionLabel(SECTION_NAME labelName) { - String label = alternateSectionLabels.get(labelName); - if (label != null) { - return label; - } else { - return labelName.getPrettyName(); - } + return labelName.getPrettyName(); } /** - * Creates the attribute section, which contains most of the basic - * attributes of the task (some of which are editable). + * Creates the attribute section, which contains most of the basic attributes of the task (some of which are + * editable). */ protected void createAttributeLayout(Composite attributesComposite) { int numColumns = ((GridLayout) attributesComposite.getLayout()).numColumns; int currentCol = 1; - for (RepositoryTaskAttribute attribute : taskData.getAttributes()) { + for (final RepositoryTaskAttribute attribute : taskData.getAttributes()) { if (attribute.isHidden()) { continue; } GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.horizontalSpan = 1; - data.horizontalIndent = HORZ_INDENT; if (attribute.hasOptions() && !attribute.isReadOnly()) { Label label = createLabel(attributesComposite, attribute); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label); - CCombo attributeCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY); + final CCombo attributeCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY); toolkit.adapt(attributeCombo, true, true); attributeCombo.setFont(TEXT_FONT); attributeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); if (hasChanged(attribute)) { - attributeCombo.setBackground(backgroundIncoming); + attributeCombo.setBackground(colorIncoming); } attributeCombo.setLayoutData(data); @@ -955,12 +873,23 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } } - String value = checkText(attribute.getValue()); + String value = attribute.getValue(); + if (value == null) { + value = ""; + } if (attributeCombo.indexOf(value) != -1) { attributeCombo.select(attributeCombo.indexOf(value)); } - attributeCombo.addSelectionListener(new ComboSelectionListener(attributeCombo)); - comboListenerMap.put(attributeCombo, attribute); + attributeCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + if (attributeCombo.getSelectionIndex() > -1) { + String sel = attributeCombo.getItem(attributeCombo.getSelectionIndex()); + attribute.setValue(sel); + attributeChanged(attribute); + } + } + }); currentCol += 2; } else { Label label = createLabel(attributesComposite, attribute); @@ -1040,15 +969,14 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { proposalProvider, "org.eclipse.ui.edit.text.contentAssist.proposals", new char[0]); IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); - controlDecoration.setDescriptionText(NLS.bind("Content Assist Available ({0})", bindingService - .getBestActiveBindingFormattedFor(adapter.getCommandId()))); + controlDecoration.setDescriptionText(NLS.bind("Content Assist Available ({0})", + bindingService.getBestActiveBindingFormattedFor(adapter.getCommandId()))); return adapter; } /** - * Creates an IContentProposalProvider to provide content assist proposals - * for the given attribute. + * Creates an IContentProposalProvider to provide content assist proposals for the given attribute. * * @param attribute * attribute for which to provide content assist. @@ -1059,8 +987,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Creates an IContentProposalProvider to provide content assist proposals - * for the given operation. + * Creates an IContentProposalProvider to provide content assist proposals for the given operation. * * @param operation * operation for which to provide content assist. @@ -1081,8 +1008,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Called to check if there's content assist available for the given - * attribute. + * Called to check if there's content assist available for the given attribute. * * @param attribute * the attribute @@ -1093,8 +1019,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Called to check if there's content assist available for the given - * operation. + * Called to check if there's content assist available for the given operation. * * @param operation * the operation @@ -1111,7 +1036,6 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { * The composite to add the text field to. */ protected void addSummaryText(Composite attributesComposite) { - Composite summaryComposite = toolkit.createComposite(attributesComposite); GridLayout summaryLayout = new GridLayout(2, false); summaryLayout.verticalSpacing = 0; @@ -1133,7 +1057,16 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { GridDataFactory.fillDefaults().grab(true, false).hint(DESCRIPTION_WIDTH, SWT.DEFAULT).applyTo( summaryText); - summaryText.addListener(SWT.KeyUp, new SummaryListener()); + summaryText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String sel = summaryText.getText(); + RepositoryTaskAttribute a = taskData.getAttribute(RepositoryTaskAttribute.SUMMARY); + if (!(a.getValue().equals(sel))) { + a.setValue(sel); + markDirty(true); + } + } + }); } } toolkit.paintBordersFor(summaryComposite); @@ -1233,8 +1166,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { final Action openWithBrowserAction = new Action(LABEL_BROWSER) { public void run() { - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); if (attachment != null) { TasksUiUtil.openUrl(attachment.getUrl(), false); } @@ -1244,8 +1176,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { final Action openWithDefaultAction = new Action(LABEL_DEFAULT_EDITOR) { public void run() { // browser shortcut - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); if (attachment == null) return; @@ -1271,8 +1202,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { final Action openWithTextEditorAction = new Action(LABEL_TEXT_EDITOR) { public void run() { - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page == null) { @@ -1289,8 +1219,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { final Action saveAction = new Action(SaveRemoteFileAction.TITLE) { public void run() { - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); /* Launch Browser */ FileDialog fileChooser = new FileDialog(attachmentsTable.getShell(), SWT.SAVE); String fname = attachment.getAttributeValue(RepositoryTaskAttribute.ATTACHMENT_FILENAME); @@ -1324,8 +1253,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { SaveRemoteFileAction save = new SaveRemoteFileAction(); try { - save.setInputStream(handler.getAttachmentAsStream(repository, - attachment, new NullProgressMonitor())); + save.setInputStream(handler.getAttachmentAsStream(repository, attachment, + new NullProgressMonitor())); save.setDestinationFilePath(filePath); save.run(); } catch (CoreException e) { @@ -1336,8 +1265,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { final Action copyToClipAction = new Action(LABEL_COPY_TO_CLIPBOARD) { public void run() { - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(attachment); job.setUser(true); job.schedule(); @@ -1351,8 +1279,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { return; } - RepositoryAttachment att = (RepositoryAttachment) (((StructuredSelection) e.getSelection()) - .getFirstElement()); + RepositoryAttachment att = (RepositoryAttachment) (((StructuredSelection) e.getSelection()).getFirstElement()); popupMenu.removeAll(); popupMenu.add(openMenu); @@ -1423,8 +1350,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { Button deleteAttachmentButton = null; if (supportsAttachmentDelete()) { - deleteAttachmentButton = toolkit - .createButton(attachmentControlsComposite, "Delete Attachment...", SWT.PUSH); + deleteAttachmentButton = toolkit.createButton(attachmentControlsComposite, "Delete Attachment...", SWT.PUSH); deleteAttachmentButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { @@ -1448,8 +1374,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { if (attachmentsTableViewer != null && attachmentsTableViewer.getSelection() != null && ((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement() != null) { - RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer - .getSelection()).getFirstElement()); + RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement()); deleteAttachment(attachment); submitToRepository(); } @@ -1504,8 +1429,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { descriptionTextViewer.getTextWidget().addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String newValue = descriptionTextViewer.getTextWidget().getText(); - RepositoryTaskAttribute attribute = (RepositoryTaskAttribute) taskData - .getAttribute(RepositoryTaskAttribute.DESCRIPTION); + RepositoryTaskAttribute attribute = (RepositoryTaskAttribute) taskData.getAttribute(RepositoryTaskAttribute.DESCRIPTION); attribute.setValue(newValue); attributeChanged(attribute); taskData.setDescription(newValue); @@ -1523,7 +1447,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } if (hasChanged(taskData.getAttribute(RepositoryTaskAttribute.DESCRIPTION))) { - descriptionTextViewer.getTextWidget().setBackground(backgroundIncoming); + descriptionTextViewer.getTextWidget().setBackground(colorIncoming); } descriptionTextViewer.getTextWidget().addListener(SWT.FocusIn, new DescriptionListener()); @@ -1644,7 +1568,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { ccListData.heightHint = 95; ccList.setLayoutData(ccListData); if (hasChanged(taskData.getAttribute(RepositoryTaskAttribute.USER_CC))) { - ccList.setBackground(backgroundIncoming); + ccList.setBackground(colorIncoming); } java.util.List<String> ccs = taskData.getCC(); if (ccs != null) { @@ -1692,12 +1616,12 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { /** * A listener for selection of the summary field. */ - protected class DescriptionListener implements Listener { + private class DescriptionListener implements Listener { public void handleEvent(Event event) { fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection( - new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), taskData - .getRepositoryKind(), getSectionLabel(SECTION_NAME.DESCRIPTION_SECTION), true, taskData - .getSummary())))); + new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), + taskData.getRepositoryKind(), getSectionLabel(SECTION_NAME.DESCRIPTION_SECTION), true, + taskData.getSummary())))); } } @@ -1746,7 +1670,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { expandableComposite.setExpanded(true); foundNew = true; } else if (isNewComment(taskComment)) { - expandableComposite.setBackground(backgroundIncoming); + expandableComposite.setBackground(colorIncoming); expandableComposite.setExpanded(true); foundNew = true; } @@ -1961,8 +1885,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Creates the button layout. This displays options and buttons at the - * bottom of the editor to allow actions to be performed on the bug. + * Creates the button layout. This displays options and buttons at the bottom of the editor to allow actions to be + * performed on the bug. */ protected void createActionsLayout(Composite composite) { Section section = createSection(composite, getSectionLabel(SECTION_NAME.ACTIONS_SECTION)); @@ -1987,8 +1911,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Adds buttons to this composite. Subclasses can override this method to - * provide different/additional buttons. + * Adds buttons to this composite. Subclasses can override this method to provide different/additional buttons. * * @param buttonComposite * Composite to add the buttons to. @@ -2010,7 +1933,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { toolkit.createLabel(buttonComposite, " "); ITask task = TasksUiPlugin.getTaskListManager().getTaskList().getTask(repository.getUrl(), taskData.getId()); - if (attachContext && task != null) { + if (attachContextEnabled && task != null) { addAttachContextButton(buttonComposite, task); } } @@ -2025,8 +1948,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Override to make hyperlink available. If not overridden hyperlink will - * simply not be displayed. + * Override to make hyperlink available. If not overridden hyperlink will simply not be displayed. * * @return url String form of url that points to task's past activity */ @@ -2034,35 +1956,16 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { return null; } - /** - * Make sure that a String that is <code>null</code> is to a null string - * - * @param text - * The text to check if it is null or not - * @return If the text is <code>null</code>, then return the null string (<code>""</code>). - * Otherwise, return the text. - */ - public static String checkText(String text) { - if (text == null) - return ""; - else - return text; - } - - public void saveTaskOffline(IProgressMonitor progressMonitor) { - // if (progressMonitor == null) { - // progressMonitor = new NullProgressMonitor(); - // } - // try { - // progressMonitor.beginTask("Saving...", IProgressMonitor.UNKNOWN); - // TasksUiPlugin.getDefault().getTaskDataManager().save(); - // } catch (Exception e) { - // MylarStatusHandler.fail(e, "Saving of offline task data failed", - // true); - // } finally { - // progressMonitor.done(); - // } - + protected void saveTaskOffline(IProgressMonitor progressMonitor) { + if (taskData == null) + return; + if (repositoryTask != null) { + TasksUiPlugin.getSynchronizationManager().saveOutgoing(repositoryTask, changedAttributes); + } + if (parentEditor != null) { + parentEditor.notifyTaskChanged(); + } + markDirty(false); } // once the following bug is fixed, this check for first focus is probably @@ -2097,9 +2000,9 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { @Override public void doSave(IProgressMonitor monitor) { - updateTask(); - updateEditorTitle(); + //updateTask(); saveTaskOffline(monitor); + updateEditorTitle(); } // // TODO: Remove once offline persistence is improved @@ -2137,7 +2040,6 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { if (waitCursor != null) { waitCursor.dispose(); } - isDisposed = true; // if (repositoryTask != null && repositoryTask.isDirty()) { // // Edits are being made to the outgoing object // // Must discard these unsaved changes @@ -2149,8 +2051,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Fires a <code>SelectionChangedEvent</code> to all listeners registered - * under <code>selectionChangedListeners</code>. + * Fires a <code>SelectionChangedEvent</code> to all listeners registered under + * <code>selectionChangedListeners</code>. * * @param event * The selection event. @@ -2167,67 +2069,19 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } } - /** - * A listener to check if the summary field was modified. - */ - protected class SummaryListener implements Listener { - public void handleEvent(Event event) { - handleSummaryEvent(); - } - } - - /** - * Check if the summary field was modified, and update it if necessary. - */ - public void handleSummaryEvent() { - String sel = summaryText.getText(); - RepositoryTaskAttribute a = taskData.getAttribute(RepositoryTaskAttribute.SUMMARY); - if (!(a.getValue().equals(sel))) { - a.setValue(sel); - markDirty(true); - } - } - /*----------------------------------------------------------* * CODE TO SCROLL TO A COMMENT OR OTHER PIECE OF TEXT *----------------------------------------------------------*/ - /** List of the StyledText's so that we can get the previous and the next */ - // protected ArrayList<StyledText> texts = new ArrayList<StyledText>(); - protected HashMap<Object, StyledText> textHash = new HashMap<Object, StyledText>(); - - protected List<StyledText> commentStyleText = new ArrayList<StyledText>(); + private HashMap<Object, StyledText> textHash = new HashMap<Object, StyledText>(); - /** Index into the styled texts */ - protected int textsindex = 0; + private List<StyledText> commentStyleText = new ArrayList<StyledText>(); - protected StyledText addCommentsTextBox = null; + private StyledText addCommentsTextBox = null; - // protected Text descriptionTextBox = null; protected TextViewer descriptionTextViewer = null; - // private FormText previousText = null; - - /** - * Selects the given object in the editor. - * - * @param commentNumber - * The comment number to be selected - */ - public void select(int commentNumber) { - if (commentNumber == -1) - return; - - for (Object o : textHash.keySet()) { - if (o instanceof TaskComment) { - if (((TaskComment) o).getNumber() == commentNumber) { - select(o, true); - } - } - } - } - - public void revealAllComments() { + private void revealAllComments() { if (commentsSection != null) { commentsSection.setExpanded(true); } @@ -2266,7 +2120,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { * @param highlight * Whether or not the object should be highlighted. */ - public void select(Object o, boolean highlight) { + private void select(Object o, boolean highlight) { if (textHash.containsKey(o)) { StyledText t = textHash.get(o); if (t != null) { @@ -2285,19 +2139,11 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } } - // public void selectDescription() { - // for (Object o : textHash.keySet()) { - // if (o.equals(editorInput.taskData.getDescription())) { - // select(o, true); - // } - // } - // } - - public void selectNewComment() { + private void selectNewComment() { focusOn(addCommentsTextBox, false); } - public void selectDescription() { + private void selectDescription() { focusOn(descriptionTextViewer.getTextWidget(), false); } @@ -2363,37 +2209,29 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { return super.getAdapter(adapter); } - public RepositoryTaskOutlineNode getOutlineModel() { - return taskOutlineModel; - } - public RepositoryTaskOutlinePage getOutline() { return outlinePage; } private boolean isDisposed = false; - protected Button[] radios; + private Button[] radios; - protected Control[] radioOptions; + private Control[] radioOptions; - protected Button attachContextButton; + private Button attachContextButton; - public AbstractRepositoryConnector connector; + private AbstractRepositoryConnector connector; private Cursor waitCursor; private boolean formBusy = false; - public boolean isDisposed() { - return isDisposed; - } - public void close() { Display activeDisplay = getSite().getShell().getDisplay(); activeDisplay.asyncExec(new Runnable() { public void run() { - if (getSite() != null && getSite().getPage() != null && !AbstractRepositoryTaskEditor.this.isDisposed()) + if (getSite() != null && getSite().getPage() != null && !getManagedForm().getForm().isDisposed()) if (parentEditor != null) { getSite().getPage().closeEditor(parentEditor, false); } else { @@ -2424,14 +2262,13 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * A listener for selection of the textbox where a new comment is entered - * in. + * A listener for selection of the textbox where a new comment is entered in. */ - protected class NewCommentListener implements Listener { + private class NewCommentListener implements Listener { public void handleEvent(Event event) { fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection( - new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), taskData - .getRepositoryKind(), "New Comment", false, taskData.getSummary())))); + new RepositoryTaskSelection(taskData.getId(), taskData.getRepositoryUrl(), + taskData.getRepositoryKind(), "New Comment", false, taskData.getSummary())))); } } @@ -2441,7 +2278,6 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { public void setSummaryText(String text) { this.summaryText.setText(text); - handleSummaryEvent(); } public void setDescriptionText(String text) { @@ -2592,9 +2428,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Creates a check box for adding the repository user to the cc list. Does - * nothing if the repository does not have a valid username, the repository - * user is the assignee, reporter or already on the the cc list. + * Creates a check box for adding the repository user to the cc list. Does nothing if the repository does not have a + * valid username, the repository user is the assignee, reporter or already on the the cc list. */ protected void addSelfToCC(Composite composite) { if (repository.getUserName() == null) { @@ -2619,8 +2454,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { FormToolkit toolkit = getManagedForm().getToolkit(); toolkit.createLabel(composite, ""); final Button addSelfButton = toolkit.createButton(composite, "Add me to CC", SWT.CHECK); - addSelfButton.setSelection(RepositoryTaskAttribute.TRUE.equals(taskData - .getAttributeValue(RepositoryTaskAttribute.ADD_SELF_CC))); + addSelfButton.setSelection(RepositoryTaskAttribute.TRUE.equals(taskData.getAttributeValue(RepositoryTaskAttribute.ADD_SELF_CC))); addSelfButton.setImage(TasksUiImages.getImage(TasksUiImages.PERSON)); addSelfButton.addSelectionListener(new SelectionAdapter() { @Override @@ -2645,14 +2479,20 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } } - public void setAttachContext(boolean attachContext) { - if (attachContextButton != null && attachContextButton.isEnabled()) { - attachContextButton.setSelection(attachContext); - } + public void setExpandAttributeSection(boolean expandAttributeSection) { + this.expandedStateAttributes = expandAttributeSection; } + public void setAttachContextEnabled(boolean attachContextEnabled) { + this.attachContextEnabled = attachContextEnabled; +// if (attachContextButton != null && attachContextButton.isEnabled()) { +// attachContextButton.setSelection(attachContext); +// } + } + + @Override public void showBusy(boolean busy) { - if (!isDisposed() && busy != formBusy) { + if (!isDisposed && busy != formBusy) { // parentEditor.showBusy(busy); if (synchronizeEditorAction != null) { synchronizeEditorAction.setEnabled(!busy); @@ -2698,7 +2538,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { public void submitToRepository() { setGlobalBusy(true); - updateTask(); + if (isDirty()) { saveTaskOffline(new NullProgressMonitor()); markDirty(false); @@ -2710,6 +2550,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { @Override protected IStatus run(IProgressMonitor monitor) { + AbstractRepositoryTask modifiedTask = null; try { monitor.beginTask("Submitting task", 3); String taskId = connector.getTaskDataHandler().postTaskData(repository, taskData, @@ -2726,7 +2567,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { "Task could not be created. No additional information was provided by the connector.")); } } else { - modifiedTask = (AbstractRepositoryTask) TasksUiPlugin.getTaskListManager().getTaskList() + modifiedTask = (AbstractRepositoryTask) TasksUiPlugin.getTaskListManager() + .getTaskList() .getTask(repository.getUrl(), taskData.getId()); } @@ -2738,6 +2580,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } modifiedTask.setSubmitting(true); + final AbstractRepositoryTask finalModifiedTask = modifiedTask; TasksUiPlugin.getSynchronizationManager().synchronize(connector, modifiedTask, true, new JobChangeAdapter() { @@ -2746,8 +2589,9 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { if (isNew) { close(); - TasksUiPlugin.getSynchronizationManager().setTaskRead(modifiedTask, true); - TasksUiUtil.openEditor(modifiedTask, false); + TasksUiPlugin.getSynchronizationManager().setTaskRead(finalModifiedTask, + true); + TasksUiUtil.openEditor(finalModifiedTask, false); } else { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { @@ -2765,8 +2609,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { // open local then via web browser... PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { - TasksUiUtil.openRepositoryTask(repository.getUrl(), taskData.getId(), connector - .getTaskWebUrl(taskData.getRepositoryUrl(), taskData.getId())); + TasksUiUtil.openRepositoryTask(repository.getUrl(), taskData.getId(), + connector.getTaskWebUrl(taskData.getRepositoryUrl(), taskData.getId())); } }); } @@ -2807,7 +2651,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { */ public void refreshEditor() { try { - if (!this.isDisposed) { + if (!getManagedForm().getForm().isDisposed()) { if (this.isDirty) { this.doSave(new NullProgressMonitor()); } @@ -2830,10 +2674,9 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { public void run() { if (taskData == null) { - parentEditor - .setMessage( - "Task data not available. Press synchronize button (right) to retrieve latest data.", - IMessageProvider.WARNING); + parentEditor.setMessage( + "Task data not available. Press synchronize button (right) to retrieve latest data.", + IMessageProvider.WARNING); } else { updateEditorTitle(); @@ -2878,8 +2721,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { } /** - * Used to prevent form menu from being disposed when disposing elements on - * the form during refresh + * Used to prevent form menu from being disposed when disposing elements on the form during refresh */ private void setMenu(Composite comp, Menu menu) { if (!comp.isDisposed()) { @@ -2976,8 +2818,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { markDirty(true); } else if (e.widget == radioOptions[i]) { RepositoryOperation o = taskData.getOperation(radios[i].getText()); - o.setOptionSelection(((CCombo) radioOptions[i]).getItem(((CCombo) radioOptions[i]) - .getSelectionIndex())); + o.setOptionSelection(((CCombo) radioOptions[i]).getItem(((CCombo) radioOptions[i]).getSelectionIndex())); if (taskData.getSelectedOperation() != null) taskData.getSelectedOperation().setChecked(false); @@ -3029,4 +2870,20 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage { validateInput(); } } + + public AbstractRepositoryConnector getConnector() { + return connector; + } + + public void setShowAttachments(boolean showAttachments) { + this.showAttachments = showAttachments; + } + + public String getCommonDateFormat() { + return HEADER_DATE_FORMAT; + } + + public Color getColorIncoming() { + return colorIncoming; + } } |