Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 92668 Details for
Bug 222833
[api] refactor LocalAttachment class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
clipboard.txt (text/plain), 12.08 KB, created by
Willian Mitsuda
on 2008-03-16 23:49:29 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Willian Mitsuda
Created:
2008-03-16 23:49:29 EDT
Size:
12.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.tasks.ui >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,320 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.tasks.ui.wizards; >+ >+import java.io.BufferedInputStream; >+import java.io.ByteArrayInputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileNotFoundException; >+import java.io.InputStream; >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.Wizard; >+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskAttachmentSource; >+import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; >+import org.eclipse.mylyn.internal.tasks.ui.SubmitTaskAttachmentJob; >+import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages; >+import org.eclipse.mylyn.monitor.core.StatusHandler; >+import org.eclipse.mylyn.tasks.core.AbstractAttachmentHandler; >+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; >+import org.eclipse.mylyn.tasks.core.RepositoryStatus; >+import org.eclipse.mylyn.tasks.core.TaskRepository; >+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; >+import org.eclipse.mylyn.tasks.ui.TasksUiUtil; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.TextTransfer; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; >+import org.eclipse.swt.graphics.ImageLoader; >+import org.eclipse.ui.PlatformUI; >+ >+/** >+ * A wizard to add a new attachment to a task report. >+ * >+ * @since 3.0 >+ * @author Jeff Pound >+ * @author Steffen Pingel >+ */ >+public class TaskAttachmentWizard extends Wizard { >+ >+ static class ClipboardSource extends AbstractTaskAttachmentSource { >+ >+ @Override >+ public InputStream createInputStream(IProgressMonitor monitor) throws CoreException { >+ String content = getContent(); >+ if (content != null) { >+ return new ByteArrayInputStream(content.getBytes()); >+ } >+ throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Invalid content type.")); >+ } >+ >+ protected String getContent() { >+ Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay()); >+ Object o = clipboard.getContents(TextTransfer.getInstance()); >+ clipboard.dispose(); >+ if (o instanceof String) { >+ return (String) o; >+ } >+ return null; >+ } >+ >+ @Override >+ public String getContentType() { >+ return "text/plain"; >+ } >+ >+ @Override >+ public long getLength() { >+ String content = getContent(); >+ if (content != null) { >+ return content.length(); >+ } >+ return -1; >+ } >+ >+ @Override >+ public String getName() { >+ return "clipboard.txt"; >+ } >+ >+ @Override >+ public boolean isLocal() { >+ return true; >+ } >+ >+ }; >+ >+ static class FileSource extends AbstractTaskAttachmentSource { >+ >+ private final File file; >+ >+ public FileSource(File file) { >+ this.file = file; >+ } >+ >+ @Override >+ public InputStream createInputStream(IProgressMonitor monitor) throws CoreException { >+ try { >+ return new FileInputStream(file); >+ } catch (FileNotFoundException e) { >+ throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, e.getMessage(), e)); >+ } >+ } >+ >+ @Override >+ public String getContentType() { >+ return null; >+ } >+ >+ @Override >+ public long getLength() { >+ return file.length(); >+ } >+ >+ @Override >+ public String getName() { >+ return file.getName(); >+ } >+ >+ @Override >+ public boolean isLocal() { >+ return true; >+ } >+ >+ } >+ >+ static class ImageSource extends AbstractTaskAttachmentSource { >+ >+ private final IImageCreator imageCreator; >+ >+ public ImageSource(IImageCreator imageCreator) { >+ this.imageCreator = imageCreator; >+ } >+ >+ @Override >+ public InputStream createInputStream(IProgressMonitor monitor) throws CoreException { >+ try { >+ return new BufferedInputStream(new FileInputStream(new File(getImageFileName()))); >+ } catch (FileNotFoundException e) { >+ throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, e.getMessage(), e)); >+ } >+ } >+ >+ private String getImageFileName() { >+ String path = TasksUiPlugin.getDefault().getDefaultDataDirectory(); >+ return path + "/" + getName(); >+ } >+ >+ @Override >+ public String getContentType() { >+ return "image/jpeg"; >+ } >+ >+ @Override >+ public long getLength() { >+ File file = new File(getImageFileName()); >+ return file.exists() ? file.length() : -1; >+ } >+ >+ @Override >+ public String getName() { >+ return "screenshot.jpg"; >+ } >+ >+ @Override >+ public boolean isLocal() { >+ return true; >+ } >+ >+ @Override >+ public void prepareAttachmentData() { >+ Image image = imageCreator.createImage(); >+ try { >+ ImageLoader loader = new ImageLoader(); >+ loader.data = new ImageData[] { image.getImageData() }; >+ loader.save(getImageFileName(), SWT.IMAGE_JPEG); >+ } finally { >+ image.dispose(); >+ } >+ } >+ >+ @Override >+ public void dispose() { >+ new File(getImageFileName()).delete(); >+ } >+ >+ } >+ >+ public enum Mode { >+ DEFAULT, SCREENSHOT >+ } >+ >+ static class StringSource extends ClipboardSource { >+ >+ private final String content; >+ >+ public StringSource(String content) { >+ this.content = content; >+ } >+ >+ @Override >+ protected String getContent() { >+ return content; >+ } >+ >+ } >+ >+ private static final String DIALOG_SETTINGS_KEY = "AttachmentWizard"; >+ >+ private Mode mode = Mode.DEFAULT; >+ >+ private final TaskAttachment taskAttachment; >+ >+ private final TaskRepository taskRepository; >+ >+ public TaskAttachmentWizard(TaskRepository taskRepository, TaskAttachment taskAttachment) { >+ this.taskRepository = taskRepository; >+ this.taskAttachment = taskAttachment; >+ >+ if (mode == Mode.SCREENSHOT) { >+ setWindowTitle("Attach Screenshot"); >+ setDefaultPageImageDescriptor(TasksUiImages.BANNER_SCREENSHOT); >+ } else { >+ setWindowTitle("Add Attachment"); >+ setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY); >+ } >+ >+ setNeedsProgressMonitor(true); >+ setDialogSettings(TasksUiPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS_KEY)); >+ } >+ >+ @Override >+ public void addPages() { >+ if (taskAttachment.getSource() == null) { >+ if (mode == Mode.SCREENSHOT) { >+ ScreenshotAttachmentPage shotPage = new ScreenshotAttachmentPage(); >+ taskAttachment.setSource(new ImageSource(shotPage)); >+ addPage(shotPage); >+ } else { >+ InputAttachmentSourcePage inputPage = new InputAttachmentSourcePage(null); >+ inputPage.setTaskAttachment(taskAttachment); >+ addPage(inputPage); >+ } >+ } >+ >+ addPage(createEditPage()); >+ } >+ >+ protected TaskAttachmentPage createEditPage() { >+ return new TaskAttachmentPage(taskAttachment); >+ } >+ >+ public TaskAttachment getAttachment() { >+ return taskAttachment; >+ } >+ >+ private void handleSubmitError(final CoreException exception) { >+ if (exception.getStatus().getCode() == RepositoryStatus.ERROR_REPOSITORY_LOGIN) { >+ if (TasksUiUtil.openEditRepositoryWizard(taskRepository) == Window.OK) { >+ // performFinish(); >+ } >+ } else { >+ StatusHandler.displayStatus("Attachment failed", exception.getStatus()); >+ } >+ } >+ >+ @Override >+ public boolean performFinish() { >+// attachPage.populateAttachment(); >+// final String path = inputPage.getAbsoluteAttachmentPath(); >+ // upload the attachment >+ final AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( >+ taskRepository.getConnectorKind()); >+ final AbstractAttachmentHandler attachmentHandler = connector.getAttachmentHandler(); >+ if (attachmentHandler == null) { >+ return false; >+ } >+ >+// final boolean attachContext = attachPage.getAttachContext(); >+ >+ final SubmitTaskAttachmentJob job = new SubmitTaskAttachmentJob(connector, taskRepository, taskAttachment); >+ try { >+ getContainer().run(true, true, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >+ job.run(monitor); >+ } >+ }); >+ } catch (InvocationTargetException e) { >+ if (e.getCause() instanceof CoreException) { >+ handleSubmitError((CoreException) e.getCause()); >+ } else { >+ StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Attachment failure", e)); >+ } >+ return false; >+ } catch (InterruptedException e) { >+ // cancelled >+ return false; >+ } >+ >+ return true; >+ } >+ >+ public void setMode(Mode mode) { >+ this.mode = mode; >+ } >+ >+} >#P org.eclipse.mylyn.tasks.core >Index: src/org/eclipse/mylyn/internal/tasks/core/AbstractTaskAttachmentSource.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/core/AbstractTaskAttachmentSource.java >diff -N src/org/eclipse/mylyn/internal/tasks/core/AbstractTaskAttachmentSource.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/core/AbstractTaskAttachmentSource.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,72 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.tasks.core; >+ >+import java.io.InputStream; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+public abstract class AbstractTaskAttachmentSource { >+ >+ /** >+ * Indicates that the attachment source model was modified, and attachment data needs to be recreated >+ */ >+ private boolean dirty = true; >+ >+ public abstract InputStream createInputStream(IProgressMonitor monitor) throws CoreException; >+ >+ public abstract boolean isLocal(); >+ >+ public abstract long getLength(); >+ >+ public abstract String getName(); >+ >+ public abstract String getContentType(); >+ >+ /** >+ * Marks the attachment source as dirty, so attachment data will be lazily recreated next time it is needed. >+ */ >+ public void markDirty() { >+ dirty = true; >+ } >+ >+ public boolean isDirty() { >+ return dirty; >+ } >+ >+ /** >+ * Ensures the attachment data is ready for use by clients of this object. >+ */ >+ public void prepareAttachmentData() { >+ if (!dirty) { >+ return; >+ } >+ >+ dirty = false; >+ createAttachmentData(); >+ } >+ >+ /** >+ * Creates the attachment data. >+ * <p> >+ * Subclasses may override. >+ */ >+ protected void createAttachmentData() { >+ } >+ >+ /** >+ * Disposes resources created by this attachment source model. >+ * <p> >+ * Subclasses may override. >+ */ >+ public void dispose() { >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 222833
:
92646
|
92648
| 92668 |
92669
|
98295