![]() |
![]() |
org.eclipse.mylyn.tasks.ui_3.7.1.v20120425-0100fileChooser.setFileName(lastFilename); String file = fileChooser.open(); if (file == null) { return; } lastFilename = file; fileNameField.setText(file); AttachmentSourcePage.this.updateWidgetEnablements(); } }); useWorkspaceButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!useWorkspaceButton.getSelection()) { return; } AttachmentSourcePage.this.clearErrorMessage(); showError = (!treeViewer.getSelection().isEmpty()); AttachmentSourcePage.this.updateWidgetEnablements(); } }); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { AttachmentSourcePage.this.clearErrorMessage(); AttachmentSourcePage.this.updateWidgetEnablements(); } }); treeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); if ((selection instanceof TreeSelection)) { TreeSelection treeSel = (TreeSelection)selection; Object res = treeSel.getFirstElement(); if (res != null) { if (((res instanceof IProject)) || ((res instanceof IFolder))) { if (treeViewer.getExpandedState(res)) { treeViewer.collapseToLevel(res, 1); } else { treeViewer.expandToLevel(res, 1); } } else if ((res instanceof IFile)) { getContainer().showPage(getNextPage()); } } } } }); useFileButton.setSelection(!initUseClipboard); setEnableWorkspaceAttachment(false); } private void addWorkspaceControls(Composite composite) { Composite newComp = new Composite(composite, 0); GridLayout layout = new GridLayout(1, false); marginLeft = 16; newComp.setLayout(layout); newComp.setLayoutData(new GridData(1808)); workspaceSelectLabel = new Label(newComp, 16384); workspaceSelectLabel.setText(Messages.AttachmentSourcePage_Select_the_location_of_the_attachment); treeViewer = new TreeViewer(newComp, 2048); treeViewer.getTree().setLayoutData(new GridData(4, 4, true, true)); treeViewer.setLabelProvider(new WorkbenchLabelProvider()); treeViewer.setContentProvider(new WorkbenchContentProvider()); treeViewer.setComparator(new ResourceComparator(1)); treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); } private void updateWidgetEnablements() { String error = null; boolean attachmentFound = false; int inputMethod = getInputMethod(); if (inputMethod == 1) { if (TaskAttachmentWizard.ClipboardTaskAttachmentSource.isSupportedType(getControl().getDisplay())) { attachmentFound = true; } else { error = Messages.AttachmentSourcePage_Clipboard_contains_an_unsupported_data; } } else if (inputMethod == 4) { attachmentFound = true; } else if (inputMethod == 2) { String path = fileNameField.getText(); if ((path != null) && (path.length() > 0)) { File file = new File(path); attachmentFound = (file.exists()) && (file.isFile()) && (file.length() > 0L); if (!attachmentFound) { error = Messages.AttachmentSourcePage_Cannot_locate_attachment_file; } } else { error = Messages.AttachmentSourcePage_No_file_name; } } else if (inputMethod == 3) { IResource[] resources = getResources(treeViewer.getSelection()); if ((resources == null) || (resources.length <= 0)) { error = Messages.AttachmentSourcePage_No_file_name; } else { IResource attachmentFile = resources[0]; if ((attachmentFile != null) && (attachmentFile.getType() == 1)) { File actualFile = attachmentFile.getRawLocation().toFile(); attachmentFound = (actualFile.exists()) && (actualFile.isFile()) && (actualFile.length() > 0L); if (!attachmentFound) { error = Messages.AttachmentSourcePage_Cannot_locate_attachment_file; } } } } setPageComplete(attachmentFound); if (showError) { setErrorMessage(error); } setEnableAttachmentFile(inputMethod == 2); setEnableWorkspaceAttachment(inputMethod == 3); } protected void setSourceName(String path) { if (path.length() > 0) { String[] currentItems = fileNameField.getItems(); int selectionIndex = -1; for (int i = 0; i < currentItems.length; i++) { if (currentItems[i].equals(path)) { selectionIndex = i; } } if (selectionIndex < 0) { int oldLength = currentItems.length; String[] newItems = new String[oldLength + 1]; System.arraycopy(currentItems, 0, newItems, 0, oldLength); newItems[oldLength] = path; fileNameField.setItems(newItems); selectionIndex = oldLength; } fileNameField.select(selectionIndex); } } private void clearErrorMessage() { setErrorMessage(null); } protected int getInputMethod() { if (useClipboardButton == null) { if (initUseClipboard) { return 1; } return 2; } if (useClipboardButton.getSelection()) { return 1; } if (useFileButton.getSelection()) { return 2; } return 3; } protected void setInputMethod(int input) { switch (input) { case 3: useWorkspaceButton.setSelection(true); useClipboardButton.setSelection(false); useFileButton.setSelection(false); break; case 1: storeClipboardContents(); useClipboardButton.setSelection(true); useFileButton.setSelection(false); useWorkspaceButton.setSelection(false); break; case 2: default: useFileButton.setSelection(true); useWorkspaceButton.setSelection(false); useClipboardButton.setSelection(false); } updateWidgetEnablements(); } private String getAttachmentFilePath() { if (fileNameField != null) { return fileNameField.getText(); } return null; } public String getAbsoluteAttachmentPath() { switch (getInputMethod()) { case 1: return Messages.AttachmentSourcePage__Clipboard_; case 4: return Messages.AttachmentSourcePage__Screenshot_; case 3: IResource[] resources = getResources(treeViewer.getSelection()); if ((resources.length > 0) && (resources[0].getRawLocation() != null)) { return resources[0].getRawLocation().toOSString(); } return null; } return getAttachmentFilePath(); } public static IResource[] getResources(ISelection selection) { ArrayList<IResource> tmp = new ArrayList(); Class<?> type = IResource.class; if ((selection instanceof IStructuredSelection)) { Object[] s = ((IStructuredSelection)selection).toArray(); Object[] arrayOfObject1; int j = (arrayOfObject1 = s).length; for (int i = 0; i < j; i++) { Object o = arrayOfObject1[i]; IResource resource = null; if (type.isInstance(o)) { resource = (IResource)o; } else if ((o instanceof ResourceMapping)) { try { ResourceTraversal[] travs = ((ResourceMapping)o).getTraversals( ResourceMappingContext.LOCAL_CONTEXT, null); if (travs == null) { break label241; } ResourceTraversal[] arrayOfResourceTraversal1; int m = (arrayOfResourceTraversal1 = travs).length; for (int k = 0; k < m; k++) { ResourceTraversal trav = arrayOfResourceTraversal1[k]; IResource[] resources = trav.getResources(); IResource[] arrayOfIResource1; int i1 = (arrayOfIResource1 = resources).length; for (int n = 0; n < i1; n++) { IResource resource2 = arrayOfIResource1[n]; if ((type.isInstance(resource2)) && (resource2.isAccessible())) { tmp.add(resource2); } } } } catch (CoreException localCoreException) {} } else if ((o instanceof IAdaptable)) { IAdaptable a = (IAdaptable)o; Object adapter = a.getAdapter(IResource.class); if (type.isInstance(adapter)) { resource = (IResource)adapter; } } label241: if ((resource != null) && (resource.isAccessible())) { tmp.add(resource); } } } return (IResource[])tmp.toArray(new IResource[tmp.size()]); } private void storeClipboardContents() { Control c = getControl(); if (c != null) { Clipboard clipboard = new Clipboard(c.getDisplay()); Object o = clipboard.getContents(TextTransfer.getInstance()); clipboard.dispose(); if ((o instanceof String)) { clipboardContents = ((String)o).trim(); } } } public String getClipboardContents() { return clipboardContents; } public void setClipboardContents(String attachContents) { clipboardContents = attachContents; } public void setUseClipboard(boolean b) { if (useClipboardButton != null) { useClipboardButton.setSelection(b); } initUseClipboard = b; } protected IDialogSettings getDialogSettings() { TasksUiPlugin plugin = TasksUiPlugin.getDefault(); IDialogSettings settings = plugin.getDialogSettings(); IDialogSettings section = settings.getSection("InputAttachmentSourcePage"); if (section == null) { section = settings.addNewSection("InputAttachmentSourcePage"); } return section; } public AbstractTaskAttachmentSource getSource() { switch (getInputMethod()) { case 1: return new TaskAttachmentWizard.ClipboardTaskAttachmentSource(); case 3: IResource[] resources = getResources(treeViewer.getSelection()); if (resources.length > 0) { return new FileTaskAttachmentSource(resources[0].getLocation().toFile()); } return null; } return new FileTaskAttachmentSource(new File(getAttachmentFilePath())); } } /* Location: * Qualified Name: org.eclipse.mylyn.internal.tasks.ui.wizards.AttachmentSourcePage * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.eclipse.mylyn.internal.tasks.ui.wizards; import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.tasks.ui.wizards.messages"; public static String EditRepositoryWizard_Failed_to_refactor_repository_urls; public static String EditRepositoryWizard_Properties_for_Task_Repository; public static String AttachmentSourcePage__Clipboard_; public static String AttachmentSourcePage__Screenshot_; public static String AttachmentSourcePage_Browse_; public static String AttachmentSourcePage_Cannot_locate_attachment_file; public static String AttachmentSourcePage_Clipboard; public static String AttachmentSourcePage_Clipboard_contains_an_unsupported_data; public static String AttachmentSourcePage_Clipboard_supports_text_and_image_attachments_only; public static String AttachmentSourcePage_File; public static String AttachmentSourcePage_No_file_name; public static String AttachmentSourcePage_Select_attachment_source; public static String AttachmentSourcePage_Select_File_Dialog_Title; public static String AttachmentSourcePage_Select_the_location_of_the_attachment; public static String AttachmentSourcePage_Workspace; public static String NewQueryWizard_New_Repository_Query; public static String NewTaskWizard_New_Task; public static String NewWebTaskPage_Create_via_Web_Browser; public static String NewWebTaskPage_New_Task; public static String NewWebTaskPage_Once_submitted_synchronize_queries_or_add_the_task_to_a_category; public static String NewWebTaskPage_This_will_open_a_web_browser_that_can_be_used_to_create_a_new_task; public static String AttachmentPreviewPage_A_preview_the_type_X_is_currently_not_available; public static String AttachmentPreviewPage_Attachment_Preview; public static String AttachmentPreviewPage_Could_not_create_preview; public static String AttachmentPreviewPage_Preparing_preview; public static String AttachmentPreviewPage_Review_the_attachment_before_submitting; public static String AttachmentPreviewPage_Run_in_background; public static String SelectRepositoryConnectorPage_discoveryProblemMessage; public static String SelectRepositoryConnectorPage_discoveryProblemTitle; public static String SelectRepositoryConnectorPage_activateDiscovery; public static String SelectRepositoryConnectorPage_Select_a_task_repository_type; public static String SelectRepositoryConnectorPage_You_can_connect_to_an_existing_account_using_one_of_the_installed_connectors; public static String SelectRepositoryPage_Add_new_repositories_using_the_X_view; public static String SelectRepositoryPage_Select_a_repository; public static String TaskAttachmentWizard_Add_Attachment; public static String TaskAttachmentWizard_Attach_Screenshot; public static String TaskAttachmentWizard_Attaching_context; public static String TaskAttachmentWizard_Attachment_Failed; public static String TaskAttachmentWizard_Screenshot; public static String TaskDataExportWizard_Export; public static String TaskDataExportWizard_export_failed; public static String TaskDataExportWizardPage_Browse_; public static String TaskDataExportWizardPage_Export_Mylyn_Task_Data; public static String TaskDataExportWizardPage_File; public static String TaskDataExportWizardPage_Folder; public static String TaskDataExportWizardPage_Folder_Selection; public static String TaskDataExportWizardPage_Please_choose_an_export_destination; public static String TaskDataExportWizardPage_Specify_the_destination_folder_for_task_data; public static String TaskDataImportWizard_confirm_overwrite; public static String TaskDataImportWizard_could_not_be_found; public static String TaskDataImportWizard_existing_task_data_about_to_be_erased_proceed; public static String TaskDataImportWizard_File_not_found; public static String TaskDataImportWizard_Import; public static String TaskDataImportWizard_Import_Error; public static String TaskDataImportWizard_Importing_Data; public static String TaskDataImportWizard_task_data_import_failed; public static String TaskDataImportWizardPage_Restore_tasks_from_history; public static String TaskDataImportWizardPage_Browse_; public static String TaskDataImportWizardPage_From_snapshot; public static String TaskDataImportWizardPage_From_zip_file; public static String TaskDataImportWizardPage_Import_method_backup; public static String TaskDataImportWizardPage_Import_method_zip; public static String TaskDataImportWizardPage_Import_Settings_saved; public static String TaskDataImportWizardPage_Import_Source_zip_file_setting; public static String TaskDataImportWizardPage_Importing_overwrites_current_tasks_and_repositories; public static String TaskDataImportWizardPage__unspecified_; public static String TaskDataImportWizardPage_Zip_File_Selection; public static String AbstractRepositoryQueryPage_A_category_with_this_name_already_exists; public static String AbstractRepositoryQueryPage_Enter_query_parameters; public static String AbstractRepositoryQueryPage_If_attributes_are_blank_or_stale_press_the_Update_button; public static String AbstractRepositoryQueryPage_Please_specify_a_title_for_the_query; public static String AbstractRepositoryQueryPage_A_query_with_this_name_already_exists; public static String AbstractRepositorySettingsPage_A_repository_with_this_name_already_exists; public static String AbstractRepositorySettingsPage_Additional_Settings; public static String AbstractRepositorySettingsPage_Anonymous_Access; public static String AbstractRepositorySettingsPage_Authentication_credentials_are_valid; public static String AbstractRepositorySettingsPage_Change_account_settings; public static String AbstractRepositorySettingsPage_Change_Settings; public static String AbstractRepositorySettingsPage_Character_encoding; public static String AbstractRepositorySettingsPage_Create_new_account; public static String AbstractRepositorySettingsPage_Default__; public static String AbstractRepositorySettingsPage_Disconnected; public static String AbstractRepositorySettingsPage_Enable_http_authentication; public static String AbstractRepositorySettingsPage_Enable_proxy_authentication; public static String AbstractRepositorySettingsPage_Enter_a_user_id_Message0; public static String AbstractRepositorySettingsPage_Enter_a_valid_server_url; public static String AbstractRepositorySettingsPage_Http_Authentication; public static String AbstractRepositorySettingsPage_Internal_error_validating_repository; public static String AbstractRepositorySettingsPage_Label_; public static String AbstractRepositorySettingsPage_Other; public static String AbstractRepositorySettingsPage_Password_; public static String AbstractRepositorySettingsPage_certificate_settings; public static String AbstractRepositorySettingsPage_Enable_certificate_authentification; public static String AbstractRepositorySettingsPage_CertificateFile_; public static String AbstractRepositorySettingsPage_ChooseCertificateFile_; public static String AbstractRepositorySettingsPage_CertificatePassword_; public static String AbstractRepositorySettingsPage_Problems_encountered_determining_available_charsets; public static String AbstractRepositorySettingsPage_Proxy_host_address_; public static String AbstractRepositorySettingsPage_Proxy_host_port_; public static String AbstractRepositorySettingsPage_Proxy_Server_Configuration; public static String AbstractRepositorySettingsPage_Repository_already_exists; public static String AbstractRepositorySettingsPage_Repository_is_valid; public static String AbstractRepositorySettingsPage_Repository_url_is_invalid; public static String AbstractRepositorySettingsPage_Save_Password; public static String AbstractRepositorySettingsPage_Server_; public static String AbstractRepositorySettingsPage_Unable_to_authenticate_with_repository; public static String AbstractRepositorySettingsPage_Use_global_Network_Connections_preferences; public static String AbstractRepositorySettingsPage_User_ID_; public static String AbstractRepositorySettingsPage_Validate_on_Finish; public static String AbstractRepositorySettingsPage_Validate_Settings; public static String AbstractRepositorySettingsPage_Validate_Settings_Button_Label; public static String AbstractRepositorySettingsPage_Validating_server_settings; public static String NewTaskWizard_Create_Task; public static String NewTaskWizard_Error_creating_new_task; public static String NewTaskWizard_Failed_to_create_new_task_; public static String NewWebTaskWizard_New_Task; public static String NewWebTaskWizard_This_connector_does_not_provide_a_rich_task_editor_for_creating_tasks; public static String RepositoryQueryWizard_Edit_Repository_Query; public static String TaskAttachmentPage_ATTACHE_CONTEXT; public static String TaskAttachmentPage_Attachment_Details; public static String TaskAttachmentPage_Comment; public static String TaskAttachmentPage_Content_Type; public static String TaskAttachmentPage_Description; public static String TaskAttachmentPage_Enter_a_description; public static String TaskAttachmentPage_Enter_a_file_name; public static String TaskAttachmentPage_File; public static String TaskAttachmentPage_Patch; public static String TaskAttachmentPage_Replace_existing_attachment_Label; public static String TaskAttachmentPage_Verify_the_content_type_of_the_attachment; public static String AbstractTaskRepositoryPage_Validation_failed; public static String LocalRepositorySettingsPage_Configure_the_local_repository; public static String LocalRepositorySettingsPage_Local_Repository_Settings; public static String QueryWizardDialog_Clear_Fields; public static String QueryWizardDialog_Update_Attributes_from_Repository; public static String AbstractRepositoryQueryPage2__Refresh_From_Repository; public static String AbstractRepositoryQueryPage2__Title_; public static String AbstractRepositoryQueryPage2_Clear_Fields; public static String AbstractRepositoryQueryPage2_Create_a_Query_Page_Description; public static String AbstractRepositoryQueryPage2_Enter_a_title; public static String AbstractRepositoryQueryPage2_Enter_query_parameters; public static String AbstractRepositoryQueryPage2_No_repository_available_please_add_one_using_the_Task_Repositories_view; public static String AbstractRepositoryQueryPage2_Refresh_Configuration_Button_Label; public static String AbstractRepositoryQueryPage2_Update_Attributes_Failed; static {} public static void reloadMessages() { NLS.initializeMessages("org.eclipse.mylyn.internal.tasks.ui.wizards.messages", Messages.class); } } /* Location: * Qualified Name: org.eclipse.mylyn.internal.tasks.ui.wizards.Messages * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.eclipse.mylyn.internal.tasks.ui.wizards; import java.lang.reflect.InvocationTargetException; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.jface.wizard.Wizard; import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryDelta; import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryDelta.Type; import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager; import org.eclipse.mylyn.internal.tasks.ui.RefactorRepositoryUrlOperation; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.tasks.core.ITaskActivityManager; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; import org.eclipse.mylyn.tasks.ui.TasksUi; import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage; import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.statushandlers.StatusManager; public class EditRepositoryWizard extends Wizard implements INewWizard { private ITaskRepositoryPage settingsPage; private final TaskRepository repository; public EditRepositoryWizard(TaskRepository repository) { this.repository = repository; setNeedsProgressMonitor(true); setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY_SETTINGS); setWindowTitle(Messages.EditRepositoryWizard_Properties_for_Task_Repository); } public boolean performFinish() { if (canFinish()) { boolean finishAccepted = settingsPage.preFinish(repository); if (finishAccepted) { String oldUrl = repository.getRepositoryUrl(); String newUrl = settingsPage.getRepositoryUrl(); if ((oldUrl != null) && (newUrl != null) && (!oldUrl.equals(newUrl))) { TasksUi.getTaskActivityManager().deactivateActiveTask(); RefactorRepositoryUrlOperation operation = new RefactorRepositoryUrlOperation(repository, oldUrl, newUrl); try { getContainer().run(true, false, operation); } catch (InvocationTargetException e) { StatusManager.getManager().handle( new Status(2, "org.eclipse.mylyn.tasks.ui", Messages.EditRepositoryWizard_Failed_to_refactor_repository_urls, e), 3); return false; } catch (InterruptedException localInterruptedException) {} } if (!repository.getConnectorKind().equals("local")) { repository.setRepositoryUrl(newUrl); } settingsPage.performFinish(repository); if ((oldUrl != null) && (newUrl != null) && (!oldUrl.equals(newUrl))) { TasksUiPlugin.getRepositoryManager().notifyRepositoryUrlChanged(repository, oldUrl); } TasksUiPlugin.getRepositoryManager().notifyRepositorySettingsChanged(repository, new TaskRepositoryDelta(TaskRepositoryDelta.Type.ALL)); TasksUiPlugin.getExternalizationManager().requestSave(); } return finishAccepted; } return false; } public void init(IWorkbench workbench, IStructuredSelection selection) {} public void addPages() { AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(repository.getConnectorKind()); settingsPage = connectorUi.getSettingsPage(repository); if ((settingsPage instanceof AbstractRepositorySettingsPage)) { ((AbstractRepositorySettingsPage)settingsPage).setRepository(repository); ((AbstractRepositorySettingsPage)settingsPage).setVersion(repository.getVersion()); } settingsPage.setWizard(this); addPage(settingsPage); } public boolean canFinish() { return settingsPage.isPageComplete(); } public ITaskRepositoryPage getSettingsPage() { return settingsPage; } public TaskRepository getRepository() { return repository; } } /* Location: * Qualified Name: org.eclipse.mylyn.internal.tasks.ui.wizards.EditRepositoryWizard * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.eclipse.mylyn.internal.tasks.ui.wizards; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.HashSet; import java.util.Set; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentModel; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class AttachmentPreviewPage extends WizardPage { private static final String DIALOG_SETTING_RUN_IN_BACKGROUND = "run-in-background"; private static final String DIALOG_SETTINGS_SECTION_ATTACHMENTS_WIZARD = "attachments-wizard"; protected static final int MAX_TEXT_SIZE = 50000; private static final String PAGE_NAME = "PreviewAttachmentPage"; private final Set<String> imageTypes; private final TaskAttachmentModel model; private Button runInBackgroundButton; private ScrolledComposite scrolledComposite; private final Set<String> textTypes; private Composite contentComposite; public AttachmentPreviewPage(TaskAttachmentModel model) { super("PreviewAttachmentPage"); this.model = model; setTitle(Messages.AttachmentPreviewPage_Attachment_Preview); setDescription(Messages.AttachmentPreviewPage_Review_the_attachment_before_submitting); textTypes = new HashSet(); textTypes.add("text/plain"); textTypes.add("text/html"); textTypes.add("application/xml"); imageTypes = new HashSet(); imageTypes.add("image/jpeg"); imageTypes.add("image/gif"); imageTypes.add("image/png"); imageTypes.add("image/tiff"); } private void adjustScrollbars(Rectangle imgSize) { Rectangle clientArea = scrolledComposite.getClientArea(); ScrollBar hBar = scrolledComposite.getHorizontalBar(); hBar.setMinimum(0); hBar.setMaximum(width - 1); hBar.setPageIncrement(width); hBar.setIncrement(10); ScrollBar vBar = scrolledComposite.getVerticalBar(); vBar.setMinimum(0); vBar.setMaximum(height - 1); vBar.setPageIncrement(height); vBar.setIncrement(10); } public void createControl(Composite parent) { Composite composite = new Composite(parent, 0); composite.setLayout(new GridLayout()); setControl(composite); contentComposite = new Composite(composite, 0); contentComposite.setLayoutData(new GridData(1808)); contentComposite.setLayout(new GridLayout()); runInBackgroundButton = new Button(composite, 32); runInBackgroundButton.setText(Messages.AttachmentPreviewPage_Run_in_background); IDialogSettings settings = TasksUiPlugin.getDefault().getDialogSettings(); IDialogSettings attachmentsSettings = settings.getSection("attachments-wizard"); if (attachmentsSettings != null) { runInBackgroundButton.setSelection(attachmentsSettings.getBoolean("run-in-background")); } Dialog.applyDialogFont(composite); } public void dispose() { IDialogSettings settings = TasksUiPlugin.getDefault().getDialogSettings(); IDialogSettings attachmentsSettings = settings.getSection("attachments-wizard"); if (attachmentsSettings == null) { attachmentsSettings = settings.addNewSection("attachments-wizard"); } attachmentsSettings.put("run-in-background", runInBackgroundButton.getSelection()); super.dispose(); } public void setVisible(boolean visible) { if (visible) { Control[] children = contentComposite.getChildren(); Control[] arrayOfControl1; int j = (arrayOfControl1 = children).length; for (int i = 0; i < j; i++) { Control control = arrayOfControl1[i]; control.dispose(); } if ((isTextAttachment()) || (isImageAttachment())) { Object content = getContent(contentComposite); if ((content instanceof String)) { createTextPreview(contentComposite, (String)content); } else if ((content instanceof Image)) { createImagePreview(contentComposite, (Image)content); } } else { createGenericPreview(contentComposite); } contentComposite.layout(true, true); } Dialog.applyDialogFont(contentComposite); super.setVisible(visible); } private void createErrorPreview(Composite composite, String message) { Label label = new Label(composite, 0); label.setLayoutData(new GridData(1808)); label.setText(message); } private void createGenericPreview(Composite composite) { Label label = new Label(composite, 0); label.setLayoutData(new GridData(1808)); String name = model.getSource().getName(); TaskAttachmentMapper taskAttachment = TaskAttachmentMapper.createFrom(model.getAttribute()); if (taskAttachment.getFileName() != null) { name = taskAttachment.getFileName(); } label.setText(MessageFormat.format( Messages.AttachmentPreviewPage_A_preview_the_type_X_is_currently_not_available, new Object[] { name, model.getContentType() })); } private void createImagePreview(Composite composite, final Image bufferedImage) { scrolledComposite = new ScrolledComposite(composite, 2816); scrolledComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); Composite canvasComposite = new Composite(scrolledComposite, 0); canvasComposite.setLayout(GridLayoutFactory.fillDefaults().create()); Canvas canvas = new Canvas(canvasComposite, 262144); final Rectangle imgSize = bufferedImage.getBounds(); canvas.setLayoutData(GridDataFactory.fillDefaults() .align(16777216, 16777216) .grab(true, true) .hint(width, height) .create()); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent event) { gc.drawImage(bufferedImage, 0, 0); } }); canvas.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { bufferedImage.dispose(); } }); canvas.setSize(width, height); scrolledComposite.setMinSize(width, height); scrolledComposite.setContent(canvasComposite); scrolledComposite.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent event) { AttachmentPreviewPage.this.adjustScrollbars(imgSize); } }); adjustScrollbars(imgSize); } private void createTextPreview(Composite composite, String contents) { Text text = new Text(composite, 2826); GridData gd = new GridData(1808); heightHint = getBoundsy; widthHint = getBoundsx; text.setLayoutData(gd); text.setText(contents); } private Object getContent(final Composite composite) { final Object[] result = new Object[1]; try { getContainer().run(true, false, new IRunnableWithProgress() { /* Error */ public void run(org.eclipse.core.runtime.IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // Byte code: // 0: aload_1 // 1: getstatic 142 org/eclipse/mylyn/internal/tasks/ui/wizards/Messages:AttachmentPreviewPage_Preparing_preview Ljava/lang/String; // 4: iconst_m1 // 5: invokeinterface 165 3 0 // 10: aload_0 // 11: getfield 140 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:this$0 Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage; // 14: invokestatic 157 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage:access$1 (Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage;)Lorg/eclipse/mylyn/tasks/core/data/TaskAttachmentModel; // 17: invokevirtual 160 org/eclipse/mylyn/tasks/core/data/TaskAttachmentModel:getSource ()Lorg/eclipse/mylyn/tasks/core/data/AbstractTaskAttachmentSource; // 20: aload_1 // 21: invokevirtual 159 org/eclipse/mylyn/tasks/core/data/AbstractTaskAttachmentSource:createInputStream (Lorg/eclipse/core/runtime/IProgressMonitor;)Ljava/io/InputStream; // 24: astore_2 // 25: aload_0 // 26: getfield 140 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:this$0 Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage; // 29: invokestatic 155 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage:access$2 (Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage;)Z // 32: ifeq +87 -> 119 // 35: new 68 java/lang/StringBuilder // 38: dup // 39: invokespecial 149 java/lang/StringBuilder:<init> ()V // 42: astore_3 // 43: new 62 java/io/BufferedReader // 46: dup // 47: new 65 java/io/InputStreamReader // 50: dup // 51: aload_2 // 52: invokespecial 146 java/io/InputStreamReader:<init> (Ljava/io/InputStream;)V // 55: invokespecial 143 java/io/BufferedReader:<init> (Ljava/io/Reader;)V // 58: astore 4 // 60: goto +17 -> 77 // 63: aload_3 // 64: aload 5 // 66: invokevirtual 151 java/lang/StringBuilder:append (Ljava/lang/String;)Ljava/lang/StringBuilder; // 69: pop // 70: aload_3 // 71: ldc 2 // 73: invokevirtual 151 java/lang/StringBuilder:append (Ljava/lang/String;)Ljava/lang/StringBuilder; // 76: pop // 77: aload 4 // 79: invokevirtual 144 java/io/BufferedReader:readLine ()Ljava/lang/String; // 82: dup // 83: astore 5 // 85: ifnull +21 -> 106 // 88: aload_3 // 89: invokevirtual 148 java/lang/StringBuilder:length ()I // 92: ldc 1 // 94: if_icmpge +12 -> 106 // 97: aload_1 // 98: invokeinterface 164 1 0 // 103: ifeq -40 -> 63 // 106: aload_0 // 107: getfield 139 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:val$result [Ljava/lang/Object; // 110: iconst_0 // 111: aload_3 // 112: invokevirtual 150 java/lang/StringBuilder:toString ()Ljava/lang/String; // 115: aastore // 116: goto +80 -> 196 // 119: aload_0 // 120: getfield 140 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:this$0 Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage; // 123: invokestatic 156 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage:access$3 (Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage;)Z // 126: ifeq +70 -> 196 // 129: invokestatic 162 org/eclipse/swt/widgets/Display:getDefault ()Lorg/eclipse/swt/widgets/Display; // 132: new 77 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4$1 // 135: dup // 136: aload_0 // 137: aload_2 // 138: aload_0 // 139: getfield 141 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:val$composite Lorg/eclipse/swt/widgets/Composite; // 142: aload_0 // 143: getfield 139 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4:val$result [Ljava/lang/Object; // 146: invokespecial 158 org/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4$1:<init> (Lorg/eclipse/mylyn/internal/tasks/ui/wizards/AttachmentPreviewPage$4;Ljava/io/InputStream;Lorg/eclipse/swt/widgets/Composite;[Ljava/lang/Object;)V // 149: invokevirtual 161 org/eclipse/swt/widgets/Display:syncExec (Ljava/lang/Runnable;)V // 152: goto +44 -> 196 // 155: astore_3 // 156: new 69 java/lang/reflect/InvocationTargetException // 159: dup // 160: aload_3 // 161: invokespecial 152 java/lang/reflect/InvocationTargetException:<init> (Ljava/lang/Throwable;)V // 164: athrow // 165: astore 6 // 167: aload_2 // 168: invokevirtual 145 java/io/InputStream:close ()V // 171: goto +22 -> 193 // 174: astore 7 // 176: new 7 Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|