private ParticipantPageSaveablePart createCompareInput() { ISynchronizeParticipant participant = new CompareParticipant( new CVSCompareSubscriber( new IResource[0], new CVSTag[0], Messages.getString("ProjectComparePage.3"))); // $NON-NLS-1$ configuration = participant.createPageConfiguration(); configuration.setMenuGroups( ISynchronizePageConfiguration.P_TOOLBAR_MENU, new String[] { ISynchronizePageConfiguration.NAVIGATE_GROUP, ISynchronizePageConfiguration.LAYOUT_GROUP, ChangeSetModelManager.CHANGE_SET_GROUP }); configuration.setMenuGroups(ISynchronizePageConfiguration.P_CONTEXT_MENU, new String[0]); CompareConfiguration cc = new CompareConfiguration(); cc.setLeftEditable(false); cc.setRightEditable(false); ParticipantPageSaveablePart part = new ParticipantPageSaveablePart(getShell(), cc, configuration, participant); // will be reset when setVisible is called setPageComplete(true); return part; }
public void testDirtyFlagOnLocalResourceTypedElementAndEmptyRight() throws CoreException, InvocationTargetException, InterruptedException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, IOException { // Create left element by SaveableCompareEditorInput to be properly // saved, see javadoc to SaveableCompareEditorInput LocalResourceTypedElement el1 = (LocalResourceTypedElement) SaveableCompareEditorInput.createFileElement(file1); ITypedElement el2 = null; CompareConfiguration conf = new CompareConfiguration(); conf.setLeftEditable(true); TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(el1, el2, conf); compareEditorInput.prepareCompareInput(null); verifyDirtyStateChanges(compareEditorInput); // check whether file was saved assertTrue( compareContent( new ByteArrayInputStream((fileContents1 + appendFileContents).getBytes()), file1.getContents())); }
private void initializeToolbars(Composite parent) { ToolBarManager tbm = CompareViewerPane.getToolBarManager(parent); if (tbm != null) { tbm.removeAll(); // define groups tbm.add(new Separator("modes")); // $NON-NLS-1$ tbm.add(new Separator("merge")); // $NON-NLS-1$ tbm.add(new Separator("navigation")); // $NON-NLS-1$ CompareConfiguration cc = getCompareConfiguration(); if (cc.isRightEditable()) { fCopyLeftToRightAction = new Action() { public void run() { copy(true); } }; Utilities.initAction( fCopyLeftToRightAction, getResourceBundle(), "action.CopyLeftToRight."); // $NON-NLS-1$ tbm.appendToGroup("merge", fCopyLeftToRightAction); // $NON-NLS-1$ fHandlerService.registerAction( fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight"); // $NON-NLS-1$ } if (cc.isLeftEditable()) { fCopyRightToLeftAction = new Action() { public void run() { copy(false); } }; Utilities.initAction( fCopyRightToLeftAction, getResourceBundle(), "action.CopyRightToLeft."); // $NON-NLS-1$ tbm.appendToGroup("merge", fCopyRightToLeftAction); // $NON-NLS-1$ fHandlerService.registerAction( fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft"); // $NON-NLS-1$ } final ChangePropertyAction a = new ChangePropertyAction( fBundle, getCompareConfiguration(), "action.EnableAncestor.", ICompareUIConstants.PROP_ANCESTOR_VISIBLE); // $NON-NLS-1$ a.setChecked(fAncestorVisible); fAncestorItem = new ActionContributionItem(a); fAncestorItem.setVisible(false); tbm.appendToGroup("modes", fAncestorItem); // $NON-NLS-1$ tbm.getControl().addDisposeListener(a); createToolItems(tbm); updateToolItems(); tbm.update(true); } }
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { CompareConfiguration cc = getCompareConfiguration(); cc.setRightEditable(false); cc.setLeftEditable(false); cc.setLeftLabel("original"); cc.setRightLabel("formatted Text"); return new DiffNode(left, right); }
private void initLabels(ICompareInput input) { CompareConfiguration cc = getCompareConfiguration(); if (getLeftRevision() != null) { String leftLabel = getFileRevisionLabel(getLeftRevision()); cc.setLeftLabel(leftLabel); } else if (getResource(input) != null) { String label = NLS.bind( Messages.GitCompareFileRevisionEditorInput_workspace, new Object[] {input.getLeft().getName()}); cc.setLeftLabel(label); } if (getRightRevision() != null) { String rightLabel = getFileRevisionLabel(getRightRevision()); cc.setRightLabel(rightLabel); } }
/** * Called on the viewer disposal. Unregisters from the compare configuration. Clients may extend * if they have to do additional cleanup. * * @see org.eclipse.jface.viewers.ContentViewer#handleDispose(org.eclipse.swt.events.DisposeEvent) */ protected void handleDispose(DisposeEvent event) { if (fHandlerService != null) fHandlerService.dispose(); Object input = getInput(); if (input instanceof ICompareInput) { ICompareContainer container = getCompareConfiguration().getContainer(); container.removeCompareInputChangeListener( (ICompareInput) input, fCompareInputChangeListener); } if (input != null) { ICompareInputLabelProvider lp = getCompareConfiguration().getLabelProvider(); if (lp != null) lp.removeListener(labelChangeListener); } if (fPropertyChangeListener != null) { fCompareConfiguration.removePropertyChangeListener(fPropertyChangeListener); fPropertyChangeListener = null; } fAncestorLabel = null; fLeftLabel = null; fDirectionLabel = null; fRightLabel = null; fCenter = null; if (fRightArrow != null) { fRightArrow.dispose(); fRightArrow = null; } if (fLeftArrow != null) { fLeftArrow.dispose(); fLeftArrow = null; } if (fBothArrow != null) { fBothArrow.dispose(); fBothArrow = null; } if (fNormalCursor != null) { fNormalCursor.dispose(); fNormalCursor = null; } if (fHSashCursor != null) { fHSashCursor.dispose(); fHSashCursor = null; } if (fVSashCursor != null) { fVSashCursor.dispose(); fVSashCursor = null; } if (fHVSashCursor != null) { fHVSashCursor.dispose(); fHVSashCursor = null; } super.handleDispose(event); }
protected Viewer createMergeViewer(Composite parent, CompareConfiguration compareConfiguration) { compareConfiguration.setProperty(DefaultMergeEditor.PROVIDER, mergeEditorProvider); return new DefaultMergeViewer( parent, SWT.NULL, compareConfiguration, documentProvider, sourceViewerConfigurationProvider); }
/** * Performs the comparison described by the given input and opens a compare editor on the result. * * @param input the input on which to open the compare editor * @param page the workbench page on which to create a new compare editor * @param editor if not null the input is opened in this editor * @param activate if <code>true</code> the editor will be activated * @see IWorkbenchPage#openEditor(org.eclipse.ui.IEditorInput, String, boolean) * @see CompareEditorInput */ public void openCompareEditor( final CompareEditorInput input, final IWorkbenchPage page, final IReusableEditor editor, final boolean activate) { CompareConfiguration configuration = input.getCompareConfiguration(); if (configuration != null) { IPreferenceStore ps = configuration.getPreferenceStore(); if (ps != null) configuration.setProperty( CompareConfiguration.USE_OUTLINE_VIEW, Boolean.valueOf(ps.getBoolean(ComparePreferencePage.USE_OUTLINE_VIEW))); } if (input.canRunAsJob()) { openEditorInBackground(input, page, editor, activate); } else { if (compareResultOK(input, null)) { internalOpenEditor(input, page, editor, activate); } } }
public void testDirtyFlagOnCustomTypedElementAndEmptyRight() throws CoreException, InvocationTargetException, InterruptedException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, IOException { ITypedElement el1 = new TestFileElement(file1); ITypedElement el2 = null; CompareConfiguration conf = new CompareConfiguration(); conf.setLeftEditable(true); TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(el1, el2, conf); compareEditorInput.prepareCompareInput(null); verifyDirtyStateChanges(compareEditorInput); /* * not checking if changes were saved because in this case saving is not * handled, see javadoc to SaveableCompareEditorInput. */ }
/** * Creates a new content merge viewer and initializes with a resource bundle and a configuration. * * @param style SWT style bits * @param bundle the resource bundle * @param cc the configuration object */ protected ContentMergeViewer(int style, ResourceBundle bundle, CompareConfiguration cc) { fStyles = style & ~(SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); // remove // BIDI // direction // bits fBundle = bundle; fAncestorVisible = Utilities.getBoolean(cc, ICompareUIConstants.PROP_ANCESTOR_VISIBLE, fAncestorVisible); fConfirmSave = Utilities.getBoolean(cc, CompareEditor.CONFIRM_SAVE_PROPERTY, fConfirmSave); setContentProvider(new MergeViewerContentProvider(cc)); fCompareInputChangeListener = new ICompareInputChangeListener() { public void compareInputChanged(ICompareInput input) { if (input == getInput()) { handleCompareInputChange(); } } }; // Make sure the compare configuration is not null if (cc == null) fCompareConfiguration = new CompareConfiguration(); else fCompareConfiguration = cc; fPropertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { ContentMergeViewer.this.handlePropertyChangeEvent(event); } }; fCompareConfiguration.addPropertyChangeListener(fPropertyChangeListener); fLeftSaveAction = new SaveAction(true); fLeftSaveAction.setEnabled(false); fRightSaveAction = new SaveAction(false); fRightSaveAction.setEnabled(false); // this is used to update the dirty status,if we use // org.eclipse.php.internal.ui.compare.ContentMergeViewer,we will get a // ClassCastException cmv = new org.eclipse.compare.contentmergeviewer.ContentMergeViewer( fStyles, fBundle, fCompareConfiguration) { @Override protected void createControls(Composite composite) {} @Override protected void handleResizeAncestor(int x, int y, int width, int height) {} @Override protected void handleResizeLeftRight( int x, int y, int leftWidth, int centerWidth, int rightWidth, int height) {} @Override protected void updateContent(Object ancestor, Object left, Object right) {} @Override protected void copy(boolean leftToRight) {} @Override protected byte[] getContents(boolean left) { return null; } @Override public boolean internalIsLeftDirty() { return ContentMergeViewer.this.isLeftDirty(); } @Override public boolean internalIsRightDirty() { return ContentMergeViewer.this.isRightDirty(); } }; }
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // make sure all resources belong to the same repository try (RevWalk rw = new RevWalk(repository)) { monitor.beginTask( UIText.GitCompareEditorInput_CompareResourcesTaskName, IProgressMonitor.UNKNOWN); for (IResource resource : resources) { RepositoryMapping map = RepositoryMapping.getMapping(resource.getProject()); if (map == null) { throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); } if (repository != null && repository != map.getRepository()) throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); String repoRelativePath = map.getRepoRelativePath(resource); filterPathStrings.add(repoRelativePath); DiffNode node = new DiffNode(Differencer.NO_CHANGE) { @Override public Image getImage() { return FOLDER_IMAGE; } }; diffRoots.put(new Path(map.getRepoRelativePath(resource)), node); repository = map.getRepository(); } if (repository == null) throw new InvocationTargetException( new IllegalStateException( UIText.GitCompareEditorInput_ResourcesInDifferentReposMessagge)); if (monitor.isCanceled()) throw new InterruptedException(); final RevCommit baseCommit; try { try { baseCommit = rw.parseCommit(repository.resolve(baseVersion)); } catch (IOException e) { throw new InvocationTargetException(e); } final RevCommit compareCommit; if (compareVersion == null) { compareCommit = null; } else { try { compareCommit = rw.parseCommit(repository.resolve(compareVersion)); } catch (IOException e) { throw new InvocationTargetException(e); } } if (monitor.isCanceled()) throw new InterruptedException(); // set the labels CompareConfiguration config = getCompareConfiguration(); config.setLeftLabel(compareVersion); config.setRightLabel(baseVersion); // set title and icon if (resources.length == 0) { Object[] titleParameters = new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repository), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) }; setTitle(NLS.bind(UIText.GitCompareEditorInput_EditorTitle, titleParameters)); } else if (resources.length == 1) { Object[] titleParameters = new Object[] { resources[0].getFullPath().makeRelative().toString(), CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion) }; setTitle( NLS.bind(UIText.GitCompareEditorInput_EditorTitleSingleResource, titleParameters)); } else { setTitle( NLS.bind( UIText.GitCompareEditorInput_EditorTitleMultipleResources, CompareUtils.truncatedRevision(compareVersion), CompareUtils.truncatedRevision(baseVersion))); } // build the nodes try { return buildDiffContainer(baseCommit, compareCommit, monitor); } catch (IOException e) { throw new InvocationTargetException(e); } } finally { monitor.done(); } } }
protected Object handleOpen() { if (mergeViewer.getAncestorTree() == this) { return null; } IStructuredSelection sel = (IStructuredSelection) getSelection(); if (sel.isEmpty()) { return null; } Object current = sel.iterator().next(); // if the current selection has an Action_Semantics field // the grab the necessary object element to open that, failing // that look for a description attribute if (current instanceof NonRootModelElementComparable) { NonRootModelElement nrme = (NonRootModelElement) ((NonRootModelElementComparable) current).getRealElement(); if (nrme instanceof StateMachineState_c || nrme instanceof Transition_c) { // we need to navigate to the Action element // for the activity and description attributes Object[] children = ((ITreeContentProvider) getContentProvider()).getChildren(current); for (Object child : children) { if (child instanceof NonRootModelElementComparable) { current = child; break; } } } ObjectElement actionObjEle = null; ObjectElement descripObjEle = null; Object[] children = ((ITreeContentProvider) getContentProvider()).getChildren(current); for (Object child : children) { if (child instanceof ObjectElementComparable) { ObjectElementComparable comparable = (ObjectElementComparable) child; ObjectElement objElement = (ObjectElement) comparable.getRealElement(); if (objElement.getName().equals("Action_Semantics")) { actionObjEle = objElement; } else { if (objElement.getName().equals("Descrip")) { descripObjEle = objElement; } } } } if (actionObjEle != null) { current = ComparableProvider.getComparableTreeObject(actionObjEle); } else { if (descripObjEle != null) { current = ComparableProvider.getComparableTreeObject(descripObjEle); } } } if (current instanceof ObjectElementComparable) { ObjectElementComparable comparable = (ObjectElementComparable) current; ObjectElement objElement = (ObjectElement) comparable.getRealElement(); if (objElement.getName().equals("Descrip") || objElement.getName().equals("Action_Semantics")) { Object leftInput = getMergeViewer().getLeftViewer().getInput(); Object rightInput = getMergeViewer().getRightViewer().getInput(); TreeItem rightMatch = getMatchingItem(comparable, synchronizedViewers.get(0)); TreeItem ancestorMatch = null; if (synchronizedViewers.size() == 2) { ancestorMatch = getMatchingItem(comparable, synchronizedViewers.get(1)); } Object leftElement = comparable.getRealElement(); Object rightElement = null; Object ancestor = null; if (ancestorMatch != null) { ancestor = ((ComparableTreeObject) ancestorMatch.getData()).getRealElement(); } if (rightMatch != null) { rightElement = ((ComparableTreeObject) rightMatch.getData()).getRealElement(); } if (mergeViewer.getLeftViewer() != this) { if (rightMatch == null) { leftElement = null; } else { leftElement = rightMatch.getData(); leftElement = ((ComparableTreeObject) leftElement).getRealElement(); } rightElement = comparable.getRealElement(); } // create a compare dialog, using the text compare final CompareConfiguration compareConfiguration = new CompareConfiguration(); boolean leftEditable = leftInput instanceof IEditableContent && ((IEditableContent) leftInput).isEditable(); boolean rightEditable = rightInput instanceof IEditableContent && ((IEditableContent) rightInput).isEditable(); // if this is a single file compare, do not allow editing // at this time as there is no easy way to place the content // changes back into the file if (ComparePlugin.getDefault() .getModelCacheManager() .isInputReadonly(ModelCacheManager.getLeftKey(mergeViewer.getInput()))) { compareConfiguration.setLeftEditable(false); compareConfiguration.setRightEditable(false); } else { compareConfiguration.setLeftEditable(leftEditable); compareConfiguration.setRightEditable(rightEditable); } final TextualAttributeCompareEditorInput compareInput = new TextualAttributeCompareEditorInput( compareConfiguration, (ObjectElement) leftElement, (ObjectElement) rightElement, (ObjectElement) ancestor, SynchronizedTreeViewer.this); if (CompareUIPlugin.getDefault().compareResultOK(compareInput, null)) { Runnable runnable = new Runnable() { public void run() { CompareDialog dialog = new CompareDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), compareInput) { @Override protected Button createButton( Composite parent, int id, String label, boolean defaultButton) { if (id == IDialogConstants.CANCEL_ID) { return null; } else { return super.createButton(parent, id, label, defaultButton); } } }; dialog.open(); } }; if (Display.getCurrent() == null) { Display.getDefault().syncExec(runnable); } else { runnable.run(); } } return null; } } return null; }