Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111072 Details for
Bug 241088
Adding clipboard content to Compare with Other dialog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch #5
patch-241088.txt (text/plain), 33.43 KB, created by
Aleksandra Wozniak
on 2008-08-27 10:19:18 EDT
(
hide
)
Description:
patch #5
Filename:
MIME Type:
Creator:
Aleksandra Wozniak
Created:
2008-08-27 10:19:18 EDT
Size:
33.43 KB
patch
obsolete
>### 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 27 Aug 2008 14:13:40 -0000 >@@ -118,8 +118,25 @@ > public static String CompareWithOther_error_not_comparable; > public static String CompareWithOther_error_empty; > public static String CompareWithOther_clear; >+ public static String CompareWithOther_clipboardRadioButton; > 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 CompareWithOtherResourceDialog_externalFileMainButton; >+ public static String CompareWithOtherResourceDialog_externalFileRadioButton; >+ public static String CompareWithOtherResourceDialog_externalFolderMainButton; >+ public static String CompareWithOtherResourceDialog_externalFolderRadioButton; >+ public static String CompareWithOtherResourceDialog_workspaceMainButton; >+ public static String CompareWithOtherResourceDialog_workspaceRadioButton; >+ public static String CompareWithOther_showInEditorButton; >+ public static String CompareWithOther_refreshButton; >+ public static String CompareWithOther_createTmpFile_title; >+ public static String CompareWithOther_createTmpFile_message; >+ public static String CompareWithOther_fileName; > > static { > NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class); >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 27 Aug 2008 14:13:41 -0000 >@@ -23,6 +23,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 >+ CompareWithOtherResourceDialog.cleanup(); > super.run(selection); > } > >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 27 Aug 2008 14:13:41 -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; >@@ -38,13 +54,22 @@ > 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.IEditorReference; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.PartInitException; > 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; > > /** >@@ -53,41 +78,53 @@ > * @since 3.4 > */ > public class CompareWithOtherResourceDialog extends TitleAreaDialog { >- >- private int CLEAR_RETURN_CODE = 150; // any number != 0 >+ > private int MIN_WIDTH = 300; > private int MIN_HEIGHT = 175; >+ >+ private static final String TMP_PROJECT_NAME = ".org.eclipse.compare.tmp"; //$NON-NLS-1$ >+ private final static String TMP_PROJECT_FILE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ >+ + "<projectDescription>\n" //$NON-NLS-1$ >+ + "\t<name>" + TMP_PROJECT_NAME + "\t</name>\n" //$NON-NLS-1$ //$NON-NLS-2$ >+ + "\t<comment></comment>\n" //$NON-NLS-1$ >+ + "\t<projects>\n" //$NON-NLS-1$ >+ + "\t</projects>\n" //$NON-NLS-1$ >+ + "\t<buildSpec>\n" //$NON-NLS-1$ >+ + "\t</buildSpec>\n" //$NON-NLS-1$ >+ + "\t<natures>\n" + "\t</natures>\n" //$NON-NLS-1$//$NON-NLS-2$ >+ + "</projectDescription>"; //$NON-NLS-1$ >+ private final static String EXTERNAL_FILES_FOLDER_NAME = "ExternalFilesFolder"; //$NON-NLS-1$ > > private class FileTextDragListener implements DragSourceListener { > >- private InternalSection section; >+ private ContentTypeElement element; > >- public FileTextDragListener(InternalSection section) { >- this.section = section; >+ public FileTextDragListener(ContentTypeElement element) { >+ this.element = element; > } > > public void dragFinished(DragSourceEvent event) { >- section.fileText.setText(""); //$NON-NLS-1$ >+ element.setText(""); //$NON-NLS-1$ > } > > public void dragSetData(DragSourceEvent event) { >- event.data = section.fileText.getText(); >+ event.data = element.getText(); > } > > public void dragStart(DragSourceEvent event) { >- if (section.fileText.getText() == null) >+ if (element.getText() == null) > event.doit = false; > } > } > > private class FileTextDropListener implements DropTargetListener { > >- private InternalSection section; >+ private ContentTypeElement element; > private ResourceTransfer resourceTransfer; > private TextTransfer textTransfer; > >- public FileTextDropListener(InternalSection section) { >- this.section = section; >+ public FileTextDropListener(ContentTypeElement element) { >+ this.element = element; > resourceTransfer = ResourceTransfer.getInstance(); > textTransfer = TextTransfer.getInstance(); > } >@@ -139,13 +176,13 @@ > String txt = (String) event.data; > IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt); > if (r != null) >- section.setResource(r); >+ element.setResource(r); > } else if (resourceTransfer.isSupportedType(event.currentDataType)) { > IResource[] files = (IResource[]) event.data; >- section.setResource(files[0]); >- } >+ if (files.length > 0) >+ element.setResource(files[0]); >+ } > >- updateErrorInfo(); > } > > public void dropAccept(DropTargetEvent event) { >@@ -153,57 +190,126 @@ > } > > } >- >- private abstract class InternalSection { >- >- protected Group group; >- protected Text fileText; >+ >+ private abstract class ContentTypeElement { >+ >+ private Button radioButton; >+ protected Button mainButton; >+ protected Text text; >+ private String type; >+ protected InternalSection section; > private IResource resource; >- >- public InternalSection(Composite parent) { >+ >+ public ContentTypeElement(Composite parent, String type, InternalSection section) { >+ this.type = type; >+ this.section = section; > createContents(parent); > } >- >- private InternalSection() { >- // not to instantiate >+ >+ private void createContents(Composite parent) { >+ createRadioButton(parent); >+ createText(parent); >+ createMainButton(parent); >+ } >+ >+ private void createRadioButton(Composite parent) { >+ radioButton = new Button(parent, SWT.RADIO); >+ radioButton.setText(type); >+ } >+ >+ protected void createText(Composite parent) { >+ text = new Text(parent, SWT.BORDER); >+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >+ text.setEditable(false); >+ } >+ >+ protected void createMainButton(Composite parent) { >+ mainButton = new Button(parent, SWT.PUSH); >+ mainButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); >+ } >+ >+ protected Button getRadioButton() { >+ return radioButton; >+ } >+ >+ protected String getText() { >+ return text.getText(); >+ } >+ >+ protected void setText(String string) { >+ text.setText(string); >+ } >+ >+ protected InternalSection getSection() { >+ return section; >+ } >+ >+ protected void setEnabled(boolean enabled) { >+ radioButton.setSelection(enabled); >+ mainButton.setEnabled(enabled); >+ text.setEnabled(enabled); > } >- >- public void createContents(Composite parent) { >- createGroup(parent); >- createFileLabel(); >- createFileCombo(); >- initDrag(); >- initDrop(); >+ >+ protected void setResource(IResource resource) { >+ this.resource = resource; >+ section.setResource(resource); > } > > public IResource getResource() { > return resource; > } >- >- public void setResource(IResource resource) { >- this.resource = resource; >- String txt = resource.getFullPath().toString(); >- fileText.setText(txt); >+ >+ void clearResource() { >+ resource = null; >+ text.setText(""); //$NON-NLS-1$ > } >+ >+ } >+ >+ private class WorkspaceContent extends ContentTypeElement { >+ >+ public WorkspaceContent(Composite parent, InternalSection section) { >+ super(parent, CompareMessages.CompareWithOtherResourceDialog_workspaceRadioButton, section); >+ } >+ >+ protected void createMainButton(Composite parent) { >+ super.createMainButton(parent); >+ mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_workspaceMainButton); >+ } >+ >+ protected void createText(Composite parent) { >+ >+ super.createText(parent); >+ text.setEditable(true); >+ >+ text.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ section.setResource(text.getText()); >+ updateErrorInfo(); >+ } >+ }); > >- public void setResource(String s) { >- IResource tmp = ResourcesPlugin.getWorkspace().getRoot() >- .findMember(s); >- if (tmp instanceof IWorkspaceRoot) >- resource = null; >- else >- resource = tmp; >- >+ text.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ public void widgetSelected(SelectionEvent e) { >+ section.setResource(text.getText()); >+ updateErrorInfo(); >+ } >+ }); >+ >+ initDrag(); >+ initDrop(); > } > >- protected void clearResource() { >- resource = null; >- fileText.setText(""); //$NON-NLS-1$ >- updateErrorInfo(); >+ protected void setResource(IResource resource) { >+ super.setResource(resource); >+ text.setText(resource.getFullPath().toOSString()); > } > > protected void initDrag() { >- DragSource source = new DragSource(fileText, DND.DROP_MOVE >+ DragSource source = new DragSource(text, DND.DROP_MOVE > | DND.DROP_COPY | DND.DROP_DEFAULT); > Transfer[] types = new Transfer[] { TextTransfer.getInstance(), > ResourceTransfer.getInstance() }; >@@ -212,49 +318,249 @@ > } > > protected void initDrop() { >- DropTarget target = new DropTarget(fileText, DND.DROP_MOVE >+ DropTarget target = new DropTarget(text, DND.DROP_MOVE > | DND.DROP_COPY | DND.DROP_DEFAULT); > Transfer[] types = new Transfer[] { TextTransfer.getInstance(), > ResourceTransfer.getInstance() }; > target.setTransfer(types); > 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)); >+ >+ } >+ >+ private class ExternalFileContent extends ContentTypeElement { >+ >+ public ExternalFileContent(Composite parent, InternalSection section) { >+ super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFileRadioButton, section); >+ } >+ >+ protected void createMainButton(Composite parent) { >+ super.createMainButton(parent); >+ mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFileMainButton); >+ mainButton.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ public void widgetSelected(SelectionEvent e) { >+ IResource r = getExtenalFile(); >+ if (r == null) >+ return; >+ setResource(r); >+ } >+ }); > } > >- protected void createFileCombo() { >- fileText = new Text(group, SWT.BORDER); >- fileText >- .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); >- >- fileText.addModifyListener(new ModifyListener() { >- public void modifyText(ModifyEvent e) { >- setResource(fileText.getText()); >- updateErrorInfo(); >+ protected void setResource(IResource resource) { >+ super.setResource(resource); >+ text.setText(resource.getLocation().toOSString()); >+ } >+ >+ } >+ >+ private class ExternalFolderContent extends ContentTypeElement { >+ >+ public ExternalFolderContent(Composite parent, InternalSection section) { >+ super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFolderRadioButton, section); >+ } >+ >+ protected void createMainButton(Composite parent) { >+ super.createMainButton(parent); >+ mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFolderMainButton); >+ mainButton.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ public void widgetSelected(SelectionEvent e) { >+ IResource r = getExternalDirectory(); >+ if (r == null) >+ return; >+ setResource(r); > } > }); >+ } > >- fileText.addSelectionListener(new SelectionListener() { >+ protected void setResource(IResource resource) { >+ super.setResource(resource); >+ text.setText(resource.getLocation().toOSString()); >+ } >+ >+ } >+ >+ private class ClipboardContent extends ContentTypeElement { >+ >+ protected Button showInEditorButton; >+ private Clipboard clipboard; >+ >+ public ClipboardContent(Composite parent, InternalSection section) { >+ super(parent, CompareMessages.CompareWithOther_clipboardRadioButton, section); >+ clipboard = new Clipboard(Display.getDefault()); >+ } >+ >+ protected void createText(Composite parent) { >+ text = new Text(parent, SWT.BORDER | SWT.MULTI); >+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >+ text.setEditable(false); >+ } >+ >+ protected void createMainButton(Composite parent) { >+ >+ Composite buttonComposite = new Composite(parent, SWT.NONE); >+ buttonComposite.setLayout(new GridLayout(1, false)); >+ >+ createRefreshButton(buttonComposite); >+ createShowInEditorButton(buttonComposite); >+ } >+ >+ protected void setEnabled(boolean enabled) { >+ super.setEnabled(enabled); >+ showInEditorButton.setEnabled(enabled); >+ if (enabled) { >+ String fileContent = clipboard.getContents(TextTransfer.getInstance()).toString(); >+ text.setText(fileContent); >+ setResource(createClipboardFile(fileContent)); >+ } >+ } > >+ 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) { >- setResource(fileText.getText()); >- updateErrorInfo(); >+ IWorkbenchPage page = getWorkbenchPage(); >+ String id = getEditorId(page); >+ try { >+ FileEditorInput input = new FileEditorInput((IFile)getResource()); >+ closeEditorWithClipboard(page); >+ page.openEditor(input, id); >+ } catch (PartInitException e1) { >+ CompareUIPlugin.log(e1); >+ } > } >+ }); >+ } > >+ private void createRefreshButton(Composite parent) { >+ mainButton = new Button(parent, SWT.PUSH); >+ mainButton.setText(CompareMessages.CompareWithOther_refreshButton); >+ mainButton.setEnabled(false); >+ mainButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); >+ mainButton.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ public void widgetSelected(SelectionEvent e) { >+ String fileContent = clipboard.getContents(TextTransfer.getInstance()).toString(); >+ text.setText(fileContent); >+ setResource(createClipboardFile(fileContent)); >+ } > }); > } >+ } > >- protected void createFileLabel() { >- final Label fileLabel = new Label(group, SWT.NONE); >- fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); >+ >+ private abstract class InternalSection { >+ >+ // there is no "enum" support in Java 1.4. Sigh... >+ public static final int WORKSPACE = 0; >+ public static final int EXTERNAL_FILE = 1; >+ public static final int EXTERNAL_FOLDER = 2; >+ >+ protected Group group; >+ private IResource resource; >+ >+ ExternalFileContent externalFileContent; >+ ExternalFolderContent externalFolderContent; >+ WorkspaceContent workspaceContent; >+ ClipboardContent clipboardContent; >+ >+ public InternalSection(Composite parent) { >+ createContents(parent); >+ } >+ >+ private InternalSection() { >+ // not to instantiate >+ } >+ >+ protected void createContents(Composite parent) { >+ >+ group = new Group(parent, SWT.NONE); >+ group.setLayout(new GridLayout(3, false)); >+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); >+ >+ workspaceContent = new WorkspaceContent(group, this); >+ externalFileContent = new ExternalFileContent(group, this); >+ externalFolderContent = new ExternalFolderContent(group, this); >+ clipboardContent = new ClipboardContent(group, this); >+ >+ addListenersToRadioButtons(); >+ } >+ >+ private void addListenersToRadioButtons() { >+ final ContentTypeElement[] elements = new ContentTypeElement[] { workspaceContent, >+ externalFileContent, externalFolderContent, clipboardContent }; >+ for (int i = 0; i < elements.length; i++) >+ elements[i].getRadioButton().addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ for (int j = 0; j < elements.length; j++) >+ if (event.widget != elements[j].getRadioButton()) >+ elements[j].setEnabled(false); >+ else { >+ elements[j].setEnabled(true); >+ setResource(elements[j].getResource()); >+ } >+ } >+ }); >+ } >+ >+ protected IResource getResource() { >+ return resource; >+ } >+ >+ protected void setResource(IResource resource) { >+ this.resource = resource; >+ updateErrorInfo(); >+ } >+ >+ protected void setResource(String s) { >+ IResource tmp = ResourcesPlugin.getWorkspace().getRoot() >+ .findMember(s); >+ if (tmp instanceof IWorkspaceRoot) >+ resource = null; >+ else >+ resource = tmp; >+ updateErrorInfo(); >+ } >+ >+ protected void clearResource() { >+ resource = null; >+ workspaceContent.clearResource(); >+ externalFileContent.clearResource(); >+ externalFolderContent.clearResource(); >+ updateErrorInfo(); >+ } >+ >+ protected void setContentType(int type) { >+ switch(type) { >+ case WORKSPACE: >+ workspaceContent.setEnabled(true); >+ externalFileContent.setEnabled(false); >+ externalFolderContent.setEnabled(false); >+ break; >+ case EXTERNAL_FILE: >+ workspaceContent.setEnabled(false); >+ externalFileContent.setEnabled(true); >+ externalFolderContent.setEnabled(false); >+ break; >+ case EXTERNAL_FOLDER: >+ workspaceContent.setEnabled(false); >+ externalFileContent.setEnabled(false); >+ externalFolderContent.setEnabled(true); >+ } > } > } > >@@ -282,36 +588,28 @@ > createContents(parent); > } > >- public void createContents(Composite parent) { >- createGroup(parent); >- createFileLabel(); >- createFileCombo(); >- createClearButton(group); >- initDrag(); >- initDrop(); >- } >- >- public void createGroup(Composite parent) { >+ protected void createContents(Composite parent) { > final Composite p = parent; > expandable = new ExpandableComposite(parent, SWT.NONE, > ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE); >- super.createGroup(expandable); >+ super.createContents(expandable); >+ createClearButton(group); > expandable.setClient(group); > expandable.addExpansionListener(new ExpansionAdapter() { > public void expansionStateChanged(ExpansionEvent e) { > p.layout(); >+ getShell().pack(); > } > }); > } > >- protected void createClearButton(Composite parent) { >- clearButton = createButton(parent, CLEAR_RETURN_CODE, >- CompareMessages.CompareWithOther_clear, false); >+ private void createClearButton(Composite parent) { >+ clearButton = new Button(parent, SWT.PUSH); >+ clearButton.setText(CompareMessages.CompareWithOther_clear); > clearButton.addSelectionListener(new SelectionListener() { > public void widgetDefaultSelected(SelectionEvent e) { > widgetSelected(e); > } >- > public void widgetSelected(SelectionEvent e) { > clearResource(); > } >@@ -332,6 +630,8 @@ > private InternalGroup rightPanel, leftPanel; > private InternalExpandable ancestorPanel; > private ISelection fselection; >+ private int externalFilesCounter = 0; >+ int clipboardCounter = 0; > > /** > * Creates the dialog. >@@ -403,45 +703,50 @@ > IResource[] selectedResources = Utilities.getResources(selection); > switch (selectedResources.length) { > case 1: >- leftPanel.setResource(selectedResources[0]); >+ leftPanel.workspaceContent.setResource(selectedResources[0]); > break; > case 2: >- leftPanel.setResource(selectedResources[0]); >- rightPanel.setResource(selectedResources[1]); >+ leftPanel.workspaceContent.setResource(selectedResources[0]); >+ rightPanel.workspaceContent.setResource(selectedResources[1]); > break; > case 3: >- ancestorPanel.setResource(selectedResources[0]); >+ ancestorPanel.workspaceContent.setResource(selectedResources[0]); > ancestorPanel.expandable.setExpanded(true); >- leftPanel.setResource(selectedResources[1]); >- rightPanel.setResource(selectedResources[2]); >+ leftPanel.workspaceContent.setResource(selectedResources[1]); >+ rightPanel.workspaceContent.setResource(selectedResources[2]); > break; > } >+ setInitialContentTypes(); >+ } >+ >+ private void setInitialContentTypes() { >+ ancestorPanel.setContentType(InternalSection.WORKSPACE); >+ leftPanel.setContentType(InternalSection.WORKSPACE); >+ rightPanel.setContentType(InternalSection.WORKSPACE); > } > > private boolean isComparePossible() { > IResource[] resources; >- if (ancestorPanel.getResource() == null) { >+ if (ancestorPanel.getResource() == null) > resources = new IResource[] { leftPanel.getResource(), > rightPanel.getResource() }; >- } else { >+ else > resources = new IResource[] { ancestorPanel.getResource(), > leftPanel.getResource(), rightPanel.getResource() }; >- } > > ResourceCompareInput r = new ResourceCompareInput( > new CompareConfiguration()); > return r.isEnabled(new StructuredSelection(resources)); > } > >- private void updateErrorInfo() { >+ public void updateErrorInfo() { > if (okButton != null) { > if (leftPanel.getResource() == null > || rightPanel.getResource() == null) { > setMessage(CompareMessages.CompareWithOther_error_empty, > IMessageProvider.ERROR); > okButton.setEnabled(false); >- } else if (ancestorPanel.getResource() == null >- && ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$ >+ } else if (ancestorPanel.getResource() == null && isComparePossible()) { > setMessage(CompareMessages.CompareWithOther_warning_two_way, > IMessageProvider.WARNING); > okButton.setEnabled(true); >@@ -456,6 +761,168 @@ > } > } > } >+ >+ private IFile getExtenalFile() { >+ FileDialog dialog = new FileDialog(getShell()); >+ String path = dialog.open(); >+ if (path != null) >+ return (IFile) getResource(new Path(path), IResource.FILE); >+ return null; >+ } >+ >+ private IFolder getExternalDirectory() { >+ DirectoryDialog dialog = new DirectoryDialog(getShell()); >+ String path = dialog.open(); >+ if (path != null) >+ return (IFolder) getResource(new Path(path), IResource.FOLDER); >+ return null; >+ } >+ >+ private IResource getResource(IPath path, int type) { >+ IResource r = null; >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IWorkspaceRoot root = workspace.getRoot(); >+ IProject project = root.getProject(TMP_PROJECT_NAME); >+ String resourceName = path.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()) { // add a number to file's name when there already is a file with that name in a folder >+ String extension = path.getFileExtension(); >+ String newName = path.removeFileExtension().lastSegment(); >+ newName += "-" + externalFilesCounter + "." + extension; //$NON-NLS-1$ //$NON-NLS-2$ >+ r = folderForExternal.getFile(newName); >+ } >+ ((IFile)r).createLink(path, IResource.REPLACE, null); >+ externalFilesCounter++; >+ } >+ else { >+ r = folderForExternal.getFolder(resourceName); >+ if (r.exists()) { >+ String newName = resourceName + "-" + externalFilesCounter; //$NON-NLS-1$ >+ r = folderForExternal.getFolder(newName); >+ } >+ ((IFolder)r).createLink(path, IResource.REPLACE, null); >+ externalFilesCounter++; >+ } >+ } catch (CoreException e) { >+ CompareUIPlugin.log(e); >+ MessageDialog.openError(getShell(), >+ CompareMessages.CompareWithOther_externalFile_errorTitle, >+ CompareMessages.CompareWithOther_externalFile_errorMessage); >+ } >+ return r; >+ } >+ >+ /* >+ * (non-javadoc) >+ * >+ * Implementation based on org.eclipse.jdt.internal.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 String getEditorId(IWorkbenchPage page) { >+ IFile file = createClipboardFile("test content"); //$NON-NLS-1$ // create empty clipboard file to get it's default editor >+ IEditorDescriptor descriptor = CompareUI.getPlugin().getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); >+ if (descriptor != null) >+ return descriptor.getId(); >+ return null; >+ } >+ >+ private void closeEditorWithClipboard(IWorkbenchPage page) { >+ IEditorReference[] editors = page.getEditorReferences(); >+ for (int j = 0; j < clipboardCounter; j++) >+ for (int i = 0; i < editors.length; i++) { >+ String name = CompareMessages.CompareWithOther_fileName + "-" + j + ".txt"; //$NON-NLS-1$ //$NON-NLS-2$ >+ try { >+ if (editors[i].getEditorInput().getName().equals(name)) >+ page.closeEditor(editors[i].getEditor(false), false); >+ } catch (PartInitException e) { >+ CompareUIPlugin.log(e); >+ } >+ } >+ } >+ >+ private IFile createClipboardFile(String fileContent) { >+ IFile file = null; >+ try { >+ file = getClipboardFileHandler(); >+ 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 getClipboardFileHandler() 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 + "-" + clipboardCounter + ".txt"); //$NON-NLS-1$ //$NON-NLS-2$ >+ clipboardCounter++; >+ return file; >+ } >+ > > /** > * Returns table with selected resources. If any resource wasn't chosen in >@@ -477,4 +944,28 @@ > rightResource }; > return resources; > } >+ >+ /** >+ * Removes temporary files created from clipboard's content or imported to >+ * workspace only for comparing. >+ */ >+ public static void cleanup() { >+ try { >+ IProject project = ResourcesPlugin.getWorkspace().getRoot() >+ .getProject(TMP_PROJECT_NAME); >+ project.delete(true, true, null); >+ } catch (CoreException e) { >+ CompareUIPlugin.log(e); >+ } >+ } >+ >+ private IWorkbenchPage getWorkbenchPage() { >+ return CompareUI.getPlugin().getWorkbench().getActiveWorkbenchWindow().getActivePage(); >+ } >+ >+ public void okPressed() { >+ IWorkbenchPage page = getWorkbenchPage(); >+ closeEditorWithClipboard(page); >+ super.okPressed(); >+ } > } >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 27 Aug 2008 14:13:41 -0000 >@@ -131,4 +131,21 @@ > CompareWithOther_error_empty=Both left and right panel must contain a valid path. > CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed. > CompareWithOther_clear=Clear >+CompareWithOther_clipboardRadioButton=Clipboard > 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=Cannot create a link to an external file. >+CompareWithOther_pathLabel=Path: >+CompareWithOtherResourceDialog_externalFileMainButton=Browse... >+CompareWithOtherResourceDialog_externalFileRadioButton=External file >+CompareWithOtherResourceDialog_externalFolderMainButton=Browse... >+CompareWithOtherResourceDialog_externalFolderRadioButton=External folder >+CompareWithOtherResourceDialog_workspaceMainButton=Browse... >+CompareWithOtherResourceDialog_workspaceRadioButton=Workspace >+CompareWithOther_showInEditorButton=Show in editor >+CompareWithOther_refreshButton=Refresh >+CompareWithOther_createTmpFile_title=Unable to create a file >+CompareWithOther_createTmpFile_message=A file cannot be created from clipbard's content. >+CompareWithOther_fileName=clipboard
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 241088
:
109159
|
109642
|
110561
|
110779
|
111072
|
111197
|
111399
|
117986