Merge "Omaha #4108 Allow editable files to be edited in the Localization Compare editor" into omaha_15.1.1
Former-commit-id: f90760b0b1e88c65caed50d34a0a1ed2468a44a7
This commit is contained in:
commit
b038dac2b5
2 changed files with 253 additions and 10 deletions
|
@ -49,6 +49,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 3, 2010 mschenke Initial creation
|
||||
* Nov 27, 2013 mschenke Moved into localization.perspective project
|
||||
* Feb 11, 2015 4108 randerso Implmented hashCode() and equals()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -226,4 +227,46 @@ public class LocalizationEditorInput implements IFileEditorInput,
|
|||
public String getFactoryId() {
|
||||
return FACTORY_ID;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result)
|
||||
+ ((localizationFile == null) ? 0 : localizationFile.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LocalizationEditorInput other = (LocalizationEditorInput) obj;
|
||||
if (localizationFile == null) {
|
||||
if (other.localizationFile != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!localizationFile.equals(other.localizationFile)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,14 +19,24 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.localization.perspective.ui.compare;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.compare.CompareConfiguration;
|
||||
import org.eclipse.compare.CompareEditorInput;
|
||||
import org.eclipse.compare.ResourceNode;
|
||||
import org.eclipse.compare.structuremergeviewer.DiffNode;
|
||||
import org.eclipse.compare.structuremergeviewer.Differencer;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.ISaveablesSource;
|
||||
import org.eclipse.ui.Saveable;
|
||||
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.LocalizationFileOutputStream;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.viz.localization.perspective.editor.LocalizationEditorInput;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +48,8 @@ import com.raytheon.uf.viz.localization.perspective.editor.LocalizationEditorInp
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 24, 2011 mschenke Initial creation
|
||||
* Mar 24, 2011 mschenke Initial creation
|
||||
* Jan 22, 2015 #4108 randerso Allow editing in the compare editor
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -46,9 +57,169 @@ import com.raytheon.uf.viz.localization.perspective.editor.LocalizationEditorInp
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class LocalizationCompareEditorInput extends CompareEditorInput {
|
||||
public class LocalizationCompareEditorInput extends CompareEditorInput
|
||||
implements ISaveablesSource {
|
||||
|
||||
private DiffNode node;
|
||||
protected static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(LocalizationCompareEditorInput.class);
|
||||
|
||||
private LocalizationEditorInput left;
|
||||
|
||||
private LocalizationEditorInput right;
|
||||
|
||||
private ResourceNode leftNode;
|
||||
|
||||
private ResourceNode rightNode;
|
||||
|
||||
private Saveable[] saveables;
|
||||
|
||||
private static class LocalizationSaveable extends Saveable {
|
||||
|
||||
private LocalizationCompareEditorInput parent;
|
||||
|
||||
private boolean left;
|
||||
|
||||
private LocalizationEditorInput input;
|
||||
|
||||
private ResourceNode node;
|
||||
|
||||
public LocalizationSaveable(LocalizationCompareEditorInput parent,
|
||||
boolean left) {
|
||||
this.parent = parent;
|
||||
this.left = left;
|
||||
|
||||
if (left) {
|
||||
this.input = parent.left;
|
||||
this.node = parent.leftNode;
|
||||
} else {
|
||||
this.input = parent.right;
|
||||
this.node = parent.rightNode;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.Saveable#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return input.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.Saveable#getToolTipText()
|
||||
*/
|
||||
@Override
|
||||
public String getToolTipText() {
|
||||
return input.getToolTipText();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.Saveable#getImageDescriptor()
|
||||
*/
|
||||
@Override
|
||||
public ImageDescriptor getImageDescriptor() {
|
||||
return input.getImageDescriptor();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.Saveable#doSave(org.eclipse.core.runtime.IProgressMonitor
|
||||
* )
|
||||
*/
|
||||
@Override
|
||||
public void doSave(IProgressMonitor monitor) throws CoreException {
|
||||
// flush changes from the viewer into the node
|
||||
if (left) {
|
||||
parent.flushLeftViewers(monitor);
|
||||
} else {
|
||||
parent.flushRightViewers(monitor);
|
||||
}
|
||||
|
||||
// write node contents to the localization file
|
||||
LocalizationFile lf = input.getLocalizationFile();
|
||||
try (LocalizationFileOutputStream os = lf.openOutputStream();
|
||||
InputStream is = node.getContents()) {
|
||||
|
||||
byte[] buf = new byte[2048];
|
||||
int len = is.read(buf);
|
||||
while (len > 0) {
|
||||
os.write(buf, 0, len);
|
||||
len = is.read(buf);
|
||||
}
|
||||
|
||||
lf.save();
|
||||
|
||||
// Force other editors on this file to update
|
||||
input.getFile().refreshLocal(IResource.DEPTH_ZERO, monitor);
|
||||
} catch (CoreException e) {
|
||||
statusHandler.error("Error refreshing local resources for "
|
||||
+ input.getFile().getName(), e);
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Error saving " + lf, e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.Saveable#isDirty()
|
||||
*/
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return (left ? parent.isLeftSaveNeeded() : parent
|
||||
.isRightSaveNeeded());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result)
|
||||
+ ((input == null) ? 0 : input.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LocalizationSaveable other = (LocalizationSaveable) obj;
|
||||
if (input == null) {
|
||||
if (other.input != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!input.equals(other.input)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configuration
|
||||
|
@ -58,13 +229,19 @@ public class LocalizationCompareEditorInput extends CompareEditorInput {
|
|||
super(new CompareConfiguration());
|
||||
|
||||
CompareConfiguration config = getCompareConfiguration();
|
||||
config.setLeftEditable(false);
|
||||
config.setRightEditable(false);
|
||||
config.setLeftEditable(!left.getFile().isReadOnly());
|
||||
config.setRightEditable(!right.getFile().isReadOnly());
|
||||
config.setLeftLabel(left.getName());
|
||||
config.setRightLabel(right.getName());
|
||||
|
||||
node = new DiffNode(new ResourceNode(left.getFile()), new ResourceNode(
|
||||
right.getFile()));
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
|
||||
this.leftNode = new ResourceNode(left.getFile());
|
||||
this.rightNode = new ResourceNode(right.getFile());
|
||||
|
||||
this.saveables = new Saveable[] { new LocalizationSaveable(this, true),
|
||||
new LocalizationSaveable(this, false) };
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -75,8 +252,31 @@ public class LocalizationCompareEditorInput extends CompareEditorInput {
|
|||
* runtime.IProgressMonitor)
|
||||
*/
|
||||
@Override
|
||||
protected Object prepareInput(IProgressMonitor monitor)
|
||||
protected Object prepareInput(IProgressMonitor pm)
|
||||
throws InvocationTargetException, InterruptedException {
|
||||
return node;
|
||||
|
||||
return new Differencer().findDifferences(false, pm, null, null,
|
||||
leftNode, rightNode);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.ISaveablesSource#getSaveables()
|
||||
*/
|
||||
@Override
|
||||
public Saveable[] getSaveables() {
|
||||
return this.saveables;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.ISaveablesSource#getActiveSaveables()
|
||||
*/
|
||||
@Override
|
||||
public Saveable[] getActiveSaveables() {
|
||||
return getSaveables();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue