use of org.eclipse.compare.CompareConfiguration in project egit by eclipse.
the class GitMergeEditorInput method prepareInput.
@Override
protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// make sure all resources belong to the same repository
RevWalk rw = null;
try {
monitor.beginTask(UIText.GitMergeEditorInput_CheckingResourcesTaskName, IProgressMonitor.UNKNOWN);
Map<Repository, Collection<String>> pathsByRepository = ResourceUtil.splitPathsByRepository(Arrays.asList(locations));
if (pathsByRepository.size() != 1) {
throw new InvocationTargetException(new IllegalStateException(UIText.RepositoryAction_multiRepoSelection));
}
Repository repo = pathsByRepository.keySet().iterator().next();
List<String> filterPaths = new ArrayList<>(pathsByRepository.get(repo));
if (monitor.isCanceled())
throw new InterruptedException();
rw = new RevWalk(repo);
// get the "right" side (MERGE_HEAD for merge, ORIG_HEAD for rebase)
final RevCommit rightCommit;
try {
String target;
if (repo.getRepositoryState().equals(RepositoryState.MERGING))
target = Constants.MERGE_HEAD;
else if (repo.getRepositoryState().equals(RepositoryState.CHERRY_PICKING))
target = Constants.CHERRY_PICK_HEAD;
else if (repo.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE))
target = readFile(repo.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA);
else
target = Constants.ORIG_HEAD;
ObjectId mergeHead = repo.resolve(target);
if (mergeHead == null)
throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target));
rightCommit = rw.parseCommit(mergeHead);
} catch (IOException e) {
throw new InvocationTargetException(e);
}
// we need the HEAD, also to determine the common
// ancestor
final RevCommit headCommit;
try {
ObjectId head = repo.resolve(Constants.HEAD);
if (head == null)
throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, Constants.HEAD));
headCommit = rw.parseCommit(head);
} catch (IOException e) {
throw new InvocationTargetException(e);
}
final String fullBranch;
try {
fullBranch = repo.getFullBranch();
} catch (IOException e) {
throw new InvocationTargetException(e);
}
// try to obtain the common ancestor
List<RevCommit> startPoints = new ArrayList<>();
rw.setRevFilter(RevFilter.MERGE_BASE);
startPoints.add(rightCommit);
startPoints.add(headCommit);
RevCommit ancestorCommit;
try {
rw.markStart(startPoints);
ancestorCommit = rw.next();
} catch (Exception e) {
ancestorCommit = null;
}
if (monitor.isCanceled())
throw new InterruptedException();
// set the labels
CompareConfiguration config = getCompareConfiguration();
config.setRightLabel(NLS.bind(LABELPATTERN, rightCommit.getShortMessage(), CompareUtils.truncatedRevision(rightCommit.name())));
if (!useWorkspace)
config.setLeftLabel(NLS.bind(LABELPATTERN, headCommit.getShortMessage(), CompareUtils.truncatedRevision(headCommit.name())));
else
config.setLeftLabel(UIText.GitMergeEditorInput_WorkspaceHeader);
if (ancestorCommit != null)
config.setAncestorLabel(NLS.bind(LABELPATTERN, ancestorCommit.getShortMessage(), CompareUtils.truncatedRevision(ancestorCommit.name())));
// set title and icon
setTitle(NLS.bind(UIText.GitMergeEditorInput_MergeEditorTitle, new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repo), rightCommit.getShortMessage(), fullBranch }));
// build the nodes
try {
return buildDiffContainer(repo, headCommit, ancestorCommit, filterPaths, rw, monitor);
} catch (IOException e) {
throw new InvocationTargetException(e);
}
} finally {
if (rw != null)
rw.dispose();
monitor.done();
}
}
use of org.eclipse.compare.CompareConfiguration in project egit by eclipse.
the class ApplyPatchActionHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IResource[] resources = getSelectedResources(event);
IResource resource = null;
if (resources.length > 0) {
resource = resources[0];
}
boolean isPatch = false;
if (resource instanceof IFile) {
try {
isPatch = ApplyPatchOperation.isPatch((IFile) resource);
} catch (CoreException e) {
Activator.handleError(e.getMessage(), e, false);
}
}
final ApplyPatchOperation op;
if (isPatch) {
op = new ApplyPatchOperation(HandlerUtil.getActivePart(event), (IFile) resource, null, new CompareConfiguration());
} else {
op = new ApplyPatchOperation(HandlerUtil.getActivePart(event), resource);
}
BusyIndicator.showWhile(Display.getDefault(), op);
return null;
}
use of org.eclipse.compare.CompareConfiguration in project ecf by eclipse.
the class RemoteResourcesView method createPartControl.
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setComparator(new ViewerComparator() {
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof BatchModelChange) {
BatchModelChange c1 = (BatchModelChange) e1;
BatchModelChange c2 = (BatchModelChange) e2;
// newest goes last
return (int) (c2.getTime() - c1.getTime());
}
// no sorting for resource changes
return 0;
}
});
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
labelProvider = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider();
// $NON-NLS-1$
final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
final CompareConfiguration config = new CompareConfiguration();
TreeViewerColumn resourceColumn = new TreeViewerColumn(viewer, SWT.LEAD);
resourceColumn.getColumn().setText("Changes");
resourceColumn.getColumn().setWidth(100);
resourceColumn.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
if (element instanceof BatchModelChange) {
StringBuffer buffer = new StringBuffer();
BatchModelChange batchChange = (BatchModelChange) element;
buffer.append(batchChange.isOutgoing() ? "Outgoing" : "Incoming");
buffer.append(" (");
buffer.append(formatter.format(new Date(batchChange.getTime())));
buffer.append(')');
return buffer.toString();
} else {
return new Path(((ResourceChangeMessage) element).getPath()).lastSegment();
}
}
public Image getImage(Object element) {
if (element instanceof BatchModelChange) {
Image image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
int kind = 0;
if (((BatchModelChange) element).isOutgoing()) {
kind = (kind & ~SyncInfo.OUTGOING) | SyncInfo.INCOMING | SyncInfo.CHANGE;
} else {
kind = (kind & ~SyncInfo.OUTGOING) | SyncInfo.OUTGOING | SyncInfo.CHANGE;
}
return config.getImage(image, kind);
} else {
ResourceChangeMessage message = (ResourceChangeMessage) element;
int type = message.getType();
IPath path = new Path(message.getPath());
Image image = null;
if (type == IResource.FILE) {
image = labelProvider.getImage(ResourcesPlugin.getWorkspace().getRoot().getFile(path));
} else {
image = labelProvider.getImage(ResourcesPlugin.getWorkspace().getRoot().getFolder(path));
}
if (message.isConflicted()) {
return config.getImage(image, SyncInfo.CHANGE | SyncInfo.CONFLICTING);
}
int imageKind = 0;
switch(message.getKind()) {
case IResourceDelta.ADDED:
imageKind = (imageKind & ~SyncInfo.CHANGE) | SyncInfo.DELETION;
break;
case IResourceDelta.CHANGED:
imageKind = (imageKind & ~SyncInfo.CHANGE) | SyncInfo.CHANGE;
break;
case IResourceDelta.REMOVED:
imageKind = (imageKind & ~SyncInfo.CHANGE) | SyncInfo.ADDITION;
break;
default:
return null;
}
return config.getImage(image, imageKind);
}
}
});
TreeViewerColumn pathColumn = new TreeViewerColumn(viewer, SWT.LEAD);
pathColumn.getColumn().setText("Path");
pathColumn.getColumn().setWidth(200);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
if (element instanceof BatchModelChange) {
return null;
} else {
return ((ResourceChangeMessage) element).getPath();
}
}
});
TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEAD);
typeColumn.getColumn().setText("Type");
typeColumn.getColumn().setWidth(75);
typeColumn.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
if (element instanceof BatchModelChange) {
return null;
} else {
switch(((ResourceChangeMessage) element).getKind()) {
case IResourceDelta.ADDED:
return "Added";
case IResourceDelta.CHANGED:
return "Changed";
case IResourceDelta.REMOVED:
return "Removed";
default:
return null;
}
}
}
});
TreeViewerColumn resolutionColumn = new TreeViewerColumn(viewer, SWT.LEAD);
resolutionColumn.getColumn().setText("Resolution");
resolutionColumn.getColumn().setWidth(100);
resolutionColumn.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
if (element instanceof BatchModelChange) {
return null;
} else {
return ((ResourceChangeMessage) element).isIgnored() ? "Ignored" : "Committed";
}
}
});
SyncResourcesCore.setView(this);
}
use of org.eclipse.compare.CompareConfiguration in project n4js by eclipse.
the class PackageJsonComparePage method createPreviewer.
private Control createPreviewer(Composite parent) {
final CompareConfiguration compareConfiguration = new CompareConfiguration();
compareConfiguration.setLeftLabel("Original package.json");
compareConfiguration.setLeftEditable(false);
compareConfiguration.setRightLabel("Merged package.json");
compareConfiguration.setRightEditable(false);
compareConfiguration.setProperty(CompareConfiguration.IGNORE_WHITESPACE, Boolean.FALSE);
fViewer = new TextMergeViewer(parent, SWT.NONE, compareConfiguration);
// add initial input in order to avoid problems when disposing the viewer later:
fViewer.setInput(new DiffNode(new DiffElementFromString(""), new DiffElementFromString("")));
Control control = fViewer.getControl();
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
compareConfiguration.dispose();
}
});
return control;
}
Aggregations