use of org.eclipse.compare.ITypedElement in project erlide_eclipse by erlang.
the class ErlStructureCreator method createStructureComparator.
@Override
protected IStructureComparator createStructureComparator(final Object element, final IDocument document0, final ISharedDocumentAdapter sharedDocumentAdapter, final IProgressMonitor monitor) throws CoreException {
IErlModule module = null;
final IErlModel model = ErlangEngine.getInstance().getModel();
String s = "";
IDocument document = document0;
if (element instanceof ResourceNode) {
final ResourceNode rn = (ResourceNode) element;
final IResource r = rn.getResource();
if (r instanceof IFile) {
final IFile f = (IFile) r;
final IErlElement e = model.findElement(r);
if (e instanceof IErlModule) {
module = (IErlModule) e;
}
if (document == null) {
try {
s = ErlStructureCreator.readString(f.getContents());
document = new Document(s);
} catch (final CoreException e1) {
}
}
}
} else if (document == null && element instanceof IStreamContentAccessor) {
try {
try (final InputStream contents = ((IStreamContentAccessor) element).getContents()) {
s = ErlStructureCreator.readString(contents);
} catch (final IOException e) {
}
document = new Document(s);
} catch (final CoreException ex) {
}
} else if (document != null) {
s = document.get();
}
if (module == null) {
String name = "comptemp";
if (element instanceof ITypedElement) {
final ITypedElement typedElement = (ITypedElement) element;
name = typedElement.getName();
}
module = model.getModuleFromText(model, name, s, null);
}
ErlNode root = null;
if (element != null && document != null) {
try {
module.open(null);
root = new RootErlNode(document, element);
recursiveMakeErlNodes(module, root, document);
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
return root;
}
use of org.eclipse.compare.ITypedElement in project tmdm-studio-se by Talend.
the class ResourceCompareInput method createDiffViewer.
@Override
public Viewer createDiffViewer(Composite parent) {
fDiffViewer = new DiffTreeViewer(parent, getCompareConfiguration()) {
@Override
protected void fillContextMenu(IMenuManager manager) {
if (fOpenAction == null) {
fOpenAction = new Action() {
@Override
public void run() {
handleOpen(null);
}
};
// $NON-NLS-1$
Utilities.initAction(fOpenAction, getBundle(), "action.CompareContents.");
}
boolean enable = false;
ISelection selection = getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
if (ss.size() == 1) {
Object element = ss.getFirstElement();
if (element instanceof MyDiffNode) {
ITypedElement te = ((MyDiffNode) element).getId();
if (te != null) {
enable = !ITypedElement.FOLDER_TYPE.equals(te.getType());
}
} else {
enable = true;
}
}
}
fOpenAction.setEnabled(enable);
manager.add(fOpenAction);
super.fillContextMenu(manager);
}
};
fDiffViewer.getControl();
return fDiffViewer;
}
use of org.eclipse.compare.ITypedElement in project tmdm-studio-se by Talend.
the class ResourceCompareInput method commit.
/*
* Recursively walks the diff tree and commits all changes.
*/
private void commit(IProgressMonitor pm, DiffNode node) throws CoreException {
if (node instanceof MyDiffNode) {
((MyDiffNode) node).clearDirty();
}
ITypedElement left = node.getLeft();
if (left instanceof BufferedResourceNode) {
((BufferedResourceNode) left).commit(pm);
}
ITypedElement right = node.getRight();
if (right instanceof BufferedResourceNode) {
((BufferedResourceNode) right).commit(pm);
}
IDiffElement[] children = node.getChildren();
if (children != null) {
for (IDiffElement element : children) {
if (element instanceof DiffNode) {
commit(pm, (DiffNode) element);
}
}
}
if (this.compareHeadInfo != null) {
commitToDB();
}
}
use of org.eclipse.compare.ITypedElement in project liferay-ide by liferay.
the class AbstractCompareFileHandler method _openCompareEditor.
private IStatus _openCompareEditor(IFile currentFile) {
ITypedElement left = null;
ITypedElement right = null;
IStatus retval = Status.OK_STATUS;
try {
File tempFile = getTemplateFile(currentFile);
if (tempFile == null) {
return ProjectCore.createErrorStatus("Can't find the original file.");
}
left = new CompareItem(tempFile);
right = new CompareItem(currentFile.getLocation().toFile());
_openInCompare(left, right);
} catch (Exception e) {
retval = ProjectCore.createErrorStatus(e);
}
return retval;
}
use of org.eclipse.compare.ITypedElement in project egit by eclipse.
the class CompareUtils method compareLocalWithRef.
/**
* Opens a compare editor comparing the working directory version of the
* file at the given location with the version corresponding to
* {@code refName} of the same file.
*
* @param repository
* The repository to load file revisions from.
* @param location
* Location of the file to compare revisions for.
* @param refName
* Reference to compare with the workspace version of
* {@code file}. Can be either a commit ID, a reference or a
* branch name.
* @param page
* If not {@null} try to re-use a compare editor on this
* page if any is available. Otherwise open a new one.
*/
private static void compareLocalWithRef(@NonNull final Repository repository, @NonNull final IPath location, final String refName, final IWorkbenchPage page) {
Job job = new Job(UIText.CompareUtils_jobName) {
@Override
public IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final String gitPath = getRepoRelativePath(location, repository);
final ITypedElement base = new LocalNonWorkspaceTypedElement(repository, location);
CompareEditorInput in;
try {
in = prepareCompareInput(repository, gitPath, base, refName);
} catch (IOException e) {
return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
openCompareEditorRunnable(page, in);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
Aggregations