### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/internal/CompareMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java,v retrieving revision 1.18 diff -u -r1.18 CompareMessages.java --- compare/org/eclipse/compare/internal/CompareMessages.java 19 Aug 2008 07:58:04 -0000 1.18 +++ compare/org/eclipse/compare/internal/CompareMessages.java 21 Aug 2008 12:51:16 -0000 @@ -120,6 +120,20 @@ public static String CompareWithOther_clear; public static String CompareWithOther_warning_two_way; public static String CompareWithOther_info; + public static String CompareWithOther_externalFileButton; + public static String CompareWithOther_externalFile_errorTitle; + public static String CompareWithOther_externalFile_errorMessage; + public static String CompareWithOther_pathLabel; + public static String CompareWithOther_externalFolderBUtton; + public static String CompareWithOther_fileName; + public static String CompareWithOther_createTmpFile_title; + public static String CompareWithOther_createTmpFile_message; + public static String CompareWithOther_showInEditorButton; + public static String CompareWithOther_refreshButton; + public static String CompareWithOther_clipboardCheckBox; + public static String CompareWithOther_clipboardRadioAncestor; + public static String CompareWithOther_clipboardRadioLeft; + public static String CompareWithOther_clipboardRadioRight; static { NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class); Index: compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java,v retrieving revision 1.4 diff -u -r1.4 CompareWithOtherResourceDialog.java --- compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java 20 Aug 2008 08:47:36 -0000 1.4 +++ compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java 21 Aug 2008 12:51:17 -0000 @@ -10,16 +10,32 @@ *******************************************************************************/ package org.eclipse.compare.internal; +import java.io.ByteArrayInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareUI; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DragSource; import org.eclipse.swt.dnd.DragSourceEvent; @@ -31,6 +47,7 @@ import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; @@ -38,26 +55,52 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.events.ExpansionAdapter; import org.eclipse.ui.forms.events.ExpansionEvent; import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.part.ResourceTransfer; /** * This is a dialog that can invoke the compare editor on chosen files. - * + * * @since 3.4 */ public class CompareWithOtherResourceDialog extends TitleAreaDialog { private int CLEAR_RETURN_CODE = 150; // any number != 0 + private int OPEN_EXTERNAL_RETURN_CODE = 153; private int MIN_WIDTH = 300; private int MIN_HEIGHT = 175; + public static final String TMP_PROJECT_NAME = ".org.eclipse.compare.tmp"; //$NON-NLS-1$ + private final static String TMP_PROJECT_FILE = "\n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + "\t" + TMP_PROJECT_NAME + "\t\n" //$NON-NLS-1$ //$NON-NLS-2$ + + "\t\n" //$NON-NLS-1$ + + "\t\n" //$NON-NLS-1$ + + "\t\n" //$NON-NLS-1$ + + "\t\n" //$NON-NLS-1$ + + "\t\n" //$NON-NLS-1$ + + "\t\n" + "\t\n" //$NON-NLS-1$//$NON-NLS-2$ + + ""; //$NON-NLS-1$ + public final static String EXTERNAL_FILES_FOLDER_NAME = "ExternalFilesFolder"; //$NON-NLS-1$ + private class FileTextDragListener implements DragSourceListener { private InternalSection section; @@ -71,7 +114,10 @@ } public void dragSetData(DragSourceEvent event) { - event.data = section.fileText.getText(); + if (TextTransfer.getInstance().isSupportedType(event.dataType)) { + event.data = section.fileText.getText(); + } else + event.data = section.fileText.getText(); } public void dragStart(DragSourceEvent event) { @@ -137,12 +183,13 @@ if (textTransfer.isSupportedType(event.currentDataType)) { String txt = (String) event.data; - IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt); - if (r != null) - section.setResource(r); + section.setResource(ResourcesPlugin.getWorkspace().getRoot() + .findMember(txt)); + section.updateAllSectionInfo(); } else if (resourceTransfer.isSupportedType(event.currentDataType)) { IResource[] files = (IResource[]) event.data; section.setResource(files[0]); + section.updateAllSectionInfo(); } updateErrorInfo(); @@ -159,6 +206,10 @@ protected Group group; protected Text fileText; private IResource resource; + private Button openExternalFileButton, openExternalFolderButton; + private String path = ""; //$NON-NLS-1$ + private Text pathLabel; + protected Label pLabel, fileLabel; public InternalSection(Composite parent) { createContents(parent); @@ -169,13 +220,37 @@ } public void createContents(Composite parent) { - createGroup(parent); - createFileLabel(); - createFileCombo(); + + group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout(2, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + Composite infoComposite = new Composite(group, SWT.NONE); + infoComposite.setLayout(new GridLayout(2, false)); + infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + createInfo(infoComposite); + + Composite buttonsComposite = new Composite(group, SWT.NONE); + buttonsComposite.setLayout(new GridLayout(-1, true)); + buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); + createButtons(buttonsComposite); + initDrag(); initDrop(); } + public void setEnabled(boolean enabled) { + fileText.setEnabled(enabled); + pLabel.setEnabled(enabled); + openExternalFileButton.setEnabled(enabled); + openExternalFolderButton.setEnabled(enabled); + pathLabel.setEnabled(enabled); + fileLabel.setEnabled(enabled); + group.setEnabled(enabled); + if (enabled) + setResource(fileText.getText()); + } + public IResource getResource() { return resource; } @@ -184,16 +259,27 @@ this.resource = resource; String txt = resource.getFullPath().toString(); fileText.setText(txt); + path = resource.getLocation().toOSString(); + pathLabel.setText(dividePath(path)); } public void setResource(String s) { IResource tmp = ResourcesPlugin.getWorkspace().getRoot() .findMember(s); - if (tmp instanceof IWorkspaceRoot) + if (tmp instanceof IWorkspaceRoot) { resource = null; - else + pathLabel.setText(""); //$NON-NLS-1$ + } + else { resource = tmp; + path = resource.getLocation().toOSString(); + pathLabel.setText(dividePath(path)); + } + } + public void setResourceFromClipboard(IFile file) { + resource = file; + updateErrorInfo(); } protected void clearResource() { @@ -220,42 +306,164 @@ target.addDropListener(new FileTextDropListener(this)); } - protected void createGroup(Composite parent) { - group = new Group(parent, SWT.NONE); - group.setLayout(new GridLayout(3, false)); - group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + protected void createButtons(Composite parent) { + createOpenExternalFileButton(parent); + createOpenExternalFolderButton(parent); + } + + protected void createInfo(Composite parent) { + createFileLabel(parent); + createFileCombo(parent); + createPathLabel(parent); } - protected void createFileCombo() { - fileText = new Text(group, SWT.BORDER); - fileText - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + protected void createFileCombo(Composite parent) { + fileText = new Text(parent, SWT.BORDER); + fileText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fileText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { setResource(fileText.getText()); + if (getResource() != null) { + path = resource.getLocation().toOSString(); + pathLabel.setText(dividePath(path)); + } else { + pathLabel.setText(""); //$NON-NLS-1$ + } updateErrorInfo(); } }); fileText.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } - public void widgetSelected(SelectionEvent e) { setResource(fileText.getText()); updateErrorInfo(); } + }); + } + protected void createOpenExternalFileButton(Composite parent) { + openExternalFileButton = createButton(parent, + OPEN_EXTERNAL_RETURN_CODE, + CompareMessages.CompareWithOther_externalFileButton, false); + openExternalFileButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + public void widgetSelected(SelectionEvent e) { + resource = getExtenalFile(); + updateAllSectionInfo(); + } }); } - protected void createFileLabel() { - final Label fileLabel = new Label(group, SWT.NONE); + protected void createOpenExternalFolderButton(Composite parent) { + openExternalFolderButton = createButton(parent, + OPEN_EXTERNAL_RETURN_CODE, + CompareMessages.CompareWithOther_externalFolderBUtton, false); + openExternalFolderButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + public void widgetSelected(SelectionEvent e) { + resource = getExternalDirectory(); + updateAllSectionInfo(); + } + }); + } + + private void updateAllSectionInfo() { + fileText.setText(resource.getFullPath().toOSString()); + pathLabel.setText(dividePath(path)); + getShell().pack(); + pathLabel.getParent().layout(); + updateErrorInfo(); + } + + private IFile getExtenalFile() { + FileDialog dialog = new FileDialog(getShell()); + path = dialog.open(); + IFile f = (IFile) getIResource(new Path(path), IResource.FILE); + return f; + } + + private IFolder getExternalDirectory() { + DirectoryDialog dialog = new DirectoryDialog(getShell()); + path = dialog.open(); + IFolder f = (IFolder) getIResource(new Path(path), IResource.FOLDER); + return f; + } + + private IResource getIResource(IPath iPath, int type) { + IResource r = null; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + IProject project = root.getProject(TMP_PROJECT_NAME); + String resourceName = iPath.lastSegment(); + try { + project = createTmpProject(); + if (!project.isOpen()) + project.open(null); + IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME); + if (!folderForExternal.exists()) + folderForExternal.create(IResource.NONE, true, null); + if (type == IResource.FILE) { + r = folderForExternal.getFile(resourceName); + if (!r.exists()) + ((IFile)r).createLink(iPath, IResource.REPLACE, null); + } + else { + r = folderForExternal.getFolder(resourceName); + if (!r.exists()) + ((IFolder)r).createLink(iPath, IResource.REPLACE, null); + } + } catch (CoreException e) { + CompareUIPlugin.log(e); + MessageDialog.openError(getShell(), + CompareMessages.CompareWithOther_externalFile_errorTitle, + CompareMessages.CompareWithOther_externalFile_errorMessage); + } + return r; + } + + protected void createFileLabel(Composite parent) { + fileLabel = new Label(parent, SWT.NONE); fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); } + + protected void createPathLabel(Composite parent) { + pLabel = new Label(parent, SWT.NONE); + pLabel.setText(CompareMessages.CompareWithOther_pathLabel); + pLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true)); + pathLabel = new Text(parent, SWT.MULTI); + pathLabel.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + pathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + } + + private String dividePath(String text) { + String[] parts; + int lineLengthLimit = computeLineLengthLimit(this); + int lineLength = 0; + String s = new String(); + String separator = new String(System.getProperty("file.separator")); //$NON-NLS-1$ + if (separator.equals("\\")) //$NON-NLS-1$ + parts = text.split("\\" + separator); //$NON-NLS-1$ + else + parts = text.split(separator); + for (int i = 0; i < parts.length; i++) { + lineLength += parts[i].length(); + if (lineLength >= lineLengthLimit) { + s += "\n"; //$NON-NLS-1$ + lineLength = 0; + } + s += parts[i]; + s += separator; + } + return s; + } } private class InternalGroup extends InternalSection { @@ -283,35 +491,39 @@ } public void createContents(Composite parent) { - createGroup(parent); - createFileLabel(); - createFileCombo(); - createClearButton(group); - initDrag(); - initDrop(); - } - - public void createGroup(Composite parent) { final Composite p = parent; expandable = new ExpandableComposite(parent, SWT.NONE, ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE); - super.createGroup(expandable); + super.createContents(expandable); expandable.setClient(group); expandable.addExpansionListener(new ExpansionAdapter() { public void expansionStateChanged(ExpansionEvent e) { p.layout(); + getShell().pack(); } }); } - protected void createClearButton(Composite parent) { + public void setEnabled(boolean enabled) { + expandable.setEnabled(enabled); + if (enabled) + setResource(fileText.getText()); + } + + protected void createInfo(Composite parent) { + createFileLabel(parent); + createFileCombo(parent); + createClearButton(parent); + createPathLabel(parent); + } + + private void createClearButton(Composite parent) { clearButton = createButton(parent, CLEAR_RETURN_CODE, CompareMessages.CompareWithOther_clear, false); clearButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } - public void widgetSelected(SelectionEvent e) { clearResource(); } @@ -328,14 +540,248 @@ } } + private class ClipboardSection { + + private Composite contents; + protected Button check; + protected Text preview; + protected Button showInEditorButton, refreshButton; + protected Button[] panels; + private IFile clipboardFile; + private Clipboard clipboard; + private InternalSection selectedSection; + + public ClipboardSection(Composite parent) { + createContents(parent); + clipboard = new Clipboard(Display.getDefault()); + String fileContent = (String) clipboard.getContents(TextTransfer.getInstance()); + clipboardFile = createClipboardFile(fileContent); + } + + private void createContents(Composite parent) { + + contents = new Composite(parent, SWT.NONE); + contents.setLayout(new GridLayout(3, false)); + + createCheckRadioComposite(contents); + + preview = new Text(contents, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); + preview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + preview.setEnabled(false); + + createButtonComposite(contents); + } + + private void createButtonComposite(Composite parent) { + + Composite buttonComposite = new Composite(parent, SWT.NONE); + buttonComposite.setLayout(new GridLayout(1, false)); + + createShowInEditorButton(buttonComposite); + createRefreshButton(buttonComposite); + } + + private void createShowInEditorButton(Composite parent) { + showInEditorButton = new Button(parent, SWT.PUSH); + showInEditorButton.setText(CompareMessages.CompareWithOther_showInEditorButton); + showInEditorButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + showInEditorButton.setEnabled(false); + showInEditorButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + public void widgetSelected(SelectionEvent e) { + IWorkbenchPage page = getWorkbenchPage(); + String id = getEditorId(page); + try { + FileEditorInput input = new FileEditorInput(clipboardFile); + closeEditorWithClipboard(page, id, input); + page.openEditor(input, id); + } catch (PartInitException e1) { + CompareUIPlugin.log(e1); + } + } + }); + } + + private void createRefreshButton(Composite parent) { + refreshButton = new Button(parent, SWT.PUSH); + refreshButton.setText(CompareMessages.CompareWithOther_refreshButton); + refreshButton.setEnabled(false); + refreshButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + refreshButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + public void widgetSelected(SelectionEvent e) { + setPreviewContent(); + clipboardFile = createClipboardFile(preview.getText()); + selectedSection.setResourceFromClipboard(clipboardFile); + } + }); + } + + private String getEditorId(IWorkbenchPage page) { + IEditorDescriptor descriptor = CompareUI.getPlugin().getWorkbench().getEditorRegistry().getDefaultEditor(clipboardFile.getName()); + return descriptor.getId(); + } + + private void closeEditorWithClipboard(IWorkbenchPage page, String id, IEditorInput input) throws PartInitException { + IEditorReference[] editors = page.getEditorReferences(); + for (int i = 0; i < editors.length; i++) + if (editors[i].getId().equals(id) && editors[i].getEditorInput().equals(input)) + page.closeEditor(editors[i].getEditor(false), false); + } + + public void closeEditorWithClipboard(IWorkbenchPage page) { + String id = getEditorId(page); + IEditorInput input = new FileEditorInput(clipboardFile); + try { + closeEditorWithClipboard(page, id, input); + } catch (PartInitException e) { + CompareUIPlugin.log(e); + } + } + + private void createCheckRadioComposite(Composite parent) { + + Composite checkAndRadioComposite = new Composite(parent, SWT.NONE); + checkAndRadioComposite.setLayout(new GridLayout(1, false)); + + check = new Button(checkAndRadioComposite, SWT.CHECK); + check.setText(CompareMessages.CompareWithOther_clipboardCheckBox); + + createRadioComposite(checkAndRadioComposite); + + check.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (check.getSelection() == true) { + setEnableForWidgets(true); + setPreviewContent(); + } + else { + setEnableForWidgets(false); + setEnableForPanels(true); + } + } + }); + } + + private void createRadioComposite(Composite parent) { + + Composite radioComposite = new Composite(parent, SWT.NONE); + radioComposite.setLayout(new GridLayout(3, false)); + + panels = new Button[3]; + + panels[0] = new Button(radioComposite, SWT.RADIO); + panels[0].setText(CompareMessages.CompareWithOther_clipboardRadioAncestor); + + panels[1] = new Button(radioComposite, SWT.RADIO); + panels[1].setText(CompareMessages.CompareWithOther_clipboardRadioLeft); + + panels[2] = new Button(radioComposite, SWT.RADIO); + panels[2].setText(CompareMessages.CompareWithOther_clipboardRadioRight); + + for (int i = 0; i < panels.length; i++) + panels[i].setEnabled(false); + + Listener listener = new Listener() { + public void handleEvent(Event event) { + for (int i = 0; i < panels.length; i++) + if (event.widget != panels[i]) + panels[i].setSelection(false); + if (event.widget instanceof Button) { + ((Button)event.widget).setSelection(true); + if (panels[0].getSelection()) + setEnableForPanels(ancestorPanel); + else if (panels[1].getSelection()) + setEnableForPanels(leftPanel); + else if (panels[2].getSelection()) + setEnableForPanels(rightPanel); + } + } + }; + for (int i = 0; i < panels.length; i++) + panels[i].addListener(SWT.Selection, listener); + } + + private void setPreviewContent() { + String clipboardContent = (String) clipboard.getContents(TextTransfer.getInstance()); + preview.setText(clipboardContent); + } + + private IFile createClipboardFile(String fileContent) { + IFile file = null; + try { + file = getClipboardFile(); + if (file.exists()) + file.delete(false, null); + InputStream source = new ByteArrayInputStream(fileContent.getBytes()); + file.create(source, IResource.NONE, null); + } catch (CoreException e) { + CompareUIPlugin.log(e); + MessageDialog.openError(getShell(), + CompareMessages.CompareWithOther_createTmpFile_title, + CompareMessages.CompareWithOther_createTmpFile_message); + return file; + } + return file; + } + + private IFile getClipboardFile() throws CoreException { + IFile file = null; + IProject project = createTmpProject(); + if (!project.isOpen()) + project.open(null); + IFolder folder = project.getFolder("ClipboardFolder"); //$NON-NLS-1$ + if (!folder.exists()) + folder.create(IResource.NONE, true, null); + file = folder.getFile(CompareMessages.CompareWithOther_fileName); + return file; + } + + private void setEnableForPanels(InternalSection selectedSection) { + this.selectedSection = selectedSection; + InternalSection[] sections = {ancestorPanel, leftPanel, rightPanel}; + for (int i = 0; i < sections.length; i++) + if (sections[i] == selectedSection) { + sections[i].setEnabled(false); + sections[i].setResourceFromClipboard(clipboardFile); + } else + sections[i].setEnabled(true); + } + + private void setEnableForPanels(boolean enabled) { + InternalSection[] sections = {ancestorPanel, leftPanel, rightPanel}; + for (int i = 0; i < sections.length; i++) + sections[i].setEnabled(enabled); + } + + private void setEnableForWidgets(boolean enabled) { + for (int i = 0; i < panels.length; i++) + panels[i].setEnabled(enabled); + showInEditorButton.setEnabled(enabled); + refreshButton.setEnabled(enabled); + preview.setEnabled(enabled); + } + + public void setLayoutData(GridData data) { + contents.setLayoutData(data); + } + + } + private Button okButton; private InternalGroup rightPanel, leftPanel; - private InternalExpandable ancestorPanel; + public InternalExpandable ancestorPanel; + private ClipboardSection clipboardSection; private ISelection fselection; + private int lineLimit = 0; /** * Creates the dialog. - * + * * @param shell * a shell * @param selection @@ -351,7 +797,7 @@ /* * (non-Javadoc) - * + * * @see * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets * .Composite) @@ -376,6 +822,11 @@ rightPanel.setText(CompareMessages.CompareWithOther_rightPanel); rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + clipboardSection = new ClipboardSection(mainPanel); + GridData data = new GridData(SWT.FILL, SWT.FILL, false, true); + data.horizontalSpan = 2; + clipboardSection.setLayoutData(data); + setSelection(fselection); getShell().setText(CompareMessages.CompareWithOther_dialogTitle); setTitle(CompareMessages.CompareWithOther_dialogMessage); @@ -387,7 +838,7 @@ /* * (non-Javadoc) - * + * * @see * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse * .swt.widgets.Composite) @@ -444,7 +895,6 @@ && ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$ setMessage(CompareMessages.CompareWithOther_warning_two_way, IMessageProvider.WARNING); - okButton.setEnabled(true); } else if (!isComparePossible()) { setMessage( CompareMessages.CompareWithOther_error_not_comparable, @@ -457,12 +907,23 @@ } } + public int computeLineLengthLimit(InternalSection section) { + int leftLenght = leftPanel.fileText.getCharCount(); + int rightLength = rightPanel.fileText.getCharCount(); + int maxLenght = (leftLenght > rightLength ? leftLenght : rightLength); + if (maxLenght > lineLimit) + lineLimit = maxLenght; + if (section instanceof InternalExpandable) + return Math.max(lineLimit * 2 + 20, 90); + return maxLenght; + } + /** * Returns table with selected resources. If any resource wasn't chosen in * the ancestor panel, table has only two elements -- resources chosen in * left and right panel. In the other case table contains all three * resources. - * + * * @return table with selected resources */ public IResource[] getResult() { @@ -477,4 +938,66 @@ rightResource }; return resources; } + + /* + * (non-javadoc) + * + * Implementation based on org.eclipse.jdt.internakl.core.ExternalFoldersManager#createExternalFoldersProject + */ + private IProject createTmpProject() throws CoreException { + IProject tmpProject = getTmpProject(); + if (!tmpProject.isAccessible()) { + try { + if (!tmpProject.exists()) { + IProjectDescription desc = tmpProject.getWorkspace() + .newProjectDescription(tmpProject.getName()); + IPath location = CompareUI.getPlugin() + .getStateLocation(); + desc.setLocation(location.append(TMP_PROJECT_NAME)); + tmpProject.create(desc, null); + } + try { + tmpProject.open(null); + } catch (CoreException e1) { // in case .project file or folder has been deleted + IPath location1 = CompareUI.getPlugin() + .getStateLocation(); + IPath projectPath1 = location1.append(TMP_PROJECT_NAME); + projectPath1.toFile().mkdirs(); + FileOutputStream output = new FileOutputStream( + projectPath1.append(".project").toOSString()); //$NON-NLS-1$ + try { + output.write(TMP_PROJECT_FILE.getBytes()); + } finally { + output.close(); + } + tmpProject.open(null); + } + } catch (IOException ioe) { + return tmpProject; + } catch (CoreException ce) { + throw new CoreException(ce.getStatus()); + } + } + return tmpProject; + } + + /* + * (non-javadoc) + * + * Following method is analogical to org.eclipse.jdt.internal + */ + private IProject getTmpProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject( + TMP_PROJECT_NAME); + } + + private IWorkbenchPage getWorkbenchPage() { + return CompareUI.getPlugin().getWorkbench().getActiveWorkbenchWindow().getActivePage(); + } + + public void okPressed() { + IWorkbenchPage page = getWorkbenchPage(); + clipboardSection.closeEditorWithClipboard(page); + super.okPressed(); + } } Index: compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java,v retrieving revision 1.2 diff -u -r1.2 CompareWithOtherResourceAction.java --- compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java 19 Aug 2008 07:58:04 -0000 1.2 +++ compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java 21 Aug 2008 12:51:16 -0000 @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.compare.internal; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; /** @@ -23,6 +26,8 @@ // Show CompareWithOtherResourceDialog which return resources to compare // and ancestor if specified. Don't need to display the other dialog showSelectAncestorDialog = false; + // prevent reusing old temporary files + cleanup(); super.run(selection); } @@ -32,4 +37,15 @@ return true; } + private void cleanup() { + try { + String projectName = CompareWithOtherResourceDialog.TMP_PROJECT_NAME; + IProject project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); + project.delete(true, true, null); + } catch (CoreException e) { + CompareUIPlugin.log(e); + } + } + } Index: compare/org/eclipse/compare/internal/CompareMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties,v retrieving revision 1.29 diff -u -r1.29 CompareMessages.properties --- compare/org/eclipse/compare/internal/CompareMessages.properties 19 Aug 2008 07:58:04 -0000 1.29 +++ compare/org/eclipse/compare/internal/CompareMessages.properties 21 Aug 2008 12:51:16 -0000 @@ -132,3 +132,17 @@ CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed. CompareWithOther_clear=Clear CompareWithOther_info=Drag files from a view or between dialog's fields. +CompareWithOther_externalFileButton=External file... +CompareWithOther_externalFolderBUtton=External folder... +CompareWithOther_externalFile_errorTitle=Compare With Other Resource Error +CompareWithOther_externalFile_errorMessage=I cannot create a link to external file. +CompareWithOther_pathLabel=Path: +CompareWithOther_fileName=clipboard.txt +CompareWithOther_createTmpFile_title= Unable to create file +CompareWithOther_createTmpFile_message= A file cannot be created from clipboard content. +CompareWithOther_showInEditorButton=Show in editor +CompareWithOther_refreshButton=Refresh +CompareWithOther_clipboardCheckBox=Use clipboard's content +CompareWithOther_clipboardRadioAncestor=Ancestor +CompareWithOther_clipboardRadioLeft=Left +CompareWithOther_clipboardRadioRight=Right