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 112655 Details for
Bug 73923
[Actions] Add "compare with arbitrary file"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch #7
73923_7.txt (text/plain), 33.32 KB, created by
Tomasz Zarna
on 2008-09-16 07:15:26 EDT
(
hide
)
Description:
patch #7
Filename:
MIME Type:
Creator:
Tomasz Zarna
Created:
2008-09-16 07:15:26 EDT
Size:
33.32 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 16 Sep 2008 11:12:46 -0000 >@@ -118,8 +118,18 @@ > public static String CompareWithOther_error_not_comparable; > public static String CompareWithOther_error_empty; > 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 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; > > 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 16 Sep 2008 11:12:46 -0000 >@@ -6,16 +6,29 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation >+ * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial implementation >+ * IBM Corporation - Bug 73923 (major refactoring and adjustments) > *******************************************************************************/ > package org.eclipse.compare.internal; > >+import java.io.FileOutputStream; >+import java.io.IOException; >+ > 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.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; >@@ -38,8 +51,11 @@ > 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.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.forms.events.ExpansionAdapter; >@@ -49,45 +65,42 @@ > > /** > * 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 MIN_WIDTH = 300; > private int MIN_HEIGHT = 175; >- >+ > 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 +152,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 +166,128 @@ > } > > } >- >- 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); >+ // temporarily hide this button. For more information about supporting for browsing workspace see bug 243744. >+ mainButton.setVisible(false); >+ } >+ >+ 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 +296,170 @@ > } > > 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)); >- } >- >- 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(); >+ >+ } >+ >+ 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 = tmpProject.getExternalFile(); >+ 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 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) { >- setResource(fileText.getText()); >- updateErrorInfo(); >+ IResource r = tmpProject.getExternalFolder(); >+ if (r == null) >+ return; >+ setResource(r); > } >- > }); > } > >- protected void createFileLabel() { >- final Label fileLabel = new Label(group, SWT.NONE); >- fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); >+ protected void setResource(IResource resource) { >+ super.setResource(resource); >+ text.setText(resource.getLocation().toOSString()); >+ } >+ >+ } >+ >+ 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; >+ >+ 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); >+ >+ addListenersToRadioButtons(); >+ } >+ >+ private void addListenersToRadioButtons() { >+ final ContentTypeElement[] elements = new ContentTypeElement[] { workspaceContent, >+ externalFileContent, externalFolderContent }; >+ 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 +487,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(); > } >@@ -327,11 +524,155 @@ > expandable.setLayoutData(layoutData); > } > } >- >+ >+ private class ExternalResourcesProject { >+ >+ // Implementation based on org.eclipse.jdt.internal.core.ExternalFoldersManager >+ >+ private int counter = 0; >+ >+ 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 TMP_FOLDER_NAME = "tmpFolder"; //$NON-NLS-1$ >+ >+ private ExternalResourcesProject() { >+ // nothing to do here >+ } >+ >+ private IProject createTmpProject() throws CoreException { >+ IProject project = getTmpProject(); >+ if (!project.isAccessible()) { >+ try { >+ IPath stateLocation = CompareUI.getPlugin().getStateLocation(); >+ if (!project.exists()) { >+ IProjectDescription desc = project.getWorkspace() >+ .newProjectDescription(project.getName()); >+ desc.setLocation(stateLocation.append(TMP_PROJECT_NAME)); >+ project.create(desc, null); >+ } >+ try { >+ project.open(null); >+ } catch (CoreException e) { // in case .project file or folder has been deleted >+ IPath projectPath = stateLocation.append(TMP_PROJECT_NAME); >+ projectPath.toFile().mkdirs(); >+ FileOutputStream output = new FileOutputStream( >+ projectPath.append(".project").toOSString()); //$NON-NLS-1$ >+ try { >+ output.write(TMP_PROJECT_FILE.getBytes()); >+ } finally { >+ output.close(); >+ } >+ project.open(null); >+ } >+ getTmpFolder(project); >+ } catch (IOException ioe) { >+ return project; >+ } catch (CoreException ce) { >+ throw new CoreException(ce.getStatus()); >+ } >+ } >+ project.setHidden(true); >+ return project; >+ } >+ >+ private IFolder getTmpFolder(IProject project) throws CoreException { >+ IFolder folder = project.getFolder(TMP_FOLDER_NAME); >+ if (!folder.exists()) >+ folder.create(IResource.NONE, true, null); >+ return folder; >+ } >+ >+ private IFile getExternalFile() { >+ FileDialog dialog = new FileDialog(getShell()); >+ String path = dialog.open(); >+ if (path != null) >+ return (IFile) linkResource(new Path(path)); >+ return null; >+ } >+ >+ private IFolder getExternalFolder() { >+ DirectoryDialog dialog = new DirectoryDialog(getShell()); >+ String path = dialog.open(); >+ if (path != null) >+ return (IFolder) linkResource(new Path(path)); >+ return null; >+ } >+ >+ private IResource linkResource(IPath path) { >+ IResource r = null; >+ String resourceName = path.lastSegment(); >+ try { >+ IProject project = createTmpProject(); >+ if (!project.isOpen()) >+ project.open(null); >+ if (path.toFile().isFile()) { >+ r = getTmpFolder(project).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 fileName = path.removeFileExtension().lastSegment(); >+ r = getTmpFolder(project).getFile(getName(fileName, extension)); >+ } >+ ((IFile)r).createLink(path, IResource.REPLACE, null); >+ } else { // isDirectory >+ r = getTmpFolder(project).getFolder(resourceName); >+ if (r.exists()) { >+ r = getTmpFolder(project).getFolder(getName(resourceName, null)); >+ } >+ ((IFolder)r).createLink(path, IResource.REPLACE, null); >+ } >+ } catch (CoreException e) { >+ CompareUIPlugin.log(e); >+ MessageDialog.openError(getShell(), >+ CompareMessages.CompareWithOther_externalFile_errorTitle, >+ CompareMessages.CompareWithOther_externalFile_errorMessage); >+ } >+ return r; >+ } >+ >+ /** >+ * This method is used to prevent duplicating names of linked resources. >+ * It adds a suffix based on the <code>counter</code> value. >+ * >+ * @param name >+ * @param extension optional >+ * @return >+ */ >+ private String getName(String name, String extension) { >+ if (counter != 0) { >+ name = name + "-" + counter; //$NON-NLS-1$ >+ } >+ // at most 3 resources at the same time with the same name: >+ // left, right, ancestor >+ counter = (counter + 1) % 3; >+ if (extension != null) { >+ name += "." + extension; //$NON-NLS-1$ >+ } >+ // don't change the name if counter equals 0 >+ return name; >+ } >+ >+ private IProject getTmpProject() { >+ return ResourcesPlugin.getWorkspace().getRoot().getProject( >+ TMP_PROJECT_NAME); >+ } >+ } >+ > private Button okButton; > private InternalGroup rightPanel, leftPanel; > private InternalExpandable ancestorPanel; >- private ISelection fselection; >+ private ISelection selection; >+ private ExternalResourcesProject tmpProject = new ExternalResourcesProject(); > > /** > * Creates the dialog. >@@ -346,7 +687,7 @@ > protected CompareWithOtherResourceDialog(Shell shell, ISelection selection) { > super(shell); > setShellStyle(SWT.MODELESS | SWT.RESIZE | SWT.MAX); >- fselection = selection; >+ this.selection = selection; > } > > /* >@@ -376,7 +717,7 @@ > rightPanel.setText(CompareMessages.CompareWithOther_rightPanel); > rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); > >- setSelection(fselection); >+ setSelection(selection); > getShell().setText(CompareMessages.CompareWithOther_dialogTitle); > setTitle(CompareMessages.CompareWithOther_dialogMessage); > getShell().setMinimumSize(convertHorizontalDLUsToPixels(MIN_WIDTH), >@@ -403,30 +744,36 @@ > 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()); >@@ -440,11 +787,6 @@ > setMessage(CompareMessages.CompareWithOther_error_empty, > IMessageProvider.ERROR); > okButton.setEnabled(false); >- } else if (ancestorPanel.getResource() == null >- && 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, >@@ -456,7 +798,7 @@ > } > } > } >- >+ > /** > * Returns table with selected resources. If any resource wasn't chosen in > * the ancestor panel, table has only two elements -- resources chosen in >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 16 Sep 2008 11:12:46 -0000 >@@ -6,16 +6,16 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation >+ * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial implementation >+ * IBM Corporation - Bug 73923 (major refactoring and adjustments) > *******************************************************************************/ > package org.eclipse.compare.internal; > > import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; > > /** > * The "Compare with other resource" action >- * >- * @since 3.4 > */ > public class CompareWithOtherResourceAction extends CompareAction { > >@@ -27,9 +27,12 @@ > } > > protected boolean isEnabled(ISelection selection) { >- // ignore returned value >- super.isEnabled(selection); >- return true; >+ int selectionSize = 0; >+ if (selection instanceof IStructuredSelection) { >+ selectionSize = ((IStructuredSelection) selection).toArray().length; >+ } >+ // enable for a single selection >+ return super.isEnabled(selection) || selectionSize == 1; > } > > } >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 16 Sep 2008 11:12:46 -0000 >@@ -129,6 +129,16 @@ > CompareWithOther_dialogMessage=Select resources to compare > CompareWithOther_error_not_comparable=Selected resources are not comparable. > 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_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 resource. >+CompareWithOther_pathLabel=Path: >+CompareWithOtherResourceDialog_externalFileMainButton=Browse... >+CompareWithOtherResourceDialog_externalFileRadioButton=External file >+CompareWithOtherResourceDialog_externalFolderMainButton=Browse... >+CompareWithOtherResourceDialog_externalFolderRadioButton=External folder >+CompareWithOtherResourceDialog_workspaceMainButton=Browse... >+CompareWithOtherResourceDialog_workspaceRadioButton=Workspace >Index: compare/org/eclipse/compare/internal/ResourceCompareInput.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java,v >retrieving revision 1.39 >diff -u -r1.39 ResourceCompareInput.java >--- compare/org/eclipse/compare/internal/ResourceCompareInput.java 19 Aug 2008 07:58:04 -0000 1.39 >+++ compare/org/eclipse/compare/internal/ResourceCompareInput.java 16 Sep 2008 11:12:46 -0000 >@@ -13,26 +13,47 @@ > package org.eclipse.compare.internal; > > import java.lang.reflect.InvocationTargetException; >-import com.ibm.icu.text.MessageFormat; > import java.util.HashSet; > import java.util.Set; > >-import org.eclipse.core.resources.*; >-import org.eclipse.core.runtime.*; >- >+import org.eclipse.compare.CompareConfiguration; >+import org.eclipse.compare.CompareEditorInput; >+import org.eclipse.compare.ITypedElement; >+import org.eclipse.compare.ZipFileStructureCreator; >+import org.eclipse.compare.structuremergeviewer.DiffNode; >+import org.eclipse.compare.structuremergeviewer.DiffTreeViewer; >+import org.eclipse.compare.structuremergeviewer.Differencer; >+import org.eclipse.compare.structuremergeviewer.IDiffContainer; >+import org.eclipse.compare.structuremergeviewer.IDiffElement; >+import org.eclipse.compare.structuremergeviewer.IStructureComparator; >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.action.IMenuManager; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.window.Window; > import org.eclipse.osgi.util.NLS; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.*; >-import org.eclipse.swt.layout.*; >-import org.eclipse.swt.widgets.*; >- >-import org.eclipse.jface.action.*; >-import org.eclipse.jface.dialogs.*; >-import org.eclipse.jface.viewers.*; >-import org.eclipse.jface.window.Window; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Shell; > >-import org.eclipse.compare.*; >-import org.eclipse.compare.structuremergeviewer.*; >+import com.ibm.icu.text.MessageFormat; > > > /** >@@ -415,6 +436,9 @@ > } > > private String buildLabel(IResource r) { >+ // for a linked resource in a hidden project use its local file system location >+ if (r.isLinked() && r.getProject().isHidden()) >+ return r.getLocation().toString(); > String n= r.getFullPath().toString(); > if (n.charAt(0) == IPath.SEPARATOR) > return n.substring(1);
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 73923
:
109656
|
110437
|
110778
|
110788
|
111014
|
111817
|
112070
| 112655 |
112656