Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/AbstractWikiHandler.java11
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracWikiHandler.java14
-rw-r--r--org.eclipse.mylyn.trac.ui/plugin.xml23
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/actions/OpenWikiPageAction.java299
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditor.java553
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditorInput.java103
6 files changed, 22 insertions, 981 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/AbstractWikiHandler.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/AbstractWikiHandler.java
index d415c29ec..371fa2f42 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/AbstractWikiHandler.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/AbstractWikiHandler.java
@@ -11,6 +11,7 @@ package org.eclipse.mylyn.internal.trac.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
@@ -18,13 +19,17 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
*/
public abstract class AbstractWikiHandler {
- public abstract String[] downloadAllPageNames(TaskRepository repository, IProgressMonitor monitor) throws CoreException;
+ public abstract String[] downloadAllPageNames(TaskRepository repository, IProgressMonitor monitor)
+ throws CoreException;
public abstract String getWikiUrl(TaskRepository repository);
public abstract TracWikiPage getWikiPage(TaskRepository repository, String pageName, IProgressMonitor monitor)
throws CoreException;
- public abstract void postWikiPage(TaskRepository repository, TracWikiPage page, IProgressMonitor monitor) throws CoreException;
-
+ public abstract void postWikiPage(TaskRepository repository, TracWikiPage page, IProgressMonitor monitor)
+ throws CoreException;
+
+ public abstract TracWikiPageInfo[] getPageHistory(TaskRepository repository, String pageName,
+ IProgressMonitor monitor) throws CoreException;
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracWikiHandler.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracWikiHandler.java
index ca7e8d9be..ca5110774 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracWikiHandler.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracWikiHandler.java
@@ -15,6 +15,7 @@ import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
@@ -78,6 +79,19 @@ public class TracWikiHandler extends AbstractWikiHandler {
}
}
+ public TracWikiPageInfo[] getPageHistory(TaskRepository repository, String pageName, IProgressMonitor monitor)
+ throws CoreException {
+ monitor.beginTask("Retrieve Wiki Page History", IProgressMonitor.UNKNOWN);
+ try {
+ TracWikiPageInfo[] versions = getTracWikiClient(repository).getWikiPageInfoAllVersions(pageName);
+ return versions;
+ } catch (TracException e) {
+ throw new CoreException(TracCorePlugin.toStatus(e, repository));
+ } finally {
+ monitor.done();
+ }
+ }
+
private ITracWikiClient getTracWikiClient(TaskRepository repository) throws TracException {
try {
ITracClient client = connector.getClientManager().getRepository(repository);
diff --git a/org.eclipse.mylyn.trac.ui/plugin.xml b/org.eclipse.mylyn.trac.ui/plugin.xml
index 127f678ac..cebac63d4 100644
--- a/org.eclipse.mylyn.trac.ui/plugin.xml
+++ b/org.eclipse.mylyn.trac.ui/plugin.xml
@@ -34,28 +34,5 @@
point="org.eclipse.mylyn.tasks.ui.editors">
<editorFactory class="org.eclipse.mylyn.internal.trac.ui.editor.TracTaskEditorFactory"/>
</extension>
- <extension
- point="org.eclipse.ui.popupMenus">
- <viewerContribution
- id="org.eclipse.mylyn.trac.ui.viewerContribution"
- targetID="org.eclipse.mylyn.tasks.ui.views.repositories">
- <action
- class="org.eclipse.mylyn.internal.trac.ui.actions.OpenWikiPageAction"
- id="org.eclipse.mylyn.trac.ui.open.wikipage"
- label="Open Wiki Page..."
- menubarPath="additions"
- tooltip="Open Wiki Page">
- </action>
- </viewerContribution>
- </extension>
- <extension
- point="org.eclipse.ui.editors">
- <editor
- class="org.eclipse.mylyn.internal.trac.ui.editor.TracWikiPageEditor"
- icon="icons/eview16/trac-icon.gif"
- id="org.eclipse.mylyn.trac.ui.editor.wikipage"
- name="Wiki Page Editor">
- </editor>
- </extension>
</plugin>
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/actions/OpenWikiPageAction.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/actions/OpenWikiPageAction.java
deleted file mode 100644
index a213e1cc0..000000000
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/actions/OpenWikiPageAction.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*******************************************************************************
- * 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.trac.ui.actions;
-
-import java.util.Comparator;
-
-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.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.mylyn.internal.trac.core.AbstractWikiHandler;
-import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
-import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
-import org.eclipse.mylyn.internal.trac.ui.TracUiPlugin;
-import org.eclipse.mylyn.internal.trac.ui.editor.TracWikiPageEditor;
-import org.eclipse.mylyn.internal.trac.ui.editor.TracWikiPageEditorInput;
-import org.eclipse.mylyn.monitor.core.StatusHandler;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
-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.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
-
-/**
- * @author Xiaoyang Guan
- */
-public class OpenWikiPageAction extends Action implements IViewActionDelegate {
-
- private TaskRepository repository;
-
- private AbstractWikiHandler wikiHandler;
-
- private class OpenWikiPageSelectionDialog extends FilteredItemsSelectionDialog {
-
- private static final String OPEN_WIKI_PAGE_DIALOG_DIALOG_SETTINGS = "org.eclipse.mylyn.trac.ui.open.wikipage";
-
- private String[] pageNames;
-
- private DownloadAllPageNamesJob downloadAllPageNamesJob;
-
- private class DownloadAllPageNamesJob extends Job {
-
- public DownloadAllPageNamesJob() {
- super("Downloading All Wiki Page Names");
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- pageNames = wikiHandler.downloadAllPageNames(repository, monitor);
- // refresh the items list with the fetched page names
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- OpenWikiPageSelectionDialog.this.applyFilter();
- }
- });
- } catch (CoreException e) {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- OpenWikiPageSelectionDialog.this.close();
- }
- });
- StatusHandler.displayStatus("Unable to download Wiki page names", e.getStatus());
- }
- return Status.OK_STATUS;
- }
- }
-
- public OpenWikiPageSelectionDialog(Shell shell, boolean multi) {
- super(shell, multi);
- setTitle("Open Wiki Page");
- setSelectionHistory(new PageSelectionHistory());
- setInitialPattern("**");
- setPageNames();
- }
-
- private void setPageNames() {
- downloadAllPageNamesJob = new DownloadAllPageNamesJob();
- downloadAllPageNamesJob.setUser(true);
- downloadAllPageNamesJob.schedule();
- }
-
- private void stopDownloading() {
- if (downloadAllPageNamesJob != null) {
- downloadAllPageNamesJob.cancel();
- }
- }
-
- private class PageSelectionHistory extends SelectionHistory {
-
- @Override
- protected Object restoreItemFromMemento(IMemento memento) {
- return null;
- }
-
- @Override
- protected void storeItemToMemento(Object item, IMemento memento) {
- }
-
- }
-
- @Override
- protected Control createExtendedContentArea(Composite parent) {
- return null;
- }
-
- @Override
- protected ItemsFilter createFilter() {
- // return null if the download job hasn't finished so the real filter
- // can be applied only after the pageNames has been populated
- if (pageNames == null) {
- return null;
- }
- return new ItemsFilter() {
-
- @Override
- public boolean isConsistentItem(Object item) {
- return true;
- }
-
- @Override
- public boolean matchItem(Object item) {
- if (item != null) {
- return matches(item.toString());
- }
- return false;
- }
-
- };
- }
-
- @Override
- protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter,
- IProgressMonitor progressMonitor) throws CoreException {
- if (pageNames != null) {
- progressMonitor.beginTask("Searching", pageNames.length);
- for (int i = 0; i < pageNames.length; i++) {
- contentProvider.add(pageNames[i], itemsFilter);
- progressMonitor.worked(1);
- }
- }
- progressMonitor.done();
- }
-
- @Override
- protected IDialogSettings getDialogSettings() {
- IDialogSettings settings = TracUiPlugin.getDefault().getDialogSettings().getSection(
- OPEN_WIKI_PAGE_DIALOG_DIALOG_SETTINGS);
- if (settings == null) {
- settings = TracUiPlugin.getDefault().getDialogSettings().addNewSection(
- OPEN_WIKI_PAGE_DIALOG_DIALOG_SETTINGS);
- }
- return settings;
- }
-
- @Override
- public String getElementName(Object item) {
- return item.toString();
- }
-
- @Override
- protected Comparator<Object> getItemsComparator() {
- return new Comparator<Object>() {
-
- public int compare(Object o1, Object o2) {
- return o1.toString().compareTo(o2.toString());
- }
-
- };
- }
-
- @Override
- protected IStatus validateItem(Object item) {
- // ignore
- return Status.OK_STATUS;
- }
-
- @Override
- protected void cancelPressed() {
- stopDownloading();
- super.cancelPressed();
- }
-
- @Override
- protected void handleShellCloseEvent() {
- stopDownloading();
- super.handleShellCloseEvent();
- }
- }
-
- public void init(IViewPart view) {
- }
-
- public void run(IAction action) {
- OpenWikiPageSelectionDialog openDialog = new OpenWikiPageSelectionDialog(PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(), true);
-
- if (openDialog.open() == Window.OK) {
- Object[] selections = openDialog.getResult();
- if (selections != null) {
- for (int i = 0; i < selections.length; i++) {
- OpenWikiPageJob job = new OpenWikiPageJob((String) selections[i]);
- job.schedule();
- }
- }
- }
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- repository = getSelectedRepository(selection);
- if (repository != null) {
- AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
- repository.getConnectorKind());
- // Note: the following type checking on the connector won't be needed once the Wiki
- // functionality is generalized into AbstractRepositoryConnector
- if (connector instanceof TracRepositoryConnector) {
- TracRepositoryConnector tracConnector = (TracRepositoryConnector) connector;
- wikiHandler = tracConnector.getWikiHandler();
- action.setEnabled(tracConnector.hasWiki(repository));
- } else {
- action.setEnabled(false);
- }
- } else {
- action.setEnabled(false);
- }
- }
-
- private TaskRepository getSelectedRepository(ISelection selection) {
- if (selection instanceof IStructuredSelection) {
- Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
- if (selectedObject instanceof TaskRepository) {
- return (TaskRepository) selectedObject;
- }
- }
- return null;
- }
-
- private class OpenWikiPageJob extends Job {
- private String pageName;
-
- public OpenWikiPageJob(String pageName) {
- super("Opening Wiki Page");
- this.pageName = pageName;
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- final TracWikiPage page = wikiHandler.getWikiPage(repository, pageName, monitor);
- if (page != null) {
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-
- public void run() {
- openWikiPageEditor(repository, page, wikiHandler.getWikiUrl(repository) + pageName);
- }
- });
- } else {
- StatusHandler.fail(null, "Unable to retrieve wiki page " + pageName, true, IStatus.ERROR);
- }
- } catch (final CoreException e) {
- StatusHandler.displayStatus("Unable to open wiki page", e.getStatus());
- } finally {
- monitor.done();
- }
- return Status.OK_STATUS;
- }
-
- }
-
- private static void openWikiPageEditor(TaskRepository repository, TracWikiPage wikiPage, String pageUrl) {
- IEditorInput editorInput = new TracWikiPageEditorInput(repository, wikiPage, pageUrl);
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- TasksUiUtil.openEditor(editorInput, TracWikiPageEditor.ID_EDITOR, window.getActivePage());
- }
-
-}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditor.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditor.java
deleted file mode 100644
index 07ddf83ff..000000000
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditor.java
+++ /dev/null
@@ -1,553 +0,0 @@
-/*******************************************************************************
- * 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.trac.ui.editor;
-
-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.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.TextViewer;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
-import org.eclipse.mylyn.internal.trac.core.TracCorePlugin;
-import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
-import org.eclipse.mylyn.monitor.core.StatusHandler;
-import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.ui.editors.AbstractRenderingEngine;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.browser.LocationAdapter;
-import org.eclipse.swt.browser.LocationEvent;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.FillLayout;
-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.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.events.ExpansionEvent;
-import org.eclipse.ui.forms.events.IExpansionListener;
-import org.eclipse.ui.forms.widgets.ExpandableComposite;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-
-/**
- * @author Xiaoyang Guan
- */
-public class TracWikiPageEditor extends FormEditor {
-
- public static final String ID_EDITOR = "org.eclipse.mylyn.trac.ui.editor.wikipage";
-
- private TaskRepository repository;
-
- private TracWikiPage page;
-
- private WikiSourceEditor wikiSourceEditor;
-
- private BrowserFormPage browserPage;
-
- private class WikiSourceEditor extends FormPage {
-
- private static final String ID = "org.eclipse.mylyn.trac.ui.editor.wikisource";
-
- private static final String TITLE = "Wiki Page Source";
-
- private static final String LABEL_PREVIEW = "Page Preview";
-
- private static final String LABEL_SOURCE = "Page Source";
-
- private static final String LABEL_BUTTON_PREVIEW = "Preview";
-
- private static final String LABEL_BUTTON_SUBMIT = "Submit";
-
- private static final int PREVIEW_BROWSER_HEIGHT = 10 * 14;
-
- private static final int DEFAULT_WIDTH = 79 * 7; // 500;
-
- private ScrolledForm form;
-
- private FormToolkit toolkit;
-
- private Composite editorComposite;
-
- private Section previewSection;
-
- private Browser previewBrowser;
-
- private TextViewer sourceEditor;
-
- private Button previewButton;
-
- private Button submitButton;
-
- protected boolean isDirty;
-
- public WikiSourceEditor(FormEditor editor) {
- super(editor, ID, TITLE);
-
- }
-
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- super.createFormContent(managedForm);
- form = managedForm.getForm();
- toolkit = managedForm.getToolkit();
-
- editorComposite = form.getBody();
- GridLayout editorLayout = new GridLayout();
- editorComposite.setLayout(editorLayout);
- editorComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- createPreviewSection(editorComposite);
- createSourceSection(editorComposite);
- }
-
- private void createPreviewSection(Composite parent) {
- previewSection = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR | Section.TWISTIE);
- previewSection.setText(LABEL_PREVIEW);
- previewSection.setExpanded(false);
- previewSection.setLayout(new GridLayout());
- previewSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- previewSection.addExpansionListener(new IExpansionListener() {
- public void expansionStateChanging(ExpansionEvent e) {
- form.reflow(true);
- }
-
- public void expansionStateChanged(ExpansionEvent e) {
- form.reflow(true);
- }
- });
-
- Composite container = toolkit.createComposite(previewSection);
- previewSection.setClient(container);
- container.setLayout(new GridLayout());
- container.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- previewBrowser = addBrowser(container, SWT.NONE);
- previewBrowser.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
- GridData previewBrowserData = new GridData(GridData.FILL_BOTH);
- previewBrowserData.heightHint = PREVIEW_BROWSER_HEIGHT;
- previewBrowser.setLayoutData(previewBrowserData);
-
- toolkit.paintBordersFor(container);
- }
-
- private void createSourceSection(Composite parent) {
- Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
- section.setText(LABEL_SOURCE);
- section.setExpanded(true);
- section.setLayout(new GridLayout());
- section.setLayoutData(new GridData(GridData.FILL_BOTH));
- section.addExpansionListener(new IExpansionListener() {
- public void expansionStateChanging(ExpansionEvent e) {
- form.reflow(true);
- }
-
- public void expansionStateChanged(ExpansionEvent e) {
- form.reflow(true);
- }
- });
-
- Composite container = toolkit.createComposite(section);
- section.setClient(container);
- container.setLayout(new GridLayout());
- container.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- sourceEditor = new SourceViewer(container, null, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
- sourceEditor.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
- sourceEditor.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
- sourceEditor.setEditable(true);
-
- sourceEditor.getTextWidget().addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- if (!isDirty()) {
- markDirty(true);
- setSubmitEnabled(true);
- }
- }
- });
-
- StyledText styledText = sourceEditor.getTextWidget();
- GridDataFactory.fillDefaults().hint(DEFAULT_WIDTH, SWT.DEFAULT).grab(true, true).applyTo(styledText);
-
- Document document = new Document(page.getContent());
- sourceEditor.setDocument(document);
-
- createActionsLayout(container);
- toolkit.paintBordersFor(container);
- }
-
- private void createActionsLayout(Composite parent) {
- Composite buttonComposite = toolkit.createComposite(parent);
- GridLayout buttonLayout = new GridLayout();
- buttonLayout.numColumns = 2;
- buttonComposite.setLayout(buttonLayout);
- buttonComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- addActionButtons(buttonComposite);
-
- }
-
- private void addActionButtons(Composite buttonComposite) {
- previewButton = toolkit.createButton(buttonComposite, LABEL_BUTTON_PREVIEW, SWT.NONE);
- GridData previewButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- previewButtonData.widthHint = 100;
- previewButton.setLayoutData(previewButtonData);
- previewButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
- previewSection.setExpanded(true);
- setText(previewBrowser, "loading preview...");
- previewWiki(previewBrowser, sourceEditor.getTextWidget().getText());
- }
- });
-
- submitButton = toolkit.createButton(buttonComposite, LABEL_BUTTON_SUBMIT, SWT.NONE);
- GridData submitButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- submitButtonData.widthHint = 100;
- submitButton.setImage(TasksUiImages.getImage(TasksUiImages.REPOSITORY_SUBMIT));
- submitButton.setLayoutData(submitButtonData);
- submitButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
- InputDialog commentDialog = new InputDialog(null, "Page Comment",
- "Enter a Comment for the page (or cancel the submit):", null, null);
- // cancel the comment dialog will cancel the submit
- if (commentDialog.open() == Window.OK) {
- page.getPageInfo().setComment(commentDialog.getValue());
- page.getPageInfo().setAuthor(repository.isAnonymous() ? "anonymous" : repository.getUserName());
- page.setContent(sourceEditor.getTextWidget().getText());
-
- submitToRepository();
- }
- }
- });
-
- setSubmitEnabled(false);
- }
-
- /**
- * Copied from AbstractRepositoryTaskEditor
- *
- * @param enabled
- */
- private void setSubmitEnabled(boolean enabled) {
- if (submitButton != null && !submitButton.isDisposed()) {
- submitButton.setEnabled(enabled);
- if (enabled) {
- submitButton.setToolTipText("Submit to " + repository.getUrl());
- }
- }
- }
-
- public void submitToRepository() {
- class SubmitPageJob extends Job {
- private IStatus jobStatus;
-
- public SubmitPageJob() {
- super("upload wiki page");
- }
-
- public IStatus getStatus() {
- return jobStatus;
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- monitor.beginTask("Uploading wiki page", IProgressMonitor.UNKNOWN);
- TracCorePlugin.getDefault().getConnector().getWikiHandler().postWikiPage(repository, page,
- monitor);
- jobStatus = Status.OK_STATUS;
- } catch (CoreException e) {
- StatusHandler.displayStatus("Submit failed", e.getStatus());
- jobStatus = e.getStatus();
- } finally {
- monitor.done();
- }
- return Status.OK_STATUS;
- }
-
- }
-
- final SubmitPageJob submitJob = new SubmitPageJob();
- submitJob.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(IJobChangeEvent event) {
-
- // refresh editor only if uploading the wiki page succeeded
- if (submitJob.getStatus().isOK()) {
- updateWikiPage();
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
- public void run() {
- browserPage.refresh();
- setActivePage(BrowserFormPage.ID_EDITOR);
- markDirty(false);
- setSubmitEnabled(false);
- }
- });
- }
- }
- });
- submitJob.schedule();
- }
-
- @Override
- public boolean isDirty() {
- return isDirty;
- }
-
- protected void markDirty(boolean dirty) {
- isDirty = dirty;
- getManagedForm().dirtyStateChanged();
- }
-
- /*====== Copied/modified from AbstractRepositoryTaskEditor ======*/
-
- private boolean ignoreLocationEvents = false;
-
- private Browser addBrowser(Composite parent, int style) {
- Browser browser = new Browser(parent, style);
- // intercept links to open tasks in rich editor and urls in separate browser
- browser.addLocationListener(new LocationAdapter() {
- @Override
- public void changing(LocationEvent event) {
- // ignore events that are caused by manually setting the contents of the browser
- if (ignoreLocationEvents) {
- return;
- }
-
- if (event.location != null) {
- event.doit = false;
- // TODO: add open link support when this editor is moved into ..mylyn.tasks.ui.editors
- //IHyperlink link = new TaskUrlHyperlink(
- // new Region(0, 0)/* a fake region just to make constructor happy */, event.location);
- //link.open();
- }
- }
-
- });
-
- return browser;
- }
-
- private void setText(Browser browser, String html) {
- try {
- ignoreLocationEvents = true;
- browser.setText((html != null) ? html : "");
- } finally {
- ignoreLocationEvents = false;
- }
-
- }
-
- private void previewWiki(final Browser browser, String sourceText) {
- final class PreviewWikiJob extends Job {
- private String sourceText;
-
- private String htmlText;
-
- private IStatus jobStatus;
-
- public PreviewWikiJob(String sourceText) {
- super("Formatting Wiki Text");
-
- if (sourceText == null) {
- throw new IllegalArgumentException("source text must not be null");
- }
-
- this.sourceText = sourceText;
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- AbstractRenderingEngine htmlRenderingEngine = new TracRenderingEngine();
-
- jobStatus = Status.OK_STATUS;
- try {
- htmlText = htmlRenderingEngine.renderAsHtml(repository, sourceText, monitor);
- } catch (CoreException e) {
- jobStatus = e.getStatus();
- }
- return Status.OK_STATUS;
- }
-
- public String getHtmlText() {
- return htmlText;
- }
-
- public IStatus getStatus() {
- return jobStatus;
- }
-
- }
-
- final PreviewWikiJob job = new PreviewWikiJob(sourceText);
-
- job.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(final IJobChangeEvent event) {
- if (!form.isDisposed()) {
- if (job.getStatus().isOK()) {
- getPartControl().getDisplay().asyncExec(new Runnable() {
- public void run() {
- WikiSourceEditor.this.setText(browser, job.getHtmlText());
- //parentEditor.setMessage(null, IMessageProvider.NONE);
- }
- });
- } else {
- getPartControl().getDisplay().asyncExec(new Runnable() {
- public void run() {
- //parentEditor.setMessage(job.getStatus().getMessage(), IMessageProvider.ERROR);
- }
- });
- }
- }
- super.done(event);
- }
- });
-
- job.setUser(true);
- job.schedule();
- }
-
- }
-
- /**
- * Modified from org.eclipse.mylyn.internal.web.tasks.BrowserFormPage
- *
- */
- private class BrowserFormPage extends FormPage {
-
- public static final String ID_EDITOR = "org.eclipse.mylyn.trac.ui.editor.wikibrowser";
-
- private Browser browser;
-
- public BrowserFormPage(FormEditor editor, String title) {
- super(editor, ID_EDITOR, title);
- }
-
- @Override
- protected void createFormContent(IManagedForm managedForm) {
- super.createFormContent(managedForm);
- try {
- TracWikiPageEditorInput editorInput = (TracWikiPageEditorInput) getEditorInput();
-
- ScrolledForm form = managedForm.getForm();
- form.getBody().setLayout(new FillLayout());
- browser = new Browser(form.getBody(), SWT.NONE);
- managedForm.getForm().setContent(browser);
- browser.setUrl(editorInput.getPageUrl());
- } catch (SWTError e) {
- StatusHandler.fail(e, "Could not create Browser page: " + e.getMessage(), true);
- } catch (RuntimeException e) {
- StatusHandler.fail(e, "Could not create wiki page", false);
- }
- }
-
- public void refresh() {
- browser.refresh();
- }
-
- @Override
- public void dispose() {
- if (browser != null && !browser.isDisposed()) {
- browser.dispose();
- }
- super.dispose();
- }
- }
-
- public TracWikiPageEditor() {
- super();
- wikiSourceEditor = new WikiSourceEditor(this);
- browserPage = new BrowserFormPage(this, "Browser");
- }
-
- protected void initializeEditor() {
- TracWikiPageEditorInput editorInput = (TracWikiPageEditorInput) getEditorInput();
- page = editorInput.getPage();
- repository = editorInput.getRepository();
- }
-
- @Override
- protected void addPages() {
- initializeEditor();
- try {
- addPage(wikiSourceEditor);
- addPage(browserPage);
- setPartName(getEditorInput().getName());
- setActivePage(BrowserFormPage.ID_EDITOR);
- } catch (PartInitException e) {
- StatusHandler.fail(e, "Cannot create Trac Wiki page editor pages", true);
- }
- }
-
- @Override
- public void doSave(IProgressMonitor monitor) {
- MessageDialog.openInformation(getSite().getShell(), "Changes cannot be saved",
- "Offline editting on wiki pages not supported yet.");
- monitor.setCanceled(true);
- }
-
- @Override
- public void doSaveAs() {
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- protected void updateWikiPage() {
- Job updatePageJob = new Job("Update wiki page") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- monitor.beginTask("Downloading wiki page", IProgressMonitor.UNKNOWN);
- TracWikiPage newPage = TracCorePlugin.getDefault().getConnector().getWikiHandler().getWikiPage(
- repository, page.getPageInfo().getPageName(), monitor);
- if (newPage != null) {
- ((TracWikiPageEditorInput) getEditorInput()).setPage(newPage);
- } else {
- StatusHandler.fail(null, "Unable to retrieve wiki page " + page.getPageInfo().getPageName(),
- true, IStatus.ERROR);
- }
- } catch (CoreException e) {
- StatusHandler.displayStatus("Download failed", e.getStatus());
- } finally {
- monitor.done();
- }
- return Status.OK_STATUS;
- }
-
- };
- updatePageJob.schedule();
- }
-
-}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditorInput.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditorInput.java
deleted file mode 100644
index 6df8e63e0..000000000
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/editor/TracWikiPageEditorInput.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * 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.trac.ui.editor;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
-import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/**
- * @author Xiaoyang Guan
- */
-public class TracWikiPageEditorInput implements IEditorInput {
-
- private TaskRepository repository;
-
- private TracWikiPage page;
-
- private String pageUrl;
-
- public TracWikiPageEditorInput(TaskRepository repository, TracWikiPage page, String pageUrl) {
- this.repository = repository;
- this.page = page;
- this.pageUrl = pageUrl;
- }
-
- public TaskRepository getRepository() {
- return repository;
- }
-
- public void setRepository(TaskRepository repository) {
- this.repository = repository;
- }
-
- public TracWikiPage getPage() {
- return page;
- }
-
- public void setPage(TracWikiPage page) {
- this.page = page;
- }
-
- public String getPageUrl() {
- return pageUrl;
- }
-
- public void setPageUrl(String pageUrl) {
- this.pageUrl = pageUrl;
- }
-
- public boolean exists() {
- // ignore
- return false;
- }
-
- public ImageDescriptor getImageDescriptor() {
- // ignore
- return null;
- }
-
- public String getName() {
- return page.getPageInfo().getPageName();
- }
-
- public IPersistableElement getPersistable() {
- // ignore
- return null;
- }
-
- public String getToolTipText() {
- return getName() + " [" + repository.getRepositoryLabel() + "]";
- }
-
- @SuppressWarnings("unchecked")
- public Object getAdapter(Class adapter) {
- if (adapter == IEditorInput.class) {
- return this;
- }
- return null;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- } else if (this == obj) {
- return true;
- } else if (getClass() != obj.getClass()) {
- return false;
- } else {
- TracWikiPageEditorInput other = (TracWikiPageEditorInput) obj;
- return repository.equals(other.repository) && page.equals(other.page);
- }
- }
-
-}

Back to the top