Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2005-10-27 17:40:13 -0400
committermkersten2005-10-27 17:40:13 -0400
commite08c8f65090de1f2a73e899f82399bb7e9b1af98 (patch)
tree22d95e4385cf665c429b5b2fc89b557543a697dc
parent66fecb21be0b70bdf2a1fcbe87525b9789453748 (diff)
downloadorg.eclipse.mylyn.tasks-e08c8f65090de1f2a73e899f82399bb7e9b1af98.tar.gz
org.eclipse.mylyn.tasks-e08c8f65090de1f2a73e899f82399bb7e9b1af98.tar.xz
org.eclipse.mylyn.tasks-e08c8f65090de1f2a73e899f82399bb7e9b1af98.zip
Patch for Bug #113682: Task data export wizard
-rw-r--r--org.eclipse.mylyn.tasks.ui/icons/wizban/banner-export.gifbin0 -> 1843 bytes
-rw-r--r--org.eclipse.mylyn.tasks.ui/plugin.xml22
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/MylarTasklistPlugin.java1
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizard.java206
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizardPage.java248
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskInputDialog.java133
6 files changed, 602 insertions, 8 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/icons/wizban/banner-export.gif b/org.eclipse.mylyn.tasks.ui/icons/wizban/banner-export.gif
new file mode 100644
index 000000000..762616867
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/icons/wizban/banner-export.gif
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.ui/plugin.xml b/org.eclipse.mylyn.tasks.ui/plugin.xml
index a798129e9..9ff698c83 100644
--- a/org.eclipse.mylyn.tasks.ui/plugin.xml
+++ b/org.eclipse.mylyn.tasks.ui/plugin.xml
@@ -42,7 +42,24 @@
id="org.eclipse.mylar.tasklist.report.ui.planningGameWizard"
name="Mylar Task Planner">
</wizard>
- </extension>
+ </extension>
+
+ <extension point="org.eclipse.ui.exportWizards">
+ <category
+ id="org.eclipse.mylar.exportCategory"
+ name="Mylar"/>
+ <wizard
+ id="org.eclipse.mylar.tasklist.ui.exportWizard"
+ name="Task Data"
+ class="org.eclipse.mylar.tasklist.ui.TaskDataExportWizard"
+ category="org.eclipse.mylar.exportCategory"
+ icon="icons/eview16/task-list.gif">
+ <description>
+ Export Mylar task data files to the file system.
+ </description>
+ </wizard>
+ </extension>
+
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="org.eclipse.jdt.ui.JavaPerspective">
@@ -95,3 +112,6 @@
</page>
</extension>
</plugin>
+
+
+
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/MylarTasklistPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/MylarTasklistPlugin.java
index a62f57047..b0823ccf7 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/MylarTasklistPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/MylarTasklistPlugin.java
@@ -62,6 +62,7 @@ public class MylarTasklistPlugin extends AbstractUIPlugin implements IStartup {
public static final String REPORT_OPEN_EXTERNAL = "org.eclipse.mylar.tasklist.report.open.external";
public static final String MULTIPLE_ACTIVE_TASKS = "org.eclipse.mylar.tasklist.active.multipe";
+ public static final String PLUGIN_ID = "org.eclipse.mylar.tasklist";
public static final String FILE_EXTENSION = ".xml";
public static final String TASK_ID = "org.eclipse.mylar.tasklist.userid";
public static final String DEFAULT_TASK_LIST_FILE = "tasklist" + FILE_EXTENSION;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizard.java
new file mode 100644
index 000000000..23ac56923
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizard.java
@@ -0,0 +1,206 @@
+package org.eclipse.mylar.tasklist.ui;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.mylar.core.MylarPlugin;
+import org.eclipse.mylar.core.internal.MylarContextManager;
+import org.eclipse.mylar.tasklist.ITask;
+import org.eclipse.mylar.tasklist.ITaskListCategory;
+import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
+import org.eclipse.mylar.tasklist.internal.TaskList;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Wizard for exporting tasklist data files to the file system. This wizard uses
+ * a single page: TaskDataExportWizardPage
+ *
+ * @author Wesley Coelho
+ */
+public class TaskDataExportWizard extends Wizard implements IExportWizard {
+
+ /**
+ * The name of the dialog store's section associated with the task data
+ * export wizard
+ */
+ private final static String SETTINGS_SECTION = "org.eclipse.mylar.tasklist.ui.exportWizard";
+
+ private final static String WINDOW_TITLE = "Export";
+
+ private TaskDataExportWizardPage exportPage = null;
+
+ public TaskDataExportWizard() {
+ IDialogSettings masterSettings = MylarTasklistPlugin.getDefault()
+ .getDialogSettings();
+ setDialogSettings(getSettingsSection(masterSettings));
+ setNeedsProgressMonitor(true); // ?
+ setWindowTitle(WINDOW_TITLE);
+ }
+
+ /**
+ * Finds or creates a dialog settings section that is used to make the
+ * dialog control settings persistent
+ */
+ public IDialogSettings getSettingsSection(IDialogSettings master) {
+ IDialogSettings settings = master.getSection(SETTINGS_SECTION);
+ if (settings == null) {
+ settings = master.addNewSection(SETTINGS_SECTION);
+ }
+ return settings;
+ }
+
+ public void addPages() {
+ exportPage = new TaskDataExportWizardPage();
+ exportPage.setWizard(this);
+ addPage(exportPage);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ // no initialization needed
+ }
+
+ public boolean canFinish() {
+ return exportPage.isPageComplete();
+ }
+
+ /**
+ * Called when the user clicks finish. Saves the task data.
+ * Waits until all overwrite decisions have been made before
+ * starting to save files. If any overwrite is canceled, no
+ * files are saved and the user must adjust the dialog.
+ */
+ public boolean performFinish() {
+ boolean overwrite = exportPage.overwrite();
+
+ //Get file paths to check for existence
+ String destDir = exportPage.getDestinationDirectory();
+ File destTaskListFile = new File(destDir + File.separator
+ + MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE);
+ File destActivationHistoryFile = new File(destDir
+ + File.separator
+ + MylarContextManager.CONTEXT_HISTORY_FILE_NAME
+ + MylarContextManager.FILE_EXTENSION);
+
+
+ //Prompt the user to confirm if ANY of the save operations will cause an overwrite
+ if(!overwrite){
+ if (exportPage.exportTaskList() && destTaskListFile.exists()){
+ if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task list file " + destTaskListFile.getPath() + " already exists. Do you want to overwrite it?")){
+ return false;
+ }
+ }
+
+ if (exportPage.exportActivationHistory() && destActivationHistoryFile.exists()){
+ if (!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "The task activation history file " + destActivationHistoryFile.getPath() + " already exists. Do you want to overwrite it?")){
+ return false;
+ }
+ }
+
+ if (exportPage.exportTaskContexts()) {
+ for(ITask task : getAllTasks())
+ {
+ File destTaskFile = new File(destDir + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+ if (destTaskFile.exists()){
+ if(!MessageDialog.openConfirm(getShell(), "Confirm File Replace", "Task context files already exist in " + destDir + ". Do you want to overwrite them?")){
+ return false;
+ }
+ else{
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ //Save the files
+
+ if (exportPage.exportTaskList()) {
+ MylarTasklistPlugin.getTaskListManager().saveTaskList();
+
+ String sourceTaskListPath = MylarPlugin.getDefault()
+ .getMylarDataDirectory()
+ + File.separator
+ + MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE;
+ File sourceTaskListFile = new File(sourceTaskListPath);
+
+ if (!copy(sourceTaskListFile, destTaskListFile)) {
+ MylarPlugin.fail(new Exception("Export Exception"), "Could not export task list file.", false);
+ }
+ }
+
+ if (exportPage.exportActivationHistory()) {
+ try {
+ MylarPlugin.getContextManager().saveActivityHistoryContextFileCopy(destActivationHistoryFile);
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "Could not export activity history context file", true);
+ }
+ }
+
+ if (exportPage.exportTaskContexts()) {
+ boolean errorDisplayed = false; //Prevent many repeated error messages
+ for(ITask task : getAllTasks())
+ {
+
+ if (!MylarPlugin.getContextManager().hasContext(task.getPath())){
+ continue; //Tasks without a context have no file to copy
+ }
+
+ File destTaskFile = new File(destDir + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+ File sourceTaskFile = new File(MylarPlugin.getDefault().getMylarDataDirectory() + File.separator + task.getPath() + MylarContextManager.FILE_EXTENSION);
+ if (!copy(sourceTaskFile, destTaskFile) && !errorDisplayed){
+ MylarPlugin.fail(new Exception("Export Exception: " + sourceTaskFile.getPath() + " -> " + destTaskFile.getPath()), "Could not export one or more task context files.", true);
+ errorDisplayed = true;
+ }
+ }
+ }
+
+ exportPage.saveSettings();
+ return true;
+ }
+
+ /** Returns all tasks in the task list root or a category in the task list */
+ protected List<ITask> getAllTasks(){
+ List<ITask> allTasks = new ArrayList<ITask>();
+ TaskList taskList = MylarTasklistPlugin.getTaskListManager().getTaskList();
+
+ allTasks.addAll(taskList.getRootTasks());
+
+ for (ITaskListCategory category : taskList.getCategories()){
+ allTasks.addAll(category.getChildren());
+ }
+
+ return allTasks;
+ }
+
+ // Note: Copied from MylarTaskListPlugin
+ private boolean copy(File src, File dst) {
+ try {
+ InputStream in = new FileInputStream(src);
+ OutputStream out = new FileOutputStream(dst);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ return true;
+ } catch (IOException ioe) {
+ return false;
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizardPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizardPage.java
new file mode 100644
index 000000000..0ef434a96
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/TaskDataExportWizardPage.java
@@ -0,0 +1,248 @@
+package org.eclipse.mylar.tasklist.ui;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.mylar.core.MylarPlugin;
+import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
+import org.eclipse.swt.SWT;
+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.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Wizard Page for the Task Data Export Wizard
+ *
+ * @author Wesley Coelho
+ */
+public class TaskDataExportWizardPage extends WizardPage {
+
+ private final static String PAGE_TITLE = "Export Mylar Task Data";
+
+ //Control fields
+ private Button taskListCheckBox = null;
+ private Button taskActivationHistoryCheckBox = null;
+ private Button taskContextsCheckBox = null;;
+ private Button browseButton = null;
+ private Text destDirText = null;
+ private Button overwriteCheckBox = null;
+
+ //Key values for the dialog settings object
+ private final static String SETTINGS_SAVED = "Settings saved";
+ private final static String TASKLIST_SETTING = "Tasklist setting";
+ private final static String ACTIVATION_HISTORY_SETTING = "Activation history setting";
+ private final static String CONTEXTS_SETTING = "Contexts setting";
+ private final static String DEST_DIR_SETTING = "Destination directory setting";
+ private final static String OVERWRITE_SETTING = "Overwrite setting";
+
+
+ public TaskDataExportWizardPage(){
+ super("org.eclipse.mylar.tasklist.exportPage", PAGE_TITLE,
+ MylarTasklistPlugin.imageDescriptorFromPlugin(MylarTasklistPlugin.PLUGIN_ID, "icons/wizban/banner-export.gif"));
+
+ setPageComplete(false);
+ }
+
+
+ /**
+ * Create the widgets on the page
+ */
+ public void createControl(Composite parent) {
+ try {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ container.setLayout(layout);
+
+ createFileSelectionControl(container);
+ createExportDirectoryControl(container);
+
+ overwriteCheckBox = createCheckBox(container, "Overwrite existing files without warning");
+
+ initSettings();
+
+ setControl(container);
+
+ setPageComplete(validate());
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "Could not create export wizard page", true);
+ }
+ }
+
+ /**
+ * Create widgets for selecting the data files to export
+ */
+ private void createFileSelectionControl(Composite parent){
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ GridLayout gl = new GridLayout(1, false);
+ group.setLayout(gl);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(gridData);
+ group.setText("Select data to export:");
+
+ taskListCheckBox = createCheckBox(group, "Task List");
+ taskActivationHistoryCheckBox = createCheckBox(group, "Task Activation History");
+ taskContextsCheckBox = createCheckBox(group, "Task Contexts");
+ }
+
+ /**
+ * Create widgets for specifying the destination directory
+ */
+ private void createExportDirectoryControl(Composite parent) {
+ Group destDirGroup= new Group(parent, SWT.SHADOW_ETCHED_IN);
+ destDirGroup.setText("Export destination folder");
+ destDirGroup.setLayout(new GridLayout(2, false));
+ destDirGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ destDirText = new Text(destDirGroup, SWT.BORDER);
+ destDirText.setEditable(false);
+ destDirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ destDirText.addModifyListener(new ModifyListener(){
+ public void modifyText(ModifyEvent e) {
+ controlChanged();
+ }
+ });
+
+
+ browseButton = new Button(destDirGroup, SWT.PUSH);
+ browseButton.setText("Browse...");
+ if (!MylarPlugin.getContextManager().hasActiveContext()) {
+ browseButton.setEnabled(true);
+ } else {
+ browseButton.setEnabled(false);
+ }
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setText("Folder Selection");
+ dialog.setMessage("Specify the destination folder for task data");
+ String dir = destDirText.getText();
+ dir = dir.replaceAll("\\\\", "/");
+ dialog.setFilterPath(dir);
+
+ dir = dialog.open();
+ if(dir == null || dir.equals(""))
+ return;
+ destDirText.setText(dir);
+ }
+ });
+ }
+
+
+ /**
+ * Initializes controls with values from the Dialog Settings object
+ */
+ protected void initSettings(){
+ IDialogSettings settings = getDialogSettings();
+
+ if (settings.get(SETTINGS_SAVED) == null){
+ //Set default values
+ taskListCheckBox.setSelection(true);
+ taskActivationHistoryCheckBox.setSelection(true);
+ taskContextsCheckBox.setSelection(true);
+ destDirText.setText("");
+ overwriteCheckBox.setSelection(true);
+ }
+ else{
+ //Retrieve previous values from the dialog settings
+ taskListCheckBox.setSelection(settings.getBoolean(TASKLIST_SETTING));
+ taskActivationHistoryCheckBox.setSelection(settings.getBoolean(ACTIVATION_HISTORY_SETTING));
+ taskContextsCheckBox.setSelection(settings.getBoolean(CONTEXTS_SETTING));
+ String directory = settings.get(DEST_DIR_SETTING);
+ if(directory != null){
+ destDirText.setText(settings.get(DEST_DIR_SETTING));
+ }
+ overwriteCheckBox.setSelection(settings.getBoolean(OVERWRITE_SETTING));
+ }
+ }
+
+ /**
+ * Saves the control values in the dialog settings to be used as
+ * defaults the next time the page is opened
+ */
+ public void saveSettings(){
+ IDialogSettings settings = getDialogSettings();
+
+ settings.put(TASKLIST_SETTING, taskListCheckBox.getSelection());
+ settings.put(ACTIVATION_HISTORY_SETTING, taskActivationHistoryCheckBox.getSelection());
+ settings.put(CONTEXTS_SETTING, taskContextsCheckBox.getSelection());
+ settings.put(DEST_DIR_SETTING, destDirText.getText());
+ settings.put(OVERWRITE_SETTING, overwriteCheckBox.getSelection());
+
+ settings.put(SETTINGS_SAVED, SETTINGS_SAVED);
+ }
+
+ /** Convenience method for creating a new checkbox */
+ protected Button createCheckBox(Composite parent, String text){
+ Button newButton= new Button(parent, SWT.CHECK);
+ newButton.setText(text);
+
+ newButton.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ controlChanged();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ //No action required
+ }
+ });
+
+ return newButton;
+ }
+
+ /** Called to indicate that a control's value has changed */
+ public void controlChanged(){
+ setPageComplete(validate());
+ }
+
+ /** Returns true if the information entered by the user is valid */
+ protected boolean validate(){
+
+ //Check that at least one type of data has been selected
+ if (!taskListCheckBox.getSelection() &&
+ !taskActivationHistoryCheckBox.getSelection() &&
+ !taskContextsCheckBox.getSelection()){
+ return false;
+ }
+
+ //Check that a destination dir has been specified
+ if (destDirText.getText().equals("")){
+ return false;
+ }
+
+ return true;
+ }
+
+ /** Returns the directory where data files are to be saved */
+ public String getDestinationDirectory(){
+ return destDirText.getText();
+ }
+
+ /** True if the user wants to export the task list */
+ public boolean exportTaskList(){
+ return taskListCheckBox.getSelection();
+ }
+
+ /** True if the user wants to export task activation history */
+ public boolean exportActivationHistory(){
+ return taskActivationHistoryCheckBox.getSelection();
+ }
+
+ /** True if the user wants to export task context files */
+ public boolean exportTaskContexts(){
+ return taskContextsCheckBox.getSelection();
+ }
+
+ /** True if the user wants to overwrite files by default*/
+ public boolean overwrite(){
+ return overwriteCheckBox.getSelection();
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskInputDialog.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskInputDialog.java
index e0d42636d..7562ac753 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskInputDialog.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasklist/ui/views/TaskInputDialog.java
@@ -19,16 +19,26 @@ import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
import org.eclipse.mylar.tasklist.contribution.DatePicker;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.TitleEvent;
+import org.eclipse.swt.browser.TitleListener;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.jface.dialogs.MessageDialog;
/**
* @author Ken Sueda
@@ -40,10 +50,11 @@ public class TaskInputDialog extends Dialog {
private static final String LABEL_DESCRIPTION = "Description:";
private String taskName = "";
private String priority = "P3";
- private String url = "http://";
+ private String taskURL = "http://";
private Date reminderDate = null;
private Text taskNameTextWidget = null;
private Text issueURLTextWidget = null;
+ private Button getDescButton = null;
public TaskInputDialog(Shell parentShell) {
super(parentShell);
@@ -100,22 +111,130 @@ public class TaskInputDialog extends Dialog {
issueURLTextWidget = new Text(composite, SWT.SINGLE | SWT.BORDER);
issueURLTextWidget.setText(getDefaultIssueURL());
GridData urlData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
- urlData.horizontalSpan = 3;
+ urlData.horizontalSpan = 2;
issueURLTextWidget.setLayoutData(urlData);
+ getDescButton = new Button(composite, SWT.PUSH);
+ getDescButton.setText("Get Description");
+ getDescButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+ setButtonStatus();
+
+
+ issueURLTextWidget.addKeyListener(new KeyListener() {
+ public void keyPressed(KeyEvent e) {
+ setButtonStatus();
+ }
+ public void keyReleased(KeyEvent e) {
+ setButtonStatus();
+ }
+ });
+
+ getDescButton.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ String desc = retrieveTaskDescription(issueURLTextWidget.getText());
+ if (!desc.equals("")){
+ taskNameTextWidget.setText(desc);
+ }
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
return composite;
}
+
+ /**Sets the Get Description button enabled or not depending on whether there is a URL specified*/
+ protected void setButtonStatus(){
+ String url = issueURLTextWidget.getText();
+
+ if (url.length() > 10 && (url.startsWith("http://") || url.startsWith("https://"))){
+ String defaultPrefix = MylarPlugin.getDefault().getPreferenceStore().getString(MylarTasklistPlugin.DEFAULT_URL_PREFIX);
+ if (url.equals(defaultPrefix)){
+ getDescButton.setEnabled(false);
+ }
+ else{
+ getDescButton.setEnabled(true);
+ }
+ }
+ else{
+ getDescButton.setEnabled(false);
+ }
+ }
+ /**
+ * Returns the default URL text for the task by first
+ * checking the contents of the clipboard and then using
+ * the default prefix preference if that fails
+ */
protected String getDefaultIssueURL(){
- String defaultURL = url;
+
+ String clipboardText = getClipboardText();
+ if ((clipboardText.startsWith("http://") || clipboardText.startsWith("https://") && clipboardText.length() > 10)){
+ return clipboardText;
+ }
String defaultPrefix = MylarPlugin.getDefault().getPreferenceStore().getString(MylarTasklistPlugin.DEFAULT_URL_PREFIX);
if (!defaultPrefix.equals("")){
- defaultURL = defaultPrefix;
+ return defaultPrefix;
}
- return defaultURL;
+ return taskURL;
+ }
+
+ /**
+ * Attempts to set the task description to the title from
+ * the specified url
+ */
+ protected String retrieveTaskDescription(final String url){
+
+ try {
+ final Shell shell = new Shell(Display.getDefault());
+ shell.setVisible(false);
+ Browser browser = new Browser(shell, SWT.NONE);
+ browser.setUrl(url);
+
+ browser.addTitleListener(new TitleListener(){
+
+ boolean changeCalled = false;
+
+ public void changed(TitleEvent event) {
+ if (!changeCalled){
+ changeCalled = true;
+ if (event.title.equals(url) ||
+ event.title.equals("Object not found!") ||
+ event.title.equals("No page to display") ||
+ event.title.equals("Cannot find server") ||
+ event.title.equals("Invalid Bug ID")){ //Last one is bugzilla-specific
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Task Description Error", "Could not retrieve a description from the specified web page.");
+ }
+ else{
+ taskNameTextWidget.setText(event.title);
+ }
+ }
+ }
+ });
+
+ } catch (RuntimeException e) {
+ MylarPlugin.fail(e, "could not open task web page", false);
+ }
+
+ return new String();
+ }
+
+ /**
+ * Returns the contents of the clipboard or "" if
+ * no text content was available
+ */
+ protected String getClipboardText(){
+ Clipboard clipboard = new Clipboard(Display.getDefault());
+ TextTransfer transfer = TextTransfer.getInstance();
+ String contents = (String) clipboard.getContents(transfer);
+ if (contents != null){
+ return contents;
+ }
+ else{
+ return new String();
+ }
}
public String getSelectedPriority() {
@@ -131,13 +250,13 @@ public class TaskInputDialog extends Dialog {
}
public String getIssueURL(){
- return url;
+ return taskURL;
}
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
taskName = taskNameTextWidget.getText();
- url = issueURLTextWidget.getText();
+ taskURL = issueURLTextWidget.getText();
} else {
taskName = null;
}

Back to the top