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 203699 Details for
Bug 218896
[patch][editor] display changes of old -> new values
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.
Description part that can open a compare dialog
DiffingTaskEditorDescriptionPart.java (text/plain), 9.16 KB, created by
Sam Davis
on 2011-09-20 12:30:29 EDT
(
hide
)
Description:
Description part that can open a compare dialog
Filename:
MIME Type:
Creator:
Sam Davis
Created:
2011-09-20 12:30:29 EDT
Size:
9.16 KB
patch
obsolete
>import java.io.ByteArrayInputStream; >import java.io.InputStream; >import java.io.UnsupportedEncodingException; >import java.lang.reflect.InvocationTargetException; > >import org.apache.commons.lang.StringUtils; >import org.eclipse.compare.CompareConfiguration; >import org.eclipse.compare.CompareEditorInput; >import org.eclipse.compare.CompareUI; >import org.eclipse.compare.IStreamContentAccessor; >import org.eclipse.compare.ITypedElement; >import org.eclipse.compare.structuremergeviewer.DiffNode; >import org.eclipse.compare.structuremergeviewer.Differencer; >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.action.Action; >import org.eclipse.jface.action.ToolBarManager; >import org.eclipse.jface.util.StatusHandler; >import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; >import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; >import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; >import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorDescriptionPart; >import org.eclipse.mylyn.tasks.core.data.TaskAttribute; >import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Color; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Control; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Event; >import org.eclipse.ui.PlatformUI; >import org.eclipse.ui.forms.widgets.FormToolkit; > >public class DiffingTaskEditorDescriptionPart extends TaskEditorDescriptionPart { > public class CompareAction extends Action { > public String localValue; > > public String remoteValue; > > public boolean isLocalChanged; > > public boolean isRemoteChanged; > > public void update(String localValue, String remoteValue, boolean isLocalChanged, boolean isRemoteChanged) { > this.localValue = localValue; > this.remoteValue = remoteValue; > this.isLocalChanged = isLocalChanged; > this.isRemoteChanged = isRemoteChanged; > String tooltip; > if (isRemoteChanged) { > if (isLocalChanged) { > tooltip = "Description has both outgoing and incoming changes. " > + "Click to compare your copy with the incoming copy."; > setToolTipText(tooltip); > setImageDescriptor(CommonImages.OVERLAY_SYNC_CONFLICT); > } else { > tooltip = "Description has been changed by someone else. " > + "Click to compare with your previous copy."; > setToolTipText(tooltip); > setImageDescriptor(CommonImages.OVERLAY_SYNC_INCOMMING); > } > } else { > tooltip = "You have made unsubmitted changes to the description. " > + "Click to compare with the remote copy."; > setImageDescriptor(CommonImages.OVERLAY_SYNC_OUTGOING); > } > setToolTipText(tooltip + " Ctrl+click to open in compare editor."); > } > > @Override > public void runWithEvent(Event event) { > boolean openInEditor = (event.stateMask & SWT.CTRL) != 0; > final String name = "description for " + getTaskEditorPage().getTask().getSummary(); > CompareConfiguration cc = new CompareConfiguration(); > cc.setProperty(CompareConfiguration.IGNORE_WHITESPACE, Boolean.valueOf(true)); > cc.setLeftEditable(true); > if (isLocalChanged) { > cc.setLeftLabel("Your Outgoing Copy"); > } else { > cc.setLeftLabel("Your Previous Copy"); > } > cc.setRightEditable(false); > if (isRemoteChanged) { > cc.setRightLabel("Incoming Copy"); > } else { > cc.setRightLabel("Remote Copy"); > } > CompareEditorInput editorInput = new CompareEditorInput(cc) { > class AttributeElement implements ITypedElement, IStreamContentAccessor { > private final String value; > > public AttributeElement(String value) { > this.value = value; > } > > public Image getImage() { > return null; > } > > public String getName() { > return name; > } > > public String getType() { > return TEXT_TYPE; > } > > public InputStream getContents() throws CoreException { > try { > return new ByteArrayInputStream(value.getBytes("UTF-8")); > } catch (UnsupportedEncodingException e) { > return null; > } > } > } > > @Override > public String getTitle() { > return "Compare " + name; > } > > @Override > protected Object prepareInput(IProgressMonitor pm) throws InvocationTargetException { > final int LINE_LENGTH = 60; > return new DiffNode(Differencer.CHANGE, null, new AttributeElement( > wordWrap(localValue, LINE_LENGTH)), > new AttributeElement(wordWrap(remoteValue, LINE_LENGTH))); > } > > }; > if (openInEditor) { > CompareUI.openCompareEditor(editorInput); > } else { > CompareUI.openCompareDialog(editorInput); > } > } > } > > private static final String ATT_CONFLICTED = "DiffingTaskEditorDescriptionPart.conflicted"; > > private ToolBarManager toolBar; > > private CompareAction compareAction; > > public DiffingTaskEditorDescriptionPart() { > } > > @Override > public void createControl(Composite parent, FormToolkit toolkit) { > super.createControl(parent, toolkit); > update(); > } > > @Override > protected void fillToolBar(ToolBarManager toolBar) { > this.toolBar = toolBar; > super.fillToolBar(toolBar); > } > > public void update() { > try { > TaskAttribute attribute = getModel().getTaskData() > .getRoot() > .getAttribute(BugzillaAttribute.STATUS_WHITEBOARD.getKey()); > final String currentValue = attribute.getValue(); > String repositoryValue = StringUtils.EMPTY; > boolean isLocalChanged = false; > for (TaskAttribute changed : getModel().getChangedOldAttributes()) { > if (changed.getId().equals(attribute.getId())) { > isLocalChanged = true; > repositoryValue = changed.getValue(); > break; > } > } > final String localValue; > final String remoteValue; > boolean isRemoteChanged = false; > TaskAttribute lastReadAttribute = getModel().getLastReadAttribute(attribute); > if (isLocalChanged) { > if (lastReadAttribute != null) { > isRemoteChanged = !repositoryValue.equals(lastReadAttribute.getValue()); > } > if (isRemoteChanged) {// persist conflicted state in case editor is closed and reopened > getTaskEditorPage().getTask().setAttribute(ATT_CONFLICTED, Boolean.toString(true)); > } else { > isRemoteChanged = Boolean.parseBoolean(getTaskEditorPage().getTask().getAttribute(ATT_CONFLICTED)); > } > localValue = currentValue; > remoteValue = repositoryValue; > } else { > getTaskEditorPage().getTask().setAttribute(ATT_CONFLICTED, Boolean.toString(false)); > if (lastReadAttribute == null) { > return; > } > localValue = lastReadAttribute.getValue(); > remoteValue = currentValue; > isRemoteChanged = true; > } > if (!localValue.trim().equals(remoteValue.trim())) { > decorateEditor(getEditor(), isRemoteChanged, isLocalChanged); > addCompareAction(localValue, remoteValue, isRemoteChanged, isLocalChanged); > } > } catch (RuntimeException e) { > StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, e.getMessage(), e)); > } > } > > private void decorateEditor(final AbstractAttributeEditor attributeEditor, final boolean isRemoteChanged, > final boolean isLocalChanged) { > PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { > public void run() { > if (isLocalChanged) { > Color color; > if (isRemoteChanged) { > color = Display.getDefault().getSystemColor(SWT.COLOR_RED); > } else { > color = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); > } > Control[] editors = ((Composite) attributeEditor.getControl()).getChildren(); > for (Control editor : editors) { > editor.setBackground(color); > if (isRemoteChanged) { > editor.setToolTipText("Submitting will overwrite incoming changes to the description. " > + "Click the red conflict button to compare with the incoming copy."); > } > } > } > } > }); > } > > private void addCompareAction(final String localValue, final String remoteValue, final boolean isRemoteChanged, > final boolean isLocalChanged) { > if (toolBar != null) { > boolean compareActionCreated = false; > if (compareAction == null) { > compareAction = new CompareAction(); > compareActionCreated = true; > } > compareAction.update(localValue, remoteValue, isLocalChanged, isRemoteChanged); > if (compareActionCreated) { > toolBar.add(compareAction); > toolBar.update(false); > toolBar.getControl().getParent().getParent().layout(); > } > } > } > > /** > * break long lines at whitespace > */ > public String wordWrap(final String s, final int LINE_LENGTH) { > StringBuilder sb = new StringBuilder(); > int lineEnd = LINE_LENGTH; > for (int i = 0; i < s.length(); i++) { > char c = s.charAt(i); > if (i < lineEnd) { > sb.append(c); > if (c == '\n' || c == '\r') { > lineEnd = sb.length() + LINE_LENGTH; > } > } else if (!Character.isWhitespace(c)) { > sb.append(c); > } else { > sb.append('\n'); > lineEnd = sb.length() + LINE_LENGTH; > } > } > sb.append('\n');// make compare editor happy > return sb.toString(); > } > >}
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 Raw
Actions:
View
Attachments on
bug 218896
:
203699
|
203949
|
265587