diff options
543 files changed, 24185 insertions, 24185 deletions
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java index 9b7b584dc..ab64d83a3 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java @@ -68,7 +68,7 @@ public class FileDiffResult implements IFilePatchResult { * @param content the contents being patched or <code>null</code> for an addition * @param monitor a progress monitor or <code>null</code> if no progress monitoring is desired */ - public void refresh(ReaderCreator content, IProgressMonitor monitor) { + public void refresh(ReaderCreator content, IProgressMonitor monitor) { this.fMatches= false; this.fDiffProblem= false; boolean create= false; diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java index f66faad94..4160b131f 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java @@ -58,17 +58,17 @@ public class FilePatch2 implements IFilePatch2 { * @param newPath the path of the after state * @param newDate the timestamp of the after state */ - public FilePatch2(IPath oldPath, long oldDate, IPath newPath, long newDate) { + public FilePatch2(IPath oldPath, long oldDate, IPath newPath, long newDate) { this.fOldPath= oldPath; this.oldDate = oldDate; this.fNewPath= newPath; this.newDate = newDate; } - /** - * Return the parent project or <code>null</code> if there isn't one. - * @return the parent project or <code>null</code> - */ + /** + * Return the parent project or <code>null</code> if there isn't one. + * @return the parent project or <code>null</code> + */ public DiffProject getProject() { return this.fProject; } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java index 938d99774..2256d28b7 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java @@ -63,9 +63,9 @@ public class Hunk implements IHunk { public Hunk(FilePatch2 parent, int hunkType, int oldStart, int oldLength, int newStart, int newLength, String[] lines) { this.fParent = parent; - if (this.fParent != null) { - this.fParent.add(this); - } + if (this.fParent != null) { + this.fParent.add(this); + } this.hunkType = hunkType; this.fOldLength = oldLength; this.fOldStart = oldStart; @@ -74,9 +74,9 @@ public class Hunk implements IHunk { this.fLines = lines; } - public Hunk(FilePatch2 parent, Hunk toCopy) { - this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines); - } + public Hunk(FilePatch2 parent, Hunk toCopy) { + this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines); + } /* * Returns the contents of this hunk. diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java index 7ae7880ff..f7732e063 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java @@ -121,15 +121,15 @@ public class LineReader { this.fIgnoreSingleCR= true; } - /** - * Reads a line of text. A line is considered to be terminated by any one - * of a line feed ('\n'), a carriage return ('\r'), or a carriage return - * followed immediately by a line-feed. - * @return A string containing the contents of the line including - * the line-termination characters, or <code>null</code> if the end of the - * stream has been reached - * @exception IOException If an I/O error occurs - */ + /** + * Reads a line of text. A line is considered to be terminated by any one + * of a line feed ('\n'), a carriage return ('\r'), or a carriage return + * followed immediately by a line-feed. + * @return A string containing the contents of the line including + * the line-termination characters, or <code>null</code> if the end of the + * stream has been reached + * @exception IOException If an I/O error occurs + */ String readLine() throws IOException { try { while (!this.fSawEOF) { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java index 058aedbc7..7bf46f7c5 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java @@ -671,7 +671,7 @@ public class PatchReader { while (st.hasMoreElements()) { String token= st.nextToken().trim(); if (token.length() > 0) - l.add(token); + l.add(token); } return l.toArray(new String[l.size()]); } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java index f7f919227..a7dd086bc 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java @@ -42,8 +42,8 @@ import java.util.List; } /* - * Returns the number of RangeDifferences - */ + * Returns the number of RangeDifferences + */ int getCount() { return this.fRange.size(); } @@ -72,8 +72,8 @@ import java.util.List; } /* - * Removes all <code>RangeDifference</code>s - */ + * Removes all <code>RangeDifference</code>s + */ void removeAll() { this.fRange.clear(); } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java index ba0f856fb..7949b3a03 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java @@ -151,7 +151,7 @@ import org.eclipse.core.runtime.*; * @param length The number of non-empty (i.e non-zero) entries in LCS * @param comparator The comparator used to generate the LCS */ - private void compactAndShiftLCS(int[] lcsSide, int length, + private void compactAndShiftLCS(int[] lcsSide, int length, IRangeComparator comparator) { // If the LCS is empty, just return if (length == 0) diff --git a/bundles/org.eclipse.compare.win32/META-INF/MANIFEST.MF b/bundles/org.eclipse.compare.win32/META-INF/MANIFEST.MF index 124efe42c..6321d2dd5 100644 --- a/bundles/org.eclipse.compare.win32/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.compare.win32/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.compare.win32;singleton:=true -Bundle-Version: 1.2.400.qualifier +Bundle-Version: 1.2.500.qualifier Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-PlatformFilter: (osgi.os=win32) diff --git a/bundles/org.eclipse.compare.win32/pom.xml b/bundles/org.eclipse.compare.win32/pom.xml index c89baa794..859508af4 100644 --- a/bundles/org.eclipse.compare.win32/pom.xml +++ b/bundles/org.eclipse.compare.win32/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.compare</groupId> <artifactId>org.eclipse.compare.win32</artifactId> - <version>1.2.400-SNAPSHOT</version> + <version>1.2.500-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <build> diff --git a/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java b/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java index bceda549b..a6cef6046 100644 --- a/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java +++ b/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java @@ -410,56 +410,56 @@ public class WordComparison { || (!inplace && getDocumentDirty(document)); } - /** - * Initialize the workbench menus for proper menu merging - * Copied from org.eclipse.ui.internal.editorsupport.win32OleEditor - */ - protected void initializeWorkbenchMenus(IWorkbenchWindow window) { - //If there was an OLE Error or nothing has been created yet - if (frame == null || frame.isDisposed()) - return; - // Get the browser menu bar. If one does not exist then - // create it. - Shell shell = frame.getShell(); - Menu menuBar = shell.getMenuBar(); - if (menuBar == null) { - menuBar = new Menu(shell, SWT.BAR); - shell.setMenuBar(menuBar); - } + /** + * Initialize the workbench menus for proper menu merging + * Copied from org.eclipse.ui.internal.editorsupport.win32OleEditor + */ + protected void initializeWorkbenchMenus(IWorkbenchWindow window) { + //If there was an OLE Error or nothing has been created yet + if (frame == null || frame.isDisposed()) + return; + // Get the browser menu bar. If one does not exist then + // create it. + Shell shell = frame.getShell(); + Menu menuBar = shell.getMenuBar(); + if (menuBar == null) { + menuBar = new Menu(shell, SWT.BAR); + shell.setMenuBar(menuBar); + } - // Swap the file and window menus. - MenuItem[] windowMenu = new MenuItem[1]; - MenuItem[] fileMenu = new MenuItem[1]; - Vector containerItems = new Vector(); + // Swap the file and window menus. + MenuItem[] windowMenu = new MenuItem[1]; + MenuItem[] fileMenu = new MenuItem[1]; + Vector containerItems = new Vector(); - for (int i = 0; i < menuBar.getItemCount(); i++) { - MenuItem item = menuBar.getItem(i); - String id = ""; //$NON-NLS-1$ - if (item.getData() instanceof IMenuManager) - id = ((IMenuManager) item.getData()).getId(); - if (id.equals(IWorkbenchActionConstants.M_FILE)) - fileMenu[0] = item; - else if (id.equals(IWorkbenchActionConstants.M_WINDOW)) - windowMenu[0] = item; - else { - if (window.isApplicationMenu(id)) { - containerItems.addElement(item); - } - } - } - MenuItem[] containerMenu = new MenuItem[containerItems.size()]; - containerItems.copyInto(containerMenu); - frame.setFileMenus(fileMenu); - frame.setContainerMenus(containerMenu); - frame.setWindowMenus(windowMenu); - } + for (int i = 0; i < menuBar.getItemCount(); i++) { + MenuItem item = menuBar.getItem(i); + String id = ""; //$NON-NLS-1$ + if (item.getData() instanceof IMenuManager) + id = ((IMenuManager) item.getData()).getId(); + if (id.equals(IWorkbenchActionConstants.M_FILE)) + fileMenu[0] = item; + else if (id.equals(IWorkbenchActionConstants.M_WINDOW)) + windowMenu[0] = item; + else { + if (window.isApplicationMenu(id)) { + containerItems.addElement(item); + } + } + } + MenuItem[] containerMenu = new MenuItem[containerItems.size()]; + containerItems.copyInto(containerMenu); + frame.setFileMenus(fileMenu); + frame.setContainerMenus(containerMenu); + frame.setWindowMenus(windowMenu); + } - /** - * Return whether the comparison document is being shown in-place or in - * a separate window. - * @return whether the comparison document is being shown in-place or in - * a separate window - */ + /** + * Return whether the comparison document is being shown in-place or in + * a separate window. + * @return whether the comparison document is being shown in-place or in + * a separate window + */ public boolean isInplace() { return inplace; } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java index ae4cb4e6e..d8c155ac8 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java @@ -376,14 +376,14 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit /* * FIXME! - */ + */ protected void setMessage(String message) { fMessage= message; } /* * FIXME! - */ + */ public String getMessage() { return fMessage; } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java index 6fa811254..18cdf0fc0 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java @@ -94,10 +94,10 @@ public final class CompareUI { /** * Name of the title property of a compare viewer. - * If a property with this name is set - * on the top level SWT control of a viewer, it is used as a title in the pane's - * title bar. - */ + * If a property with this name is set + * on the top level SWT control of a viewer, it is used as a title in the pane's + * title bar. + */ public static final String COMPARE_VIEWER_TITLE= "org.eclipse.compare.CompareUI.CompareViewerTitle"; //$NON-NLS-1$ private CompareUI() { @@ -283,7 +283,7 @@ public final class CompareUI { */ @Deprecated public static IStreamMerger createStreamMerger(IContentType type) { - return CompareUIPlugin.getDefault().createStreamMerger(type); + return CompareUIPlugin.getDefault().createStreamMerger(type); } /** @@ -298,7 +298,7 @@ public final class CompareUI { */ @Deprecated public static IStreamMerger createStreamMerger(String type) { - return CompareUIPlugin.getDefault().createStreamMerger(type); + return CompareUIPlugin.getDefault().createStreamMerger(type); } /** diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java index 6f2ddc727..db2e4fa38 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java @@ -204,7 +204,7 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane { @Override public void setSelection(ISelection s) { if (fViewer != null) - fViewer.setSelection(s); + fViewer.setSelection(s); } private boolean hasFocus2() { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java index 78ff969d4..3d856f9f0 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java @@ -603,20 +603,20 @@ public class EditionSelectionDialog extends ResizableDialog { return result.toArray(new ITypedElement[result.size()]); } - /** - * Returns a label for identifying the target side of a compare viewer. - * This implementation extracts the value for the key "targetLabel" from the resource bundle - * and passes it as the format argument to <code>MessageFormat.format</code>. - * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) - * is the name of the given input element. + /** + * Returns a label for identifying the target side of a compare viewer. + * This implementation extracts the value for the key "targetLabel" from the resource bundle + * and passes it as the format argument to <code>MessageFormat.format</code>. + * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) + * is the name of the given input element. * <p> * Subclasses may override to create their own label. * </p> - * - * @param target the target element for which a label must be returned - * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given target; otherwise the same as target - * @return a label the target side of a compare viewer - */ + * + * @param target the target element for which a label must be returned + * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given target; otherwise the same as target + * @return a label the target side of a compare viewer + */ protected String getTargetLabel(ITypedElement target, ITypedElement item) { String format= null; if (target instanceof ResourceNode) @@ -636,7 +636,7 @@ public class EditionSelectionDialog extends ResizableDialog { return string; } - private boolean hasDoubleQuotes(String string) { + private boolean hasDoubleQuotes(String string) { return string.indexOf("''") != -1; //$NON-NLS-1$ } @@ -645,19 +645,19 @@ public class EditionSelectionDialog extends ResizableDialog { } /** - * Returns a label for identifying the edition side of a compare viewer. - * This implementation extracts the value for the key "editionLabel" from the resource bundle - * and passes it as the format argument to <code>MessageFormat.format</code>. - * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) - * is the formatted modification date of the given input element. - * <p> + * Returns a label for identifying the edition side of a compare viewer. + * This implementation extracts the value for the key "editionLabel" from the resource bundle + * and passes it as the format argument to <code>MessageFormat.format</code>. + * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) + * is the formatted modification date of the given input element. + * <p> * Subclasses may override to create their own label. * </p> * * @param selectedEdition the selected edition for which a label must be returned - * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition - * @return a label for the edition side of a compare viewer - */ + * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition + * @return a label for the edition side of a compare viewer + */ protected String getEditionLabel(ITypedElement selectedEdition, ITypedElement item) { String format= null; if (selectedEdition instanceof ResourceNode) @@ -679,21 +679,21 @@ public class EditionSelectionDialog extends ResizableDialog { return formatString(format, date); } - /** - * Returns a label for identifying a node in the edition tree viewer. - * This implementation extracts the value for the key "workspaceTreeFormat" or - * "treeFormat" (in that order) from the resource bundle - * and passes it as the format argument to <code>MessageFormat.format</code>. - * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) - * is the formatted modification date of the given input element. - * <p> + /** + * Returns a label for identifying a node in the edition tree viewer. + * This implementation extracts the value for the key "workspaceTreeFormat" or + * "treeFormat" (in that order) from the resource bundle + * and passes it as the format argument to <code>MessageFormat.format</code>. + * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) + * is the formatted modification date of the given input element. + * <p> * Subclasses may override to create their own label. * </p> * * @param edition the edition for which a label must be returned - * @param item if a path has been specified in <code>edition</code> a sub element of the given edition; otherwise the same as edition - * @param date this date will be returned as part of the formatted string - * @return a label of a node in the edition tree viewer + * @param item if a path has been specified in <code>edition</code> a sub element of the given edition; otherwise the same as edition + * @param date this date will be returned as part of the formatted string + * @return a label of a node in the edition tree viewer * @since 2.0 */ protected String getShortEditionLabel(ITypedElement edition, ITypedElement item, Date date) { @@ -709,21 +709,21 @@ public class EditionSelectionDialog extends ResizableDialog { return formatString(format, ds); } - /** - * Returns an image for identifying the edition side of a compare viewer. - * This implementation extracts the value for the key "editionLabel" from the resource bundle - * and passes it as the format argument to <code>MessageFormat.format</code>. - * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) - * is the formatted modification date of the given input element. - * <p> + /** + * Returns an image for identifying the edition side of a compare viewer. + * This implementation extracts the value for the key "editionLabel" from the resource bundle + * and passes it as the format argument to <code>MessageFormat.format</code>. + * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) + * is the formatted modification date of the given input element. + * <p> * Subclasses may override to create their own label. * </p> * * @param selectedEdition the selected edition for which a label must be returned - * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition - * @return a label the edition side of a compare viewer - * @since 2.0 - */ + * @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition + * @return a label the edition side of a compare viewer + * @since 2.0 + */ protected Image getEditionImage(ITypedElement selectedEdition, ITypedElement item) { if (selectedEdition instanceof ResourceNode) return selectedEdition.getImage(); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java index c799c3bac..57e685093 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java @@ -78,19 +78,19 @@ public class HistoryItem implements IEncodedStreamContentAccessor, ITypedElement @Override public String getCharset() throws CoreException { - String charset= fFileState.getCharset(); - if (charset == null) { - IResource resource= getResource(); - if (resource instanceof IEncodedStorage) - charset= ((IEncodedStorage)resource).getCharset(); - } + String charset= fFileState.getCharset(); + if (charset == null) { + IResource resource= getResource(); + if (resource instanceof IEncodedStorage) + charset= ((IEncodedStorage)resource).getCharset(); + } return charset; } @Override public IResource getResource() { - IPath fullPath= fFileState.getFullPath(); - return ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); + IPath fullPath= fFileState.getFullPath(); + return ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java index bc19f6202..6c2c622ea 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamMerger.java @@ -32,42 +32,42 @@ import org.eclipse.core.runtime.IStatus; @Deprecated public interface IStreamMerger { - /** - * Indicates the successful completion of the merge operation (value <code>IStatus.OK</code>) - */ - public static final int OK= IStatus.OK; + /** + * Indicates the successful completion of the merge operation (value <code>IStatus.OK</code>) + */ + public static final int OK= IStatus.OK; - /** - * Indicates that a change conflict prevented the merge from successful completion (value <code>1</code>) - */ - public static final int CONFLICT= 1; + /** + * Indicates that a change conflict prevented the merge from successful completion (value <code>1</code>) + */ + public static final int CONFLICT= 1; - /** - * Status code describing an internal error (value <code>2</code>) - */ - public static final int INTERNAL_ERROR= 2; + /** + * Status code describing an internal error (value <code>2</code>) + */ + public static final int INTERNAL_ERROR= 2; - /** - * Performs a merge operation on the given input streams and writes the merge result to the output stream. - * On success a status <code>IStatus.OK</code> is returned, on error a status <code>IStatus.ERROR</code>. - * If the merge operation cannot deal with conflicts, the code of the error status has the value <code>IStreamMerger.CONFLICT</code>. - * For text oriented mergers the encoding for the input and output streams is honored. - * It is the responsibility of callers to close input and output streams. - * - * @param output the byte stream to which the merge result is written; the merger will not close the stream - * @param outputEncoding the encoding to use when writing to the output stream - * @param ancestor the byte stream from which the common ancestor is read - * @param ancestorEncoding the encoding of the ancestor input byte stream - * @param target the byte stream containing the target of the merge - * @param targetEncoding the encoding of the target input byte stream - * @param other the byte stream containing the target of the merge - * @param otherEncoding the encoding of the other input byte stream - * @param monitor reports progress of the merge operation - * @return returns the completion status of the operation - */ + /** + * Performs a merge operation on the given input streams and writes the merge result to the output stream. + * On success a status <code>IStatus.OK</code> is returned, on error a status <code>IStatus.ERROR</code>. + * If the merge operation cannot deal with conflicts, the code of the error status has the value <code>IStreamMerger.CONFLICT</code>. + * For text oriented mergers the encoding for the input and output streams is honored. + * It is the responsibility of callers to close input and output streams. + * + * @param output the byte stream to which the merge result is written; the merger will not close the stream + * @param outputEncoding the encoding to use when writing to the output stream + * @param ancestor the byte stream from which the common ancestor is read + * @param ancestorEncoding the encoding of the ancestor input byte stream + * @param target the byte stream containing the target of the merge + * @param targetEncoding the encoding of the target input byte stream + * @param other the byte stream containing the target of the merge + * @param otherEncoding the encoding of the other input byte stream + * @param monitor reports progress of the merge operation + * @return returns the completion status of the operation + */ IStatus merge(OutputStream output, String outputEncoding, InputStream ancestor, String ancestorEncoding, InputStream target, String targetEncoding, InputStream other, String otherEncoding, - IProgressMonitor monitor); + IProgressMonitor monitor); } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java index 018ed5aa1..1b3ff0866 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java @@ -121,7 +121,7 @@ public class ResourceNode extends BufferedContent /** * Returns the hash code of the name. - * @return a hash code value for this object. + * @return a hash code value for this object. */ @Override public int hashCode() { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java index 442f31092..826bd9df2 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java @@ -175,16 +175,16 @@ public class ZipFileStructureCreator implements IStructureCreator { } void appendBytes(byte[] buffer, int length) { - if (length > 0) { + if (length > 0) { int oldLen= 0; if (fContents != null) oldLen= fContents.length; byte[] newBuf= new byte[oldLen + length]; if (oldLen > 0) - System.arraycopy(fContents, 0, newBuf, 0, oldLen); - System.arraycopy(buffer, 0, newBuf, oldLen, length); - fContents= newBuf; - } + System.arraycopy(fContents, 0, newBuf, 0, oldLen); + System.arraycopy(buffer, 0, newBuf, oldLen, length); + fContents= newBuf; + } } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java index a0b270840..db23be7a3 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java @@ -1068,7 +1068,7 @@ public abstract class ContentMergeViewer extends ContentViewer } super.handleDispose(event); - } + } /** * Updates the enabled state of the toolbar items. diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java index 6135f5ba7..7c6f260f8 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java @@ -505,7 +505,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { return null; } - private Diff findDiff(Position p, boolean left) { + private Diff findDiff(Position p, boolean left) { for (Iterator<?> iterator = fMerger.rangesIterator(); iterator.hasNext();) { Diff diff = (Diff) iterator.next(); Position diffPos; @@ -1650,11 +1650,11 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { } private ChainedPreferenceStore createChainedPreferenceStore() { - List<IPreferenceStore> stores= new ArrayList<>(2); + List<IPreferenceStore> stores= new ArrayList<>(2); stores.add(getCompareConfiguration().getPreferenceStore()); stores.add(EditorsUI.getPreferenceStore()); return new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()])); - } + } /** * Creates a color from the information stored in the given preference store. @@ -2012,7 +2012,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { } // don't add anything here, disposing colors should be done last super.handleDispose(event); - } + } private void disconnect(ContributorInfo legInfo) { if (legInfo != null) @@ -2102,16 +2102,16 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { }); fRight.getSourceViewer().addTextPresentationListener(new ChangeHighlighter(fRight)); - IWorkbenchPart part = getCompareConfiguration().getContainer().getWorkbenchPart(); - // part is not available for contexts different than editor - if (part != null) { - ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); - if (selectionProvider instanceof CompareEditorSelectionProvider) { - CompareEditorSelectionProvider cesp = (CompareEditorSelectionProvider) selectionProvider; - SourceViewer focusSourceViewer = fFocusPart == null ? null : fFocusPart.getSourceViewer(); - cesp.setViewers(new SourceViewer[] { fLeft.getSourceViewer(), fRight.getSourceViewer(), fAncestor.getSourceViewer() }, focusSourceViewer); - } - } + IWorkbenchPart part = getCompareConfiguration().getContainer().getWorkbenchPart(); + // part is not available for contexts different than editor + if (part != null) { + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider instanceof CompareEditorSelectionProvider) { + CompareEditorSelectionProvider cesp = (CompareEditorSelectionProvider) selectionProvider; + SourceViewer focusSourceViewer = fFocusPart == null ? null : fFocusPart.getSourceViewer(); + cesp.setViewers(new SourceViewer[] { fLeft.getSourceViewer(), fRight.getSourceViewer(), fAncestor.getSourceViewer() }, focusSourceViewer); + } + } hsynchViewport(fAncestor.getSourceViewer(), fLeft.getSourceViewer(), fRight.getSourceViewer()); hsynchViewport(fLeft.getSourceViewer(), fAncestor.getSourceViewer(), fRight.getSourceViewer()); @@ -2197,13 +2197,13 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { sb1.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (fSynchronizedScrolling) { + if (fSynchronizedScrolling) { int v= sb1.getSelection(); if (st2.isVisible()) st2.setHorizontalPixel(v); if (st3.isVisible()) st3.setHorizontalPixel(v); - } + } } }); } @@ -2331,7 +2331,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { for (Iterator<?> iterator = fMerger.rangesIterator(); iterator.hasNext();) { Diff diff = (Diff) iterator.next(); int h= fSynchronizedScrolling ? diff.getMaxDiffHeight() - : diff.getRightHeight(); + : diff.getRightHeight(); if (fMerger.useChange(diff)) { @@ -2928,20 +2928,20 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { if (input instanceof IDiffElement) { IDiffContainer parent= ((IDiffElement) input).getParent(); if (parent instanceof ICompareInput) { - ICompareInput ci= (ICompareInput) parent; - - if (ci.getAncestor() instanceof IDocumentRange - || ci.getLeft() instanceof IDocumentRange - || ci.getRight() instanceof IDocumentRange) { - if (left instanceof IDocumentRange) - leftRange= ((IDocumentRange) left).getRange(); - if (right instanceof IDocumentRange) - rightRange= ((IDocumentRange) right).getRange(); - - ancestor= ci.getAncestor(); - left= getCompareConfiguration().isMirrored() ? ci.getRight() : ci.getLeft(); - right= getCompareConfiguration().isMirrored() ? ci.getLeft() : ci.getRight(); - } + ICompareInput ci= (ICompareInput) parent; + + if (ci.getAncestor() instanceof IDocumentRange + || ci.getLeft() instanceof IDocumentRange + || ci.getRight() instanceof IDocumentRange) { + if (left instanceof IDocumentRange) + leftRange= ((IDocumentRange) left).getRange(); + if (right instanceof IDocumentRange) + rightRange= ((IDocumentRange) right).getRange(); + + ancestor= ci.getAncestor(); + left= getCompareConfiguration().isMirrored() ? ci.getRight() : ci.getLeft(); + right= getCompareConfiguration().isMirrored() ? ci.getLeft() : ci.getRight(); + } } } } @@ -3024,9 +3024,9 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { Diff selectDiff= null; if (FIX_47640) { if (leftRange != null) - selectDiff= fMerger.findDiff(LEFT_CONTRIBUTOR, leftRange); + selectDiff= fMerger.findDiff(LEFT_CONTRIBUTOR, leftRange); else if (rightRange != null) - selectDiff= fMerger.findDiff(RIGHT_CONTRIBUTOR, rightRange); + selectDiff= fMerger.findDiff(RIGHT_CONTRIBUTOR, rightRange); } if (selectDiff != null) setCurrentDiff(selectDiff, true); @@ -3386,9 +3386,9 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { } @Override - protected final void handleResizeLeftRight(int x, int y, int width1, int centerWidth, int width2, int height) { - if (fBirdsEyeCanvas != null) - width2-= BIRDS_EYE_VIEW_WIDTH; + protected final void handleResizeLeftRight(int x, int y, int width1, int centerWidth, int width2, int height) { + if (fBirdsEyeCanvas != null) + width2-= BIRDS_EYE_VIEW_WIDTH; Rectangle trim= fLeft.getSourceViewer().getTextWidget().computeTrim(0, 0, 0, 0); int scrollbarHeight= trim.height + trim.x; @@ -3422,7 +3422,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { int scrollbarWidth= 0; if (fSynchronizedScrolling && fScrollCanvas != null) { trim= fLeft.getSourceViewer().getTextWidget().computeTrim(0, 0, 0, 0); - // one pixel was cut off + // one pixel was cut off scrollbarWidth= trim.width + 2*trim.x+1; } int rightTextWidth= width2-scrollbarWidth; @@ -3440,18 +3440,18 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable { fScrollCanvas.setBounds(x, y, scrollbarWidth, height-scrollbarHeight); } - if (fBirdsEyeCanvas != null) { - int verticalScrollbarButtonHeight= scrollbarWidth; + if (fBirdsEyeCanvas != null) { + int verticalScrollbarButtonHeight= scrollbarWidth; int horizontalScrollbarButtonHeight= scrollbarHeight; if (fIsMac) { verticalScrollbarButtonHeight+= 2; horizontalScrollbarButtonHeight= 18; } - if (fSummaryHeader != null) + if (fSummaryHeader != null) fSummaryHeader.setBounds(x+scrollbarWidth, y, BIRDS_EYE_VIEW_WIDTH, verticalScrollbarButtonHeight); - y+= verticalScrollbarButtonHeight; - fBirdsEyeCanvas.setBounds(x+scrollbarWidth, y, BIRDS_EYE_VIEW_WIDTH, height-(2*verticalScrollbarButtonHeight+horizontalScrollbarButtonHeight)); - } + y+= verticalScrollbarButtonHeight; + fBirdsEyeCanvas.setBounds(x+scrollbarWidth, y, BIRDS_EYE_VIEW_WIDTH, height-(2*verticalScrollbarButtonHeight+horizontalScrollbarButtonHeight)); + } // doesn't work since TextEditors don't have their correct size yet. updateVScrollBar(); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedResourceNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedResourceNode.java index ca80919c0..815b44c1a 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedResourceNode.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedResourceNode.java @@ -45,11 +45,11 @@ public class BufferedResourceNode extends ResourceNode { super(resource); } - /* - * Returns <code>true</code> if buffer contains uncommitted changes. - */ + /* + * Returns <code>true</code> if buffer contains uncommitted changes. + */ public boolean isDirty() { - return fDirty; + return fDirty; } @Override diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java index 07af66f1c..2d5d8c9f8 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java @@ -240,20 +240,20 @@ public class CompareEditor extends EditorPart ErrorDialog.openError(getSite().getShell(), title, msg, s); return; } - doSetInput(input); - // Need to refresh the contributor (see #67888) - refreshActionBarsContributor(); + doSetInput(input); + // Need to refresh the contributor (see #67888) + refreshActionBarsContributor(); } public void refreshActionBarsContributor() { IEditorSite editorSite= getEditorSite(); - if (editorSite != null) { - IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor(); - if (actionBarContributor != null) { - actionBarContributor.setActiveEditor(null); - actionBarContributor.setActiveEditor(this); - } - } + if (editorSite != null) { + IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor(); + if (actionBarContributor != null) { + actionBarContributor.setActiveEditor(null); + actionBarContributor.setActiveEditor(this); + } + } } private void doSetInput(IEditorInput input) { @@ -299,12 +299,12 @@ public class CompareEditor extends EditorPart initializeInBackground(cei, hadPreviousInput); } - firePropertyChange(IWorkbenchPartConstants.PROP_INPUT); + firePropertyChange(IWorkbenchPartConstants.PROP_INPUT); - // We only need to notify of new Saveables if we are changing inputs - if (hadPreviousInput && hasResult) { - registerSaveable(); - } + // We only need to notify of new Saveables if we are changing inputs + if (hadPreviousInput && hasResult) { + registerSaveable(); + } } private void registerSaveable() { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditorSelectionProvider.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditorSelectionProvider.java index cfa829fbe..ea1004aa7 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditorSelectionProvider.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditorSelectionProvider.java @@ -45,17 +45,17 @@ public class CompareEditorSelectionProvider implements IPostSelectionProvider { doSelectionChanged(event); } - @Override + @Override public void focusGained(FocusEvent e) { - // expecting a StyledText widget here - doFocusChanged(e.widget); - } + // expecting a StyledText widget here + doFocusChanged(e.widget); + } - @Override + @Override public void focusLost(FocusEvent e) { - // do not reset due to focus behavior on GTK - //fViewerInFocus= null; - } + // do not reset due to focus behavior on GTK + //fViewerInFocus= null; + } } private class InternalPostSelectionListener implements ISelectionChangedListener { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java index 4d72bd60e..ac215b261 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java @@ -369,8 +369,8 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP CompareMessages.ComparePreferencePage_0, 1, new String[][] { new String[] { CompareMessages.ComparePreferencePage_1, ICompareUIConstants.PREF_VALUE_PROMPT }, - new String[] { CompareMessages.ComparePreferencePage_2, ICompareUIConstants.PREF_VALUE_LOOP }, - new String[] { CompareMessages.ComparePreferencePage_3, ICompareUIConstants.PREF_VALUE_NEXT }, + new String[] { CompareMessages.ComparePreferencePage_2, ICompareUIConstants.PREF_VALUE_LOOP }, + new String[] { CompareMessages.ComparePreferencePage_3, ICompareUIConstants.PREF_VALUE_NEXT }, new String[] { CompareMessages.ComparePreferencePage_4, ICompareUIConstants.PREF_VALUE_DO_NOTHING} }, radioGroup, true); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java index 21f2399fe..45f71276b 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java @@ -106,63 +106,63 @@ import org.osgi.framework.ServiceRegistration; */ public final class CompareUIPlugin extends AbstractUIPlugin { - static class CompareRegistry<T> { - private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ - private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ - private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$ - - private HashMap<String, T> fIdMap; // maps ids to data - private HashMap<String, List<T>> fExtensionMap; // multimap: maps extensions to list of data - private HashMap<IContentType, List<T>> fContentTypeBindings; // multimap: maps content type bindings to list of data - - - void register(IConfigurationElement element, T data) { - String id= element.getAttribute(ID_ATTRIBUTE); - if (id != null) { - if (fIdMap == null) - fIdMap= new HashMap<>(); - fIdMap.put(id, data); - } - - String types= element.getAttribute(EXTENSIONS_ATTRIBUTE); - if (types != null) { - if (fExtensionMap == null) - fExtensionMap= new HashMap<>(); - StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreElements()) { - String extension= tokenizer.nextToken().trim(); - List<T> l = fExtensionMap.get(normalizeCase(extension)); + static class CompareRegistry<T> { + private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ + private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ + private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$ + + private HashMap<String, T> fIdMap; // maps ids to data + private HashMap<String, List<T>> fExtensionMap; // multimap: maps extensions to list of data + private HashMap<IContentType, List<T>> fContentTypeBindings; // multimap: maps content type bindings to list of data + + + void register(IConfigurationElement element, T data) { + String id= element.getAttribute(ID_ATTRIBUTE); + if (id != null) { + if (fIdMap == null) + fIdMap= new HashMap<>(); + fIdMap.put(id, data); + } + + String types= element.getAttribute(EXTENSIONS_ATTRIBUTE); + if (types != null) { + if (fExtensionMap == null) + fExtensionMap= new HashMap<>(); + StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$ + while (tokenizer.hasMoreElements()) { + String extension= tokenizer.nextToken().trim(); + List<T> l = fExtensionMap.get(normalizeCase(extension)); if (l == null) fExtensionMap.put(normalizeCase(extension), l = new ArrayList<>()); l.add(data); - } - } - } - - void createBinding(IConfigurationElement element, String idAttributeName) { - String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE); - String id= element.getAttribute(idAttributeName); - if (id == null) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$ - if (type != null && id != null && fIdMap != null) { - T o= fIdMap.get(id); - if (o != null) { - IContentType ct= fgContentTypeManager.getContentType(type); - if (ct != null) { - if (fContentTypeBindings == null) - fContentTypeBindings= new HashMap<>(); - List<T> l = fContentTypeBindings.get(ct); - if (l == null) + } + } + } + + void createBinding(IConfigurationElement element, String idAttributeName) { + String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE); + String id= element.getAttribute(idAttributeName); + if (id == null) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$ + if (type != null && id != null && fIdMap != null) { + T o= fIdMap.get(id); + if (o != null) { + IContentType ct= fgContentTypeManager.getContentType(type); + if (ct != null) { + if (fContentTypeBindings == null) + fContentTypeBindings= new HashMap<>(); + List<T> l = fContentTypeBindings.get(ct); + if (l == null) fContentTypeBindings.put(ct, l = new ArrayList<>()); - l.add(o); - } else { - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$ - } - } else { - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$ - } - } - } + l.add(o); + } else { + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$ + } + } else { + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$ + } + } + } T search(IContentType type) { List<T> list = searchAll(type); @@ -190,7 +190,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin { return fExtensionMap.get(normalizeCase(extension)); return null; } - } + } /** Status code describing an internal error */ public static final int INTERNAL_ERROR= 1; @@ -222,7 +222,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin { private static final String CONTENT_TYPE_BINDING= "contentTypeBinding"; //$NON-NLS-1$ - private static final String COMPARE_EDITOR= PLUGIN_ID + ".CompareEditor"; //$NON-NLS-1$ + private static final String COMPARE_EDITOR= PLUGIN_ID + ".CompareEditor"; //$NON-NLS-1$ private static final String STRUCTUREVIEWER_ALIASES_PREFERENCE_NAME= "StructureViewerAliases"; //$NON-NLS-1$ @@ -362,65 +362,65 @@ public final class CompareUIPlugin extends AbstractUIPlugin { // collect all IStreamMergers IConfigurationElement[] elements= registry.getConfigurationElementsFor(PLUGIN_ID, STREAM_MERGER_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (STREAM_MERGER.equals(element.getName())) + IConfigurationElement element= elements[i]; + if (STREAM_MERGER.equals(element.getName())) fStreamMergers.register(element, new StreamMergerDescriptor(element)); } for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (CONTENT_TYPE_BINDING.equals(element.getName())) - fStreamMergers.createBinding(element, STREAM_MERGER_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (CONTENT_TYPE_BINDING.equals(element.getName())) + fStreamMergers.createBinding(element, STREAM_MERGER_ID_ATTRIBUTE); } // collect all IStructureCreators elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_CREATOR_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - String name= element.getName(); - if (!CONTENT_TYPE_BINDING.equals(name)) { - if (!STRUCTURE_CREATOR.equals(name)) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, STRUCTURE_CREATOR)); //$NON-NLS-1$ - fStructureCreators.register(element, new StructureCreatorDescriptor(element)); - } + IConfigurationElement element= elements[i]; + String name= element.getName(); + if (!CONTENT_TYPE_BINDING.equals(name)) { + if (!STRUCTURE_CREATOR.equals(name)) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, STRUCTURE_CREATOR)); //$NON-NLS-1$ + fStructureCreators.register(element, new StructureCreatorDescriptor(element)); + } } for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (CONTENT_TYPE_BINDING.equals(element.getName())) - fStructureCreators.createBinding(element, STRUCTURE_CREATOR_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (CONTENT_TYPE_BINDING.equals(element.getName())) + fStructureCreators.createBinding(element, STRUCTURE_CREATOR_ID_ATTRIBUTE); } // collect all viewers which define the structure merge viewer extension point elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_MERGE_VIEWER_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - String name= element.getName(); - if (!CONTENT_TYPE_BINDING.equals(name)) { - if (!VIEWER_TAG.equals(name)) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ - fStructureMergeViewers.register(element, new ViewerDescriptor(element)); - } + IConfigurationElement element= elements[i]; + String name= element.getName(); + if (!CONTENT_TYPE_BINDING.equals(name)) { + if (!VIEWER_TAG.equals(name)) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ + fStructureMergeViewers.register(element, new ViewerDescriptor(element)); + } } for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (CONTENT_TYPE_BINDING.equals(element.getName())) - fStructureMergeViewers.createBinding(element, STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (CONTENT_TYPE_BINDING.equals(element.getName())) + fStructureMergeViewers.createBinding(element, STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE); } // collect all viewers which define the content merge viewer extension point elements= registry.getConfigurationElementsFor(PLUGIN_ID, CONTENT_MERGE_VIEWER_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - String name= element.getName(); - if (!CONTENT_TYPE_BINDING.equals(name)) { - if (!VIEWER_TAG.equals(name)) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ - fContentMergeViewers.register(element, new ViewerDescriptor(element)); - } + IConfigurationElement element= elements[i]; + String name= element.getName(); + if (!CONTENT_TYPE_BINDING.equals(name)) { + if (!VIEWER_TAG.equals(name)) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ + fContentMergeViewers.register(element, new ViewerDescriptor(element)); + } } for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (CONTENT_TYPE_BINDING.equals(element.getName())) - fContentMergeViewers.createBinding(element, CONTENT_MERGE_VIEWER_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (CONTENT_TYPE_BINDING.equals(element.getName())) + fContentMergeViewers.createBinding(element, CONTENT_MERGE_VIEWER_ID_ATTRIBUTE); } // collect all extensions that define the compare filter extension point @@ -446,18 +446,18 @@ public final class CompareUIPlugin extends AbstractUIPlugin { // collect all viewers which define the content viewer extension point elements= registry.getConfigurationElementsFor(PLUGIN_ID, CONTENT_VIEWER_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - String name= element.getName(); - if (!CONTENT_TYPE_BINDING.equals(name)) { - if (!VIEWER_TAG.equals(name)) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ - fContentViewers.register(element, new ViewerDescriptor(element)); - } + IConfigurationElement element= elements[i]; + String name= element.getName(); + if (!CONTENT_TYPE_BINDING.equals(name)) { + if (!VIEWER_TAG.equals(name)) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$ + fContentViewers.register(element, new ViewerDescriptor(element)); + } } for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (CONTENT_TYPE_BINDING.equals(element.getName())) - fContentViewers.createBinding(element, CONTENT_VIEWER_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (CONTENT_TYPE_BINDING.equals(element.getName())) + fContentViewers.createBinding(element, CONTENT_VIEWER_ID_ATTRIBUTE); } } @@ -877,7 +877,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin { initializeRegistries(); StructureCreatorDescriptor scc= fStructureCreators.search(ctype); // search for content type if (scc == null && type != null) - scc= getStructureCreator(type); // search for old-style type scheme + scc= getStructureCreator(type); // search for old-style type scheme if (scc != null) { IStructureCreator sc= scc.createStructureCreator(); if (sc != null) { @@ -998,7 +998,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin { if (in instanceof ITypedElement) { ITypedElement tin= (ITypedElement) in; - IContentType ct= getContentType(tin); + IContentType ct= getContentType(tin); if (ct != null) { initializeRegistries(); List<ViewerDescriptor> list = fContentViewers.searchAll(ct); @@ -1105,9 +1105,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin { } private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) { - if (descriptor instanceof IViewerDescriptor) + if (descriptor instanceof IViewerDescriptor) return ((IViewerDescriptor)descriptor).createViewer(oldViewer, parent, cc); - return null; + return null; } private static String[] getTypes(ICompareInput input) { @@ -1119,17 +1119,17 @@ public final class CompareUIPlugin extends AbstractUIPlugin { if (ancestor != null) { String type= ancestor.getType(); if (type != null) - tmp.add(normalizeCase(type)); + tmp.add(normalizeCase(type)); } if (left != null) { String type= left.getType(); if (type != null) - tmp.add(normalizeCase(type)); + tmp.add(normalizeCase(type)); } if (right != null) { String type= right.getType(); if (type != null) - tmp.add(normalizeCase(type)); + tmp.add(normalizeCase(type)); } return tmp.toArray(new String[tmp.size()]); } @@ -1376,7 +1376,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin { //---- filters public boolean filter(String name, boolean isFolder, boolean isArchive) { - if (fFilter == null) { + if (fFilter == null) { fFilter= new CompareResourceFilter(); final IPreferenceStore ps= getPreferenceStore(); fFilter.setFilters(ps.getString(ComparePreferencePage.PATH_FILTER)); @@ -1385,8 +1385,8 @@ public final class CompareUIPlugin extends AbstractUIPlugin { fFilter.setFilters(ps.getString(ComparePreferencePage.PATH_FILTER)); }; ps.addPropertyChangeListener(fPropertyChangeListener); - } - return fFilter.filter(name, isFolder, isArchive); + } + return fFilter.filter(name, isFolder, isArchive); } private void internalOpenDialog(final CompareEditorInput input) { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DiffImageDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DiffImageDescriptor.java index fabcc9c81..f4d70a4e9 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DiffImageDescriptor.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DiffImageDescriptor.java @@ -133,7 +133,7 @@ public class DiffImageDescriptor extends CompositeImageDescriptor { /* && i1.palette == i2.palette */ && i1.transparentPixel == i2.transparentPixel && i1.maskPad == i2.maskPad - && i1.alpha == i2.alpha + && i1.alpha == i2.alpha && i1.type == i2.type && i1.x == i2.x && i1.y == i2.y && i1.disposalMethod == i2.disposalMethod && i1.delayTime == i2.delayTime && equals(i1.data,i2.data) && equals(i1.maskData, i2.maskData) diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java index fe2ebb007..5eb99ee55 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java @@ -251,7 +251,7 @@ public class DocLineComparator implements ITokenComparator { * Extract a single line from the underlying document. * * @param line the number of the line to extract - * @param whether to include the line separator + * @param whether to include the line separator * @return the contents of the line as a String */ private String extract(int line, boolean includeSeparator) { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java index e004e2493..14b092e4c 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java @@ -307,7 +307,7 @@ public class MergeSourceViewer implements ISelectionChangedListener, MergeSourceViewer.this.getSourceViewer().setSelectedRange(selectionStart, selectionLength); - markInNavigationHistory(); + markInNavigationHistory(); } widget.setRedraw(true); } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java index 49427d2ce..374523a14 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java @@ -504,44 +504,44 @@ class ResourceCompareInput extends CompareEditorInput { @Override public <T> T getAdapter(Class<T> adapter) { if (IFile.class.equals(adapter)) { - IProgressMonitor pm= new NullProgressMonitor(); + IProgressMonitor pm= new NullProgressMonitor(); // flush changes in any dirty viewer flushViewers(pm); - IFile[] files= getAdapter(IFile[].class); - if (files != null && files.length > 0) - return (T) files[0]; // can only return one: limitation on IDE.saveAllEditors; see #64617 - return null; + IFile[] files= getAdapter(IFile[].class); + if (files != null && files.length > 0) + return (T) files[0]; // can only return one: limitation on IDE.saveAllEditors; see #64617 + return null; } if (IFile[].class.equals(adapter)) { - HashSet<IFile> collector= new HashSet<>(); - collectDirtyResources(fRoot, collector); - return (T) collector.toArray(new IFile[collector.size()]); + HashSet<IFile> collector= new HashSet<>(); + collectDirtyResources(fRoot, collector); + return (T) collector.toArray(new IFile[collector.size()]); } return super.getAdapter(adapter); } private void collectDirtyResources(Object o, Set<IFile> collector) { if (o instanceof DiffNode) { - DiffNode node= (DiffNode) o; + DiffNode node= (DiffNode) o; ITypedElement left= node.getLeft(); if (left instanceof BufferedResourceNode) { - BufferedResourceNode bn= (BufferedResourceNode) left; - if (bn.isDirty()) { - IResource resource= bn.getResource(); - if (resource instanceof IFile) - collector.add((IFile) resource); - } + BufferedResourceNode bn= (BufferedResourceNode) left; + if (bn.isDirty()) { + IResource resource= bn.getResource(); + if (resource instanceof IFile) + collector.add((IFile) resource); + } } ITypedElement right= node.getRight(); if (right instanceof BufferedResourceNode) { - BufferedResourceNode bn= (BufferedResourceNode) right; - if (bn.isDirty()) { - IResource resource= bn.getResource(); - if (resource instanceof IFile) - collector.add((IFile) resource); - } + BufferedResourceNode bn= (BufferedResourceNode) right; + if (bn.isDirty()) { + IResource resource= bn.getResource(); + if (resource instanceof IFile) + collector.add((IFile) resource); + } } IDiffElement[] children= node.getChildren(); @@ -549,7 +549,7 @@ class ResourceCompareInput extends CompareEditorInput { for (int i= 0; i < children.length; i++) { IDiffElement element= children[i]; if (element instanceof DiffNode) - collectDirtyResources(element, collector); + collectDirtyResources(element, collector); } } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java index 06ab3e188..3ae8cafdc 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java @@ -429,7 +429,7 @@ public class Utilities { for (Iterator it = validPaths.iterator(); it.hasNext();) { IPath path = (IPath) it.next(); if(path.isPrefixOf(resourceFullPath) || - resourceFullPath.isPrefixOf(path)) { + resourceFullPath.isPrefixOf(path)) { return false; } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/DocumentMerger.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/DocumentMerger.java index 12dc5d0d8..faa11e67a 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/DocumentMerger.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/DocumentMerger.java @@ -976,7 +976,7 @@ public class DocumentMerger { return region; } - public Diff findDiff(Position p, boolean left) { + public Diff findDiff(Position p, boolean left) { for (Iterator<Diff> iterator = fAllDiffs.iterator(); iterator.hasNext();) { Diff diff = iterator.next(); Position diffPos; @@ -1150,7 +1150,7 @@ public class DocumentMerger { while (e.hasNext()) { Diff diff= e.next(); int h= synchronizedScrolling ? diff.getMaxDiffHeight() - : diff.getRightHeight(); + : diff.getRightHeight(); if (useChange(diff.getKind()) && !diff.fIsWhitespace) { yy= (y*size.y)/virtualHeight; @@ -1282,7 +1282,7 @@ public class DocumentMerger { for (Iterator<Diff> iterator = changesIterator(); iterator.hasNext();) { Diff diff = iterator.next(); if (diff.isDeleted() || diff.getKind() == RangeDifference.NOCHANGE) - continue; + continue; if (diff.overlaps(contributor, rangeStart, rangeEnd, getDocument(contributor).getLength())) return diff; } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java index f7f8e399e..0b85c139e 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java @@ -26,39 +26,39 @@ import org.eclipse.compare.rangedifferencer.IRangeComparator; */ class LineComparator implements IRangeComparator { - private String[] fLines; + private String[] fLines; - public LineComparator(InputStream is, String encoding) throws IOException { + public LineComparator(InputStream is, String encoding) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding)); - String line; - ArrayList<String> ar = new ArrayList<>(); - while ((line = br.readLine()) != null) { - ar.add(line); - } - // It is the responsibility of the caller to close the stream - fLines = ar.toArray(new String[ar.size()]); - } + BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding)); + String line; + ArrayList<String> ar = new ArrayList<>(); + while ((line = br.readLine()) != null) { + ar.add(line); + } + // It is the responsibility of the caller to close the stream + fLines = ar.toArray(new String[ar.size()]); + } - String getLine(int ix) { - return fLines[ix]; - } + String getLine(int ix) { + return fLines[ix]; + } - @Override + @Override public int getRangeCount() { - return fLines.length; - } + return fLines.length; + } - @Override + @Override public boolean rangesEqual(int thisIndex, IRangeComparator other, - int otherIndex) { - String s1 = fLines[thisIndex]; - String s2 = ((LineComparator) other).fLines[otherIndex]; - return s1.equals(s2); - } + int otherIndex) { + String s1 = fLines[thisIndex]; + String s2 = ((LineComparator) other).fLines[otherIndex]; + return s1.equals(s2); + } - @Override + @Override public boolean skipRangeComparison(int length, int maxLength, IRangeComparator other) { - return false; - } + return false; + } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DecoratorOverlayIcon.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DecoratorOverlayIcon.java index 37c9b6a42..20db8e922 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DecoratorOverlayIcon.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DecoratorOverlayIcon.java @@ -27,104 +27,104 @@ import org.eclipse.swt.graphics.Point; * Copied until bug 164394 is resolved. */ class DecoratorOverlayIcon extends CompositeImageDescriptor { - // the base image - private Image base; + // the base image + private Image base; - // the overlay images - private ImageDescriptor[] overlays; + // the overlay images + private ImageDescriptor[] overlays; - // the size - private Point size; + // the size + private Point size; - /** - * OverlayIcon constructor. - * - * @param baseImage the base image - * @param overlaysArray the overlay images - * @param sizeValue the size - */ - public DecoratorOverlayIcon(Image baseImage, - ImageDescriptor[] overlaysArray, Point sizeValue) { - this.base = baseImage; - this.overlays = overlaysArray; - this.size = sizeValue; - } + /** + * OverlayIcon constructor. + * + * @param baseImage the base image + * @param overlaysArray the overlay images + * @param sizeValue the size + */ + public DecoratorOverlayIcon(Image baseImage, + ImageDescriptor[] overlaysArray, Point sizeValue) { + this.base = baseImage; + this.overlays = overlaysArray; + this.size = sizeValue; + } - /** - * Draw the overlays for the receiver. - * @param overlaysArray the overlay images - */ - protected void drawOverlays(ImageDescriptor[] overlaysArray) { + /** + * Draw the overlays for the receiver. + * @param overlaysArray the overlay images + */ + protected void drawOverlays(ImageDescriptor[] overlaysArray) { - for (int i = 0; i < overlays.length; i++) { - ImageDescriptor overlay = overlaysArray[i]; - if (overlay == null) { + for (int i = 0; i < overlays.length; i++) { + ImageDescriptor overlay = overlaysArray[i]; + if (overlay == null) { continue; } - ImageData overlayData = overlay.getImageData(); - //Use the missing descriptor if it is not there. - if (overlayData == null) { + ImageData overlayData = overlay.getImageData(); + //Use the missing descriptor if it is not there. + if (overlayData == null) { overlayData = ImageDescriptor.getMissingImageDescriptor() - .getImageData(); + .getImageData(); } - switch (i) { - case IDecoration.TOP_LEFT: - drawImage(overlayData, 0, 0); - break; - case IDecoration.TOP_RIGHT: - drawImage(overlayData, size.x - overlayData.width, 0); - break; - case IDecoration.BOTTOM_LEFT: - drawImage(overlayData, 0, size.y - overlayData.height); - break; - case IDecoration.BOTTOM_RIGHT: - drawImage(overlayData, size.x - overlayData.width, size.y - - overlayData.height); - break; - } - } - } + switch (i) { + case IDecoration.TOP_LEFT: + drawImage(overlayData, 0, 0); + break; + case IDecoration.TOP_RIGHT: + drawImage(overlayData, size.x - overlayData.width, 0); + break; + case IDecoration.BOTTOM_LEFT: + drawImage(overlayData, 0, size.y - overlayData.height); + break; + case IDecoration.BOTTOM_RIGHT: + drawImage(overlayData, size.x - overlayData.width, size.y + - overlayData.height); + break; + } + } + } - @Override + @Override public boolean equals(Object o) { - if (!(o instanceof DecoratorOverlayIcon)) { + if (!(o instanceof DecoratorOverlayIcon)) { return false; } - DecoratorOverlayIcon other = (DecoratorOverlayIcon) o; - return base.equals(other.base) - && Arrays.equals(overlays, other.overlays); - } + DecoratorOverlayIcon other = (DecoratorOverlayIcon) o; + return base.equals(other.base) + && Arrays.equals(overlays, other.overlays); + } - @Override + @Override public int hashCode() { - int code = base.hashCode(); - for (int i = 0; i < overlays.length; i++) { - if (overlays[i] != null) { + int code = base.hashCode(); + for (int i = 0; i < overlays.length; i++) { + if (overlays[i] != null) { code ^= overlays[i].hashCode(); } - } - return code; - } + } + return code; + } - @Override + @Override protected void drawCompositeImage(int width, int height) { - ImageDescriptor underlay = overlays[IDecoration.UNDERLAY]; - if (underlay != null) { + ImageDescriptor underlay = overlays[IDecoration.UNDERLAY]; + if (underlay != null) { drawImage(underlay.getImageData(), 0, 0); } - drawImage(base.getImageData(), 0, 0); - drawOverlays(overlays); - } + drawImage(base.getImageData(), 0, 0); + drawOverlays(overlays); + } - @Override + @Override protected Point getSize() { - return size; - } + return size; + } - @Override + @Override protected int getTransparentPixel() { - return base.getImageData().transparentPixel; - } + return base.getImageData().transparentPixel; + } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java index e762bf5f3..2c0e878b1 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java @@ -92,15 +92,15 @@ public class PatchTargetPage extends WizardPage { useWorkspaceAsTarget.addListener(SWT.Selection, event -> { fShowError = true; - if (useWorkspaceAsTarget.getSelection()) { - fPatchTargets.getTree().setEnabled(false); - fPatcher.setTarget(ResourcesPlugin.getWorkspace().getRoot()); - } else { - fPatchTargets.getTree().setEnabled(true); - fPatcher.setTarget(Utilities.getFirstResource(fPatchTargets.getSelection())); - } - markPreviewPageToRecalucateIfNonWorkspacePatch(); - updateWidgetEnablements(); + if (useWorkspaceAsTarget.getSelection()) { + fPatchTargets.getTree().setEnabled(false); + fPatcher.setTarget(ResourcesPlugin.getWorkspace().getRoot()); + } else { + fPatchTargets.getTree().setEnabled(true); + fPatcher.setTarget(Utilities.getFirstResource(fPatchTargets.getSelection())); + } + markPreviewPageToRecalucateIfNonWorkspacePatch(); + updateWidgetEnablements(); }); } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizardDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizardDialog.java index 211da60e4..a2a42d850 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizardDialog.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizardDialog.java @@ -32,11 +32,11 @@ public class PatchWizardDialog extends WizardDialog { @Override protected IDialogSettings getDialogBoundsSettings() { - IDialogSettings settings = CompareUIPlugin.getDefault().getDialogSettings(); - IDialogSettings section = settings.getSection(PATCH_WIZARD_SETTINGS_SECTION); - if (section == null) { - section = settings.addNewSection(PATCH_WIZARD_SETTINGS_SECTION); - } - return section; + IDialogSettings settings = CompareUIPlugin.getDefault().getDialogSettings(); + IDialogSettings section = settings.getSection(PATCH_WIZARD_SETTINGS_SECTION); + if (section == null) { + section = settings.addNewSection(PATCH_WIZARD_SETTINGS_SECTION); + } + return section; } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java index 778970a88..20f2a9314 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java @@ -49,7 +49,7 @@ class RetargetPatchElementDialog extends Dialog { private static class RetargetPatchContentProvider extends BaseWorkbenchContentProvider { private final PatchDiffNode node; public RetargetPatchContentProvider(PatchDiffNode node) { - this.node = node; + this.node = node; } @Override public Object[] getChildren(Object element) { @@ -104,8 +104,8 @@ class RetargetPatchElementDialog extends Dialog { GridLayout layout= new GridLayout(); layout.numColumns= 1; - layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); composite.setLayout(layout); final GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(data); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java index f206b7234..aed63ed10 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java @@ -370,8 +370,8 @@ public class DiffTreeViewer extends TreeViewer { /** * Overridden to avoid expanding {@code DiffNode}s that shouldn't expand. * - * @param node the node to expand - * @param level non-negative level, or {@code ALL_LEVELS} to collapse all levels of the tree + * @param node the node to expand + * @param level non-negative level, or {@code ALL_LEVELS} to collapse all levels of the tree */ @Override protected void internalExpandToLevel(Widget node, int level) { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java index 701fd922f..28fad0147 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java @@ -255,8 +255,8 @@ public class DocumentRangeNode /** * Implementation based on <code>getID</code>. - * @param other the object to compare this <code>DocumentRangeNode</code> against. - * @return <code>true</code> if the <code>DocumentRangeNodes</code>are equal; <code>false</code> otherwise. + * @param other the object to compare this <code>DocumentRangeNode</code> against. + * @return <code>true</code> if the <code>DocumentRangeNodes</code>are equal; <code>false</code> otherwise. */ @Override public boolean equals(Object other) { diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/ICompareInputChangeListener.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/ICompareInputChangeListener.java index ad5319d60..2682af036 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/ICompareInputChangeListener.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/ICompareInputChangeListener.java @@ -32,7 +32,7 @@ package org.eclipse.compare.structuremergeviewer; public interface ICompareInputChangeListener { /** * Called whenever the value (not the content) of one or more of the three sides - * of a {@link ICompareInput} has changed. + * of a {@link ICompareInput} has changed. * * @param source the {@link ICompareInput} that has changed */ diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java index e534f7cd6..af1093d5f 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java @@ -263,7 +263,7 @@ public class StructureDiffViewer extends DiffTreeViewer { return fRoot; } - /* + /* * Method declared on StructuredViewer. Overridden to create the comparable * structures from the input object and to feed them through the differencing * engine. Note: for this viewer the value from <code>getInput</code> is not diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java index d4fe64494..d47165cc2 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java @@ -57,27 +57,27 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener public static final int NEVER_SET = 2; public static int socksSystemPropertySetting; - /** - * Absolute path to the node for the cached proxy information - */ - private static final String PREFERENCES_CONTEXT = "/org.eclipse.core.net.proxy.auth"; //$NON-NLS-1$ + /** + * Absolute path to the node for the cached proxy information + */ + private static final String PREFERENCES_CONTEXT = "/org.eclipse.core.net.proxy.auth"; //$NON-NLS-1$ /* * Fields used to cache authentication information in the keyring */ - private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ - private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ - static { - String value = System.getProperty(PROP_SOCKS_SYSTEM_PROPERTY_HANDLING); - if (value == null) { - socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER; - } else if (value.equals("always")) { //$NON-NLS-1$ - socksSystemPropertySetting = ALWAYS_SET; - } else if (value.equals("never")) { //$NON-NLS-1$ - socksSystemPropertySetting = NEVER_SET; - } else { - socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER; - } - } + private static final String INFO_PROXY_USER = "user"; //$NON-NLS-1$ + private static final String INFO_PROXY_PASS = "pass"; //$NON-NLS-1$ + static { + String value = System.getProperty(PROP_SOCKS_SYSTEM_PROPERTY_HANDLING); + if (value == null) { + socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER; + } else if (value.equals("always")) { //$NON-NLS-1$ + socksSystemPropertySetting = ALWAYS_SET; + } else if (value.equals("never")) { //$NON-NLS-1$ + socksSystemPropertySetting = NEVER_SET; + } else { + socksSystemPropertySetting = ONLY_SET_FOR_1_5_OR_LATER; + } + } private String name; private boolean updatingPreferences; @@ -532,7 +532,7 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener return node; } - private void loadProxyAuth(IProxyData data) { + private void loadProxyAuth(IProxyData data) { ISecurePreferences node = getNode(); if (node == null) return; diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IHelpContextIds.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IHelpContextIds.java index cc47d2591..8012ddbfd 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IHelpContextIds.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IHelpContextIds.java @@ -15,7 +15,7 @@ package org.eclipse.jsch.internal.ui; public interface IHelpContextIds{ - public final String USER_VALIDATION_DIALOG="org.eclipse.team.cvs.ui.user_validation_dialog_contex"; //$NON-NLS-1$ - public final String KEYBOARD_INTERACTIVE_DIALOG="org.eclipse.team.cvs.ui.keyboard_interactive_dialog_context"; //$NON-NLS-1$ + public final String USER_VALIDATION_DIALOG="org.eclipse.team.cvs.ui.user_validation_dialog_contex"; //$NON-NLS-1$ + public final String KEYBOARD_INTERACTIVE_DIALOG="org.eclipse.team.cvs.ui.keyboard_interactive_dialog_context"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IUIConstants.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IUIConstants.java index b7a5a84a7..8144daf9c 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IUIConstants.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/IUIConstants.java @@ -15,15 +15,15 @@ package org.eclipse.jsch.internal.ui; public interface IUIConstants{ - public final String PREFIX=JSchUIPlugin.ID+"."; //$NON-NLS-1$ + public final String PREFIX=JSchUIPlugin.ID+"."; //$NON-NLS-1$ - // image path - public final String ICON_PATH="$nl$/icons/full/"; //$NON-NLS-1$ + // image path + public final String ICON_PATH="$nl$/icons/full/"; //$NON-NLS-1$ - // preferences - public final String PREF_FIRST_STARTUP="pref_first_startup"; //$NON-NLS-1$ + // preferences + public final String PREF_FIRST_STARTUP="pref_first_startup"; //$NON-NLS-1$ - // images - public final String IMG_KEY_LOCK="wizban/keylock.gif"; //$NON-NLS-1$ + // images + public final String IMG_KEY_LOCK="wizban/keylock.gif"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java index 8345362fb..b8eef4087 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/JSchUIPlugin.java @@ -29,95 +29,95 @@ import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; public class JSchUIPlugin extends AbstractUIPlugin{ - public static final String ID="org.eclipse.jsch.ui"; //$NON-NLS-1$ - public static final String DECORATOR_ID="org.eclipse.jsch.ui.decorator"; //$NON-NLS-1$ - - private static Hashtable<String, ImageDescriptor> imageDescriptors = new Hashtable<>(20); - /** - * The singleton plug-in instance - */ - private static JSchUIPlugin plugin; - private ServiceTracker<?, ?> tracker; - - public JSchUIPlugin(){ - super(); - plugin=this; - } - - /** - * Returns the singleton plug-in instance. - * - * @return the plugin instance - */ - public static JSchUIPlugin getPlugin(){ - return plugin; - } - - /** - * Returns the image descriptor for the given image ID. - * Returns null if there is no such image. - * @param id the id of the image descriptor - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String id){ - return imageDescriptors.get(id); - } - - /** - * Creates an image and places it in the image registry. - */ - protected void createImageDescriptor(String id){ - URL url=FileLocator.find(JSchUIPlugin.getPlugin().getBundle(), new Path( - IUIConstants.ICON_PATH+id), null); - ImageDescriptor desc=ImageDescriptor.createFromURL(url); - imageDescriptors.put(id, desc); - } - - /** - * Convenience method to get an image descriptor for an extension - * - * @param extension the extension declaring the image - * @param subdirectoryAndFilename the path to the image - * @return the image - */ - public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) { - URL fullPathString = FileLocator.find(Platform.getBundle(extension.getNamespaceIdentifier()), new Path(subdirectoryAndFilename), null); - return ImageDescriptor.createFromURL(fullPathString); - } - - /** - * Initializes the table of images used in this plugin. - */ - private void initializeImages() { - createImageDescriptor(IUIConstants.IMG_KEY_LOCK); - } - - @Override + public static final String ID="org.eclipse.jsch.ui"; //$NON-NLS-1$ + public static final String DECORATOR_ID="org.eclipse.jsch.ui.decorator"; //$NON-NLS-1$ + + private static Hashtable<String, ImageDescriptor> imageDescriptors = new Hashtable<>(20); + /** + * The singleton plug-in instance + */ + private static JSchUIPlugin plugin; + private ServiceTracker<?, ?> tracker; + + public JSchUIPlugin(){ + super(); + plugin=this; + } + + /** + * Returns the singleton plug-in instance. + * + * @return the plugin instance + */ + public static JSchUIPlugin getPlugin(){ + return plugin; + } + + /** + * Returns the image descriptor for the given image ID. + * Returns null if there is no such image. + * @param id the id of the image descriptor + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String id){ + return imageDescriptors.get(id); + } + + /** + * Creates an image and places it in the image registry. + */ + protected void createImageDescriptor(String id){ + URL url=FileLocator.find(JSchUIPlugin.getPlugin().getBundle(), new Path( + IUIConstants.ICON_PATH+id), null); + ImageDescriptor desc=ImageDescriptor.createFromURL(url); + imageDescriptors.put(id, desc); + } + + /** + * Convenience method to get an image descriptor for an extension + * + * @param extension the extension declaring the image + * @param subdirectoryAndFilename the path to the image + * @return the image + */ + public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) { + URL fullPathString = FileLocator.find(Platform.getBundle(extension.getNamespaceIdentifier()), new Path(subdirectoryAndFilename), null); + return ImageDescriptor.createFromURL(fullPathString); + } + + /** + * Initializes the table of images used in this plugin. + */ + private void initializeImages() { + createImageDescriptor(IUIConstants.IMG_KEY_LOCK); + } + + @Override public void start(BundleContext context) throws Exception { - super.start(context); + super.start(context); - initializeImages(); + initializeImages(); - IPreferenceStore store = getPreferenceStore(); - if (store.getBoolean(IUIConstants.PREF_FIRST_STARTUP)) { - store.setValue(IUIConstants.PREF_FIRST_STARTUP, false); - } + IPreferenceStore store = getPreferenceStore(); + if (store.getBoolean(IUIConstants.PREF_FIRST_STARTUP)) { + store.setValue(IUIConstants.PREF_FIRST_STARTUP, false); + } - tracker = new ServiceTracker(getBundle().getBundleContext(),IJSchService.class.getName(), null); - tracker.open(); - } + tracker = new ServiceTracker(getBundle().getBundleContext(),IJSchService.class.getName(), null); + tracker.open(); + } - @Override + @Override public void stop(BundleContext context) throws Exception{ - super.stop(context); - tracker.close(); - } + super.stop(context); + tracker.close(); + } - public IJSchService getJSchService() { - return (IJSchService)tracker.getService(); - } + public IJSchService getJSchService() { + return (IJSchService)tracker.getService(); + } - public URL getImageUrl(String relative){ - return FileLocator.find(Platform.getBundle(ID), new Path(IUIConstants.ICON_PATH + relative), null); - } + public URL getImageUrl(String relative){ + return FileLocator.find(Platform.getBundle(ID), new Path(IUIConstants.ICON_PATH + relative), null); + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/KeyboardInteractiveDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/KeyboardInteractiveDialog.java index 85f6dcd07..6b1328251 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/KeyboardInteractiveDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/KeyboardInteractiveDialog.java @@ -37,68 +37,68 @@ import org.eclipse.ui.PlatformUI; * A dialog for keyboard-interactive authentication for the ssh2 connection. */ public class KeyboardInteractiveDialog extends TrayDialog { - // widgets - private Text[] texts; - protected Image keyLockImage; - protected Button allowCachingButton; - protected Text usernameField; - - protected String userName; - protected String domain; - protected String destination; - protected String name; - protected String instruction; - protected String lang; - protected String[] prompt; - protected boolean[] echo; - private String message; - private String[] result; - protected boolean allowCaching=false; - - private boolean isPasswordAuth=false; - - - /** - * Creates a new KeyboardInteractiveDialog. - * - * @param parentShell the parent shell - * @param location - * @param destination - * @param name the name - * @param userName - * @param instruction the instruction - * @param prompt the titles for text fields - * @param echo '*' should be used or not - */ - public KeyboardInteractiveDialog(Shell parentShell, - String location, - String destination, - String name, - String userName, - String instruction, - String[] prompt, - boolean[] echo){ - super(parentShell); - this.domain=location; - this.destination=destination; - this.name=name; - this.userName=userName; - this.instruction=instruction; - this.prompt=prompt; - this.echo=echo; - if (name!=null && name.length()>0) { - this.message=NLS.bind(Messages.KeyboardInteractiveDialog_0, new String[] { destination, name }); - } else { - this.message=NLS.bind(Messages.KeyboardInteractiveDialog_1, destination); - } - - if(KeyboardInteractiveDialog.isPasswordAuth(prompt)){ - isPasswordAuth=true; - } - } + // widgets + private Text[] texts; + protected Image keyLockImage; + protected Button allowCachingButton; + protected Text usernameField; + + protected String userName; + protected String domain; + protected String destination; + protected String name; + protected String instruction; + protected String lang; + protected String[] prompt; + protected boolean[] echo; + private String message; + private String[] result; + protected boolean allowCaching=false; + + private boolean isPasswordAuth=false; + + + /** + * Creates a new KeyboardInteractiveDialog. + * + * @param parentShell the parent shell + * @param location + * @param destination + * @param name the name + * @param userName + * @param instruction the instruction + * @param prompt the titles for text fields + * @param echo '*' should be used or not + */ + public KeyboardInteractiveDialog(Shell parentShell, + String location, + String destination, + String name, + String userName, + String instruction, + String[] prompt, + boolean[] echo){ + super(parentShell); + this.domain=location; + this.destination=destination; + this.name=name; + this.userName=userName; + this.instruction=instruction; + this.prompt=prompt; + this.echo=echo; + if (name!=null && name.length()>0) { + this.message=NLS.bind(Messages.KeyboardInteractiveDialog_0, new String[] { destination, name }); + } else { + this.message=NLS.bind(Messages.KeyboardInteractiveDialog_1, destination); + } + + if(KeyboardInteractiveDialog.isPasswordAuth(prompt)){ + isPasswordAuth=true; + } + } @Override - protected void configureShell(Shell newShell) { + protected void configureShell(Shell newShell) { super.configureShell(newShell); if (isPasswordAuth) { newShell.setText(Messages.KeyboardInteractiveDialog_2); @@ -112,7 +112,7 @@ public class KeyboardInteractiveDialog extends TrayDialog { } @Override - public void create() { + public void create() { super.create(); if (isPasswordAuth && usernameField != null && userName != null) { @@ -124,7 +124,7 @@ public class KeyboardInteractiveDialog extends TrayDialog { texts[0].setFocus(); } } - @Override + @Override protected Control createDialogArea(Composite parent) { Composite top = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -212,109 +212,109 @@ protected Control createDialogArea(Composite parent) { return main; } - /** - * Creates the three widgets that represent the user name entry area. - * - * @param parent the parent of the widgets - */ - protected void createUsernameFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.KeyboardInteractiveDialog_6); - - usernameField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - usernameField.setLayoutData(data); - } - - /** + /** + * Creates the three widgets that represent the user name entry area. + * + * @param parent the parent of the widgets + */ + protected void createUsernameFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.KeyboardInteractiveDialog_6); + + usernameField=new Text(parent, SWT.BORDER); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + } + + /** * Creates the widgets that represent the entry area. * * @param parent * the parent of the widgets */ - protected void createPasswordFields(Composite parent) { - texts=new Text[prompt.length]; - - for(int i=0; i<prompt.length; i++){ - new Label(parent, SWT.NONE).setText(prompt[i]); - int flag=SWT.BORDER; - if(!echo[i]){ - flag|=SWT.PASSWORD; - } - texts[i]=new Text(parent, flag); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - texts[i].setLayoutData(data); - if(!echo[i]){ - texts[i].setEchoChar('*'); - } - } - } - /** - * Returns the entered values, or null - * if the user canceled. - * - * @return the entered values - */ - public String[] getResult() { - return result; - } - - /** - * Returns <code>true</code> if the save password checkbox was selected. - * @return <code>true</code> if the save password checkbox was selected and <code>false</code> - * otherwise. - */ - public boolean getAllowCaching(){ - return allowCaching; - } - - /** - * Notifies that the ok button of this dialog has been pressed. - * <p> - * The default implementation of this framework method sets - * this dialog's return code to <code>Window.OK</code> - * and closes the dialog. Subclasses may override. - * </p> - */ - @Override + protected void createPasswordFields(Composite parent) { + texts=new Text[prompt.length]; + + for(int i=0; i<prompt.length; i++){ + new Label(parent, SWT.NONE).setText(prompt[i]); + int flag=SWT.BORDER; + if(!echo[i]){ + flag|=SWT.PASSWORD; + } + texts[i]=new Text(parent, flag); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + texts[i].setLayoutData(data); + if(!echo[i]){ + texts[i].setEchoChar('*'); + } + } + } + /** + * Returns the entered values, or null + * if the user canceled. + * + * @return the entered values + */ + public String[] getResult() { + return result; + } + + /** + * Returns <code>true</code> if the save password checkbox was selected. + * @return <code>true</code> if the save password checkbox was selected and <code>false</code> + * otherwise. + */ + public boolean getAllowCaching(){ + return allowCaching; + } + + /** + * Notifies that the ok button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets + * this dialog's return code to <code>Window.OK</code> + * and closes the dialog. Subclasses may override. + * </p> + */ + @Override protected void okPressed() { - result=new String[prompt.length]; - for(int i=0; i<texts.length; i++){ - result[i]=texts[i].getText(); - } - super.okPressed(); - } - /** - * Notifies that the cancel button of this dialog has been pressed. - * <p> - * The default implementation of this framework method sets - * this dialog's return code to <code>Window.CANCEL</code> - * and closes the dialog. Subclasses may override. - * </p> - */ - @Override + result=new String[prompt.length]; + for(int i=0; i<texts.length; i++){ + result[i]=texts[i].getText(); + } + super.okPressed(); + } + /** + * Notifies that the cancel button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets + * this dialog's return code to <code>Window.CANCEL</code> + * and closes the dialog. Subclasses may override. + * </p> + */ + @Override protected void cancelPressed() { - result=null; - super.cancelPressed(); - } - - @Override - public boolean close(){ - if(keyLockImage!=null){ - keyLockImage.dispose(); - } - return super.close(); - } - - /** - * Guesses if this dialog is used for password authentication. - * @param prompt prompts for keyboard-interactive authentication method. - * @return <code>true</code> if this dialog is used for password authentication. - */ - static boolean isPasswordAuth(String[] prompt) { + result=null; + super.cancelPressed(); + } + + @Override + public boolean close(){ + if(keyLockImage!=null){ + keyLockImage.dispose(); + } + return super.close(); + } + + /** + * Guesses if this dialog is used for password authentication. + * @param prompt prompts for keyboard-interactive authentication method. + * @return <code>true</code> if this dialog is used for password authentication. + */ + static boolean isPasswordAuth(String[] prompt) { return prompt != null && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java index 0dbd5e9ca..0453c56f0 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java @@ -17,117 +17,117 @@ package org.eclipse.jsch.internal.ui; import org.eclipse.osgi.util.NLS; public class Messages extends NLS{ - private static final String BUNDLE_NAME="org.eclipse.jsch.internal.ui.messages";//$NON-NLS-1$ + private static final String BUNDLE_NAME="org.eclipse.jsch.internal.ui.messages";//$NON-NLS-1$ - static{ - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } + static{ + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } - public static String CVSSSH2ServerConnection_open; - public static String CVSSSH2PreferencePage_18; - public static String CVSSSH2PreferencePage_19; - public static String CVSSSH2PreferencePage_2; - public static String CVSSSH2PreferencePage_20; - public static String CVSSSH2PreferencePage_21; - public static String CVSSSH2PreferencePage_23; - public static String CVSSSH2PreferencePage_24; - public static String CVSSSH2PreferencePage_25; - public static String CVSSSH2PreferencePage_26; - public static String CVSSSH2PreferencePage_27; - public static String CVSSSH2PreferencePage_3; - public static String CVSSSH2PreferencePage_30; - public static String CVSSSH2PreferencePage_31; - public static String CVSSSH2PreferencePage_32; - public static String CVSSSH2PreferencePage_33; - public static String CVSSSH2PreferencePage_34; - public static String CVSSSH2PreferencePage_35; - public static String CVSSSH2PreferencePage_36; - public static String CVSSSH2PreferencePage_39; - public static String CVSSSH2PreferencePage_4; - public static String CVSSSH2PreferencePage_41; - public static String CVSSSH2PreferencePage_42; - public static String CVSSSH2PreferencePage_43; - public static String CVSSSH2PreferencePage_44; - public static String CVSSSH2PreferencePage_45; - public static String CVSSSH2PreferencePage_47; - public static String CVSSSH2PreferencePage_48; - public static String CVSSSH2PreferencePage_49; - public static String CVSSSH2PreferencePage_5; - public static String CVSSSH2PreferencePage_50; - public static String CVSSSH2PreferencePage_53; - public static String CVSSSH2PreferencePage_55; - public static String CVSSSH2PreferencePage_57; - public static String CVSSSH2PreferencePage_59; - public static String CVSSSH2PreferencePage_99; - public static String CVSSSH2PreferencePage_100; - public static String CVSSSH2PreferencePage_104; - public static String CVSSSH2PreferencePage_105; - public static String CVSSSH2PreferencePage_106; - public static String CVSSSH2PreferencePage_107; - public static String CVSSSH2PreferencePage_108; - public static String CVSSSH2PreferencePage_109; - public static String CVSSSH2PreferencePage_110; - public static String CVSSSH2PreferencePage_111; - public static String CVSSSH2ServerConnection_3; - public static String CVSSSH2ServerConnection_0; - public static String CVSSSH2ServerConnection_1; - public static String CVSSSH2PreferencePage_information; - public static String CVSSSH2PreferencePage_error; - public static String CVSSSH2PreferencePage_confirmation; - public static String CVSSSH2PreferencePage_question; - public static String CVSSSH2PreferencePage_125; - public static String CVSSSH2PreferencePage_126; - public static String CVSSSH2PreferencePage_127; - public static String CVSSSH2PreferencePage_128; - public static String CVSSSH2PreferencePage_129; - public static String CVSSSH2PreferencePage_130; - public static String CVSSSH2PreferencePage_131; - public static String CVSSSH2PreferencePage_132; - public static String CVSSSH2PreferencePage_133; - public static String CVSSSH2PreferencePage_134; - public static String CVSSSH2PreferencePage_135; - public static String CVSSSH2PreferencePage_136; - public static String CVSSSH2PreferencePage_137; - public static String CVSSSH2PreferencePage_138; - public static String CVSSSH2PreferencePage_139; - public static String CVSSSH2PreferencePage_140; - public static String CVSSSH2PreferencePage_141; - public static String CVSSSH2PreferencePage_142; - public static String CVSSSH2PreferencePage_143; - public static String CVSSSH2PreferencePage_144; - public static String CVSSSH2PreferencePage_145; - public static String CVSSSH2PreferencePage_146; - public static String CVSSSH2PreferencePage_147; - public static String KeyboardInteractiveDialog_0; - public static String KeyboardInteractiveDialog_1; - public static String KeyboardInteractiveDialog_2; - public static String KeyboardInteractiveDialog_3; - public static String KeyboardInteractiveDialog_4; - public static String KeyboardInteractiveDialog_6; - public static String KeyboradInteractiveDialog_message; - public static String KeyboardInteractiveDialog_labelRepository; + public static String CVSSSH2ServerConnection_open; + public static String CVSSSH2PreferencePage_18; + public static String CVSSSH2PreferencePage_19; + public static String CVSSSH2PreferencePage_2; + public static String CVSSSH2PreferencePage_20; + public static String CVSSSH2PreferencePage_21; + public static String CVSSSH2PreferencePage_23; + public static String CVSSSH2PreferencePage_24; + public static String CVSSSH2PreferencePage_25; + public static String CVSSSH2PreferencePage_26; + public static String CVSSSH2PreferencePage_27; + public static String CVSSSH2PreferencePage_3; + public static String CVSSSH2PreferencePage_30; + public static String CVSSSH2PreferencePage_31; + public static String CVSSSH2PreferencePage_32; + public static String CVSSSH2PreferencePage_33; + public static String CVSSSH2PreferencePage_34; + public static String CVSSSH2PreferencePage_35; + public static String CVSSSH2PreferencePage_36; + public static String CVSSSH2PreferencePage_39; + public static String CVSSSH2PreferencePage_4; + public static String CVSSSH2PreferencePage_41; + public static String CVSSSH2PreferencePage_42; + public static String CVSSSH2PreferencePage_43; + public static String CVSSSH2PreferencePage_44; + public static String CVSSSH2PreferencePage_45; + public static String CVSSSH2PreferencePage_47; + public static String CVSSSH2PreferencePage_48; + public static String CVSSSH2PreferencePage_49; + public static String CVSSSH2PreferencePage_5; + public static String CVSSSH2PreferencePage_50; + public static String CVSSSH2PreferencePage_53; + public static String CVSSSH2PreferencePage_55; + public static String CVSSSH2PreferencePage_57; + public static String CVSSSH2PreferencePage_59; + public static String CVSSSH2PreferencePage_99; + public static String CVSSSH2PreferencePage_100; + public static String CVSSSH2PreferencePage_104; + public static String CVSSSH2PreferencePage_105; + public static String CVSSSH2PreferencePage_106; + public static String CVSSSH2PreferencePage_107; + public static String CVSSSH2PreferencePage_108; + public static String CVSSSH2PreferencePage_109; + public static String CVSSSH2PreferencePage_110; + public static String CVSSSH2PreferencePage_111; + public static String CVSSSH2ServerConnection_3; + public static String CVSSSH2ServerConnection_0; + public static String CVSSSH2ServerConnection_1; + public static String CVSSSH2PreferencePage_information; + public static String CVSSSH2PreferencePage_error; + public static String CVSSSH2PreferencePage_confirmation; + public static String CVSSSH2PreferencePage_question; + public static String CVSSSH2PreferencePage_125; + public static String CVSSSH2PreferencePage_126; + public static String CVSSSH2PreferencePage_127; + public static String CVSSSH2PreferencePage_128; + public static String CVSSSH2PreferencePage_129; + public static String CVSSSH2PreferencePage_130; + public static String CVSSSH2PreferencePage_131; + public static String CVSSSH2PreferencePage_132; + public static String CVSSSH2PreferencePage_133; + public static String CVSSSH2PreferencePage_134; + public static String CVSSSH2PreferencePage_135; + public static String CVSSSH2PreferencePage_136; + public static String CVSSSH2PreferencePage_137; + public static String CVSSSH2PreferencePage_138; + public static String CVSSSH2PreferencePage_139; + public static String CVSSSH2PreferencePage_140; + public static String CVSSSH2PreferencePage_141; + public static String CVSSSH2PreferencePage_142; + public static String CVSSSH2PreferencePage_143; + public static String CVSSSH2PreferencePage_144; + public static String CVSSSH2PreferencePage_145; + public static String CVSSSH2PreferencePage_146; + public static String CVSSSH2PreferencePage_147; + public static String KeyboardInteractiveDialog_0; + public static String KeyboardInteractiveDialog_1; + public static String KeyboardInteractiveDialog_2; + public static String KeyboardInteractiveDialog_3; + public static String KeyboardInteractiveDialog_4; + public static String KeyboardInteractiveDialog_6; + public static String KeyboradInteractiveDialog_message; + public static String KeyboardInteractiveDialog_labelRepository; - public static String PreferencePage_0; - public static String PreferencePage_1; - public static String UserInfoPrompter_0; - public static String UserInfoPrompter_1; - public static String UserValidationDialog_0; - public static String UserValidationDialog_1; - public static String UserValidationDialog_2; - public static String UserValidationDialog_4; - public static String UserValidationDialog_5; - public static String UserValidationDialog_6; + public static String PreferencePage_0; + public static String PreferencePage_1; + public static String UserInfoPrompter_0; + public static String UserInfoPrompter_1; + public static String UserValidationDialog_0; + public static String UserValidationDialog_1; + public static String UserValidationDialog_2; + public static String UserValidationDialog_4; + public static String UserValidationDialog_5; + public static String UserValidationDialog_6; - public static String UserValidationDialog_required; - public static String UserValidationDialog_labelUser; - public static String UserValidationDialog_labelPassword; - public static String UserValidationDialog_password; - public static String UserValidationDialog_user; + public static String UserValidationDialog_required; + public static String UserValidationDialog_labelUser; + public static String UserValidationDialog_labelPassword; + public static String UserValidationDialog_password; + public static String UserValidationDialog_user; - public static String WorkbenchUserAuthenticator_cancelled; - public static String WorkbenchUserAuthenticator_1; - public static String WorkbenchUserAuthenticator_2; - public static String WorkbenchUserAuthenticator_The_operation_was_canceled_by_the_user_1; + public static String WorkbenchUserAuthenticator_cancelled; + public static String WorkbenchUserAuthenticator_1; + public static String WorkbenchUserAuthenticator_2; + public static String WorkbenchUserAuthenticator_The_operation_was_canceled_by_the_user_1; } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/UserValidationDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/UserValidationDialog.java index 1859876b3..dcef8115a 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/UserValidationDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/UserValidationDialog.java @@ -62,7 +62,7 @@ public class UserValidationDialog extends TrayDialog { */ public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { super(parentShell); - setShellStyle(getShellStyle() | SWT.RESIZE); + setShellStyle(getShellStyle() | SWT.RESIZE); this.defaultUsername = defaultName; this.domain = location; this.message = message; @@ -72,7 +72,7 @@ public class UserValidationDialog extends TrayDialog { super.configureShell(newShell); newShell.setText(Messages.UserValidationDialog_0); // set F1 help - PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG); + PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IHelpContextIds.USER_VALIDATION_DIALOG); } @Override public void create() { @@ -153,7 +153,7 @@ public class UserValidationDialog extends TrayDialog { }); } - Dialog.applyDialogFont(parent); + Dialog.applyDialogFont(parent); return main; } @@ -234,9 +234,9 @@ public class UserValidationDialog extends TrayDialog { @Override protected void cancelPressed(){ - password = null; - username = null; - super.cancelPressed(); + password = null; + username = null; + super.cancelPressed(); } /** diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java index d4124076b..efdd1d5fc 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/IHelpContextIds.java @@ -24,10 +24,10 @@ import org.eclipse.jsch.internal.ui.JSchUIPlugin; */ public interface IHelpContextIds{ - public static final String PREFIX=JSchUIPlugin.ID+"."; //$NON-NLS-1$ + public static final String PREFIX=JSchUIPlugin.ID+"."; //$NON-NLS-1$ - public static final String KEYBOARD_INTERACTIVE_DIALOG=PREFIX - +"keyboard_interactive_dialog_context"; //$NON-NLS-1$ - public static final String USER_VALIDATION_DIALOG=PREFIX - +"user_validation_dialog_context"; //$NON-NLS-1$ + public static final String KEYBOARD_INTERACTIVE_DIALOG=PREFIX + +"keyboard_interactive_dialog_context"; //$NON-NLS-1$ + public static final String USER_VALIDATION_DIALOG=PREFIX + +"user_validation_dialog_context"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java index 40a6d82cc..a20b22e0c 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/KeyboardInteractiveDialog.java @@ -41,282 +41,282 @@ import org.eclipse.ui.PlatformUI; * @since 1.1 */ public class KeyboardInteractiveDialog extends TrayDialog{ - // whether or not the user name can be changed - protected boolean isUsernameMutable=false; - - // widgets - private Text[] texts; - protected Image keyLockImage; - protected Button allowCachingButton; - protected Text usernameField; - - protected String defaultUsername; - protected String comment; - protected String destination; - protected String name; - protected String instruction; - protected String lang; - protected String[] prompt; - protected boolean[] echo; - private String message; - private String[] result; - protected boolean allowCaching=false; - - private boolean isPasswordAuth=false; - - /** - * Creates a new KeyboardInteractiveDialog. - * - * @param parentShell the parent shell - * @param comment the comment - * @param destination the location - * @param name the name - * @param userName user name - * @param instruction the instruction - * @param prompt the titles for text-fields - * @param echo '*' should be used or not - */ - public KeyboardInteractiveDialog(Shell parentShell, String comment, - String destination, String name, String userName, String instruction, String[] prompt, - boolean[] echo){ - super(parentShell); - setShellStyle(getShellStyle()|SWT.RESIZE); - this.comment=comment; - this.destination=destination; - this.name=name; - this.defaultUsername=userName; - this.instruction=instruction; - this.prompt=prompt; - this.echo=echo; - this.message=NLS.bind(Messages.KeyboradInteractiveDialog_message, - new String[] {destination - +(name!=null&&name.length()>0 ? ": "+name : "")}); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ - - if(prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ - isPasswordAuth=true; - } - - } - - @Override + // whether or not the user name can be changed + protected boolean isUsernameMutable=false; + + // widgets + private Text[] texts; + protected Image keyLockImage; + protected Button allowCachingButton; + protected Text usernameField; + + protected String defaultUsername; + protected String comment; + protected String destination; + protected String name; + protected String instruction; + protected String lang; + protected String[] prompt; + protected boolean[] echo; + private String message; + private String[] result; + protected boolean allowCaching=false; + + private boolean isPasswordAuth=false; + + /** + * Creates a new KeyboardInteractiveDialog. + * + * @param parentShell the parent shell + * @param comment the comment + * @param destination the location + * @param name the name + * @param userName user name + * @param instruction the instruction + * @param prompt the titles for text-fields + * @param echo '*' should be used or not + */ + public KeyboardInteractiveDialog(Shell parentShell, String comment, + String destination, String name, String userName, String instruction, String[] prompt, + boolean[] echo){ + super(parentShell); + setShellStyle(getShellStyle()|SWT.RESIZE); + this.comment=comment; + this.destination=destination; + this.name=name; + this.defaultUsername=userName; + this.instruction=instruction; + this.prompt=prompt; + this.echo=echo; + this.message=NLS.bind(Messages.KeyboradInteractiveDialog_message, + new String[] {destination + +(name!=null&&name.length()>0 ? ": "+name : "")}); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ + + if(prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ + isPasswordAuth=true; + } + + } + + @Override protected void configureShell(Shell newShell){ - super.configureShell(newShell); - if(isPasswordAuth){ - newShell.setText(Messages.UserValidationDialog_required); - } - else{ - newShell.setText(message); - } - // set F1 help - PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, - IHelpContextIds.KEYBOARD_INTERACTIVE_DIALOG); - } - - @Override + super.configureShell(newShell); + if(isPasswordAuth){ + newShell.setText(Messages.UserValidationDialog_required); + } + else{ + newShell.setText(message); + } + // set F1 help + PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, + IHelpContextIds.KEYBOARD_INTERACTIVE_DIALOG); + } + + @Override public void create(){ - super.create(); + super.create(); - if(isPasswordAuth&&usernameField!=null){ - usernameField.setText(defaultUsername); - usernameField.setEditable(false); - } + if(isPasswordAuth&&usernameField!=null){ + usernameField.setText(defaultUsername); + usernameField.setEditable(false); + } - if(texts.length>0){ - texts[0].setFocus(); - } - } + if(texts.length>0){ + texts[0].setFocus(); + } + } - @Override + @Override protected Control createDialogArea(Composite parent){ - Composite top=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=2; - - top.setLayout(layout); - top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite imageComposite=new Composite(top, SWT.NONE); - layout=new GridLayout(); - imageComposite.setLayout(layout); - imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - - Composite main=new Composite(top, SWT.NONE); - layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label imageLabel=new Label(imageComposite, SWT.NONE); - keyLockImage=JSchUIPlugin.getImageDescriptor(IUIConstants.IMG_KEY_LOCK) - .createImage(); - imageLabel.setImage(keyLockImage); - GridData data=new GridData(GridData.FILL_HORIZONTAL - |GridData.GRAB_HORIZONTAL); - imageLabel.setLayoutData(data); - - if(message!=null){ - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - data.widthHint=400; - messageLabel.setLayoutData(data); - } - if(comment!=null){ - Label label=new Label(main, SWT.WRAP); - if(isUsernameMutable){ - label.setText(NLS.bind(Messages.UserValidationDialog_labelUser, - new String[] {comment})); - } - else{ - label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword, - (new Object[] {defaultUsername, comment}))); - } - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - data.widthHint=400; - label.setLayoutData(data); - } - if(instruction!=null&&instruction.length()>0){ - Label label=new Label(main, SWT.WRAP); - label.setText(instruction); - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - data.widthHint=400; - label.setLayoutData(data); - } - - if(isPasswordAuth){ - createUsernameFields(main); - } - - createPasswordFields(main); - - if(isPasswordAuth){ - allowCachingButton=new Button(main, SWT.CHECK); - allowCachingButton.setText(Messages.UserValidationDialog_6); - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - allowCachingButton.setLayoutData(data); - allowCachingButton.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - allowCaching=allowCachingButton.getSelection(); - } - }); - } - - Dialog.applyDialogFont(parent); - - return main; - } - - /** - * Creates the three widgets that represent the user name entry area. - * - * @param parent the parent of the widgets - */ - protected void createUsernameFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_user); - - usernameField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - usernameField.setLayoutData(data); - } - - /** - * Creates the widgets that represent the entry area. - * - * @param parent the parent of the widgets - */ - protected void createPasswordFields(Composite parent){ - texts=new Text[prompt.length]; - - for(int i=0; i<prompt.length; i++){ - new Label(parent, SWT.NONE).setText(prompt[i]); - int flag=SWT.BORDER; - if(!echo[i]){ - flag|=SWT.PASSWORD; - } - texts[i]=new Text(parent, flag); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - texts[i].setLayoutData(data); - if(!echo[i]){ - texts[i].setEchoChar('*'); - } - } - } - - /** - * Returns the entered values, or null - * if the user canceled. - * - * @return the entered values - */ - public String[] getResult(){ - return result; - } - - /** - * Returns <code>true</code> if the save password checkbox was selected. - * @return <code>true</code> if the save password checkbox was selected and <code>false</code> - * otherwise. - */ - public boolean getAllowCaching(){ - return allowCaching; - } - - /** - * Notifies that the ok button of this dialog has been pressed. - * <p> - * The default implementation of this framework method sets - * this dialog's return code to <code>Window.OK</code> - * and closes the dialog. Subclasses may override. - * </p> - */ - @Override + Composite top=new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.numColumns=2; + + top.setLayout(layout); + top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Composite imageComposite=new Composite(top, SWT.NONE); + layout=new GridLayout(); + imageComposite.setLayout(layout); + imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + + Composite main=new Composite(top, SWT.NONE); + layout=new GridLayout(); + layout.numColumns=3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label imageLabel=new Label(imageComposite, SWT.NONE); + keyLockImage=JSchUIPlugin.getImageDescriptor(IUIConstants.IMG_KEY_LOCK) + .createImage(); + imageLabel.setImage(keyLockImage); + GridData data=new GridData(GridData.FILL_HORIZONTAL + |GridData.GRAB_HORIZONTAL); + imageLabel.setLayoutData(data); + + if(message!=null){ + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(message); + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + data.widthHint=400; + messageLabel.setLayoutData(data); + } + if(comment!=null){ + Label label=new Label(main, SWT.WRAP); + if(isUsernameMutable){ + label.setText(NLS.bind(Messages.UserValidationDialog_labelUser, + new String[] {comment})); + } + else{ + label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword, + (new Object[] {defaultUsername, comment}))); + } + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + data.widthHint=400; + label.setLayoutData(data); + } + if(instruction!=null&&instruction.length()>0){ + Label label=new Label(main, SWT.WRAP); + label.setText(instruction); + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + data.widthHint=400; + label.setLayoutData(data); + } + + if(isPasswordAuth){ + createUsernameFields(main); + } + + createPasswordFields(main); + + if(isPasswordAuth){ + allowCachingButton=new Button(main, SWT.CHECK); + allowCachingButton.setText(Messages.UserValidationDialog_6); + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + allowCachingButton.setLayoutData(data); + allowCachingButton.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + allowCaching=allowCachingButton.getSelection(); + } + }); + } + + Dialog.applyDialogFont(parent); + + return main; + } + + /** + * Creates the three widgets that represent the user name entry area. + * + * @param parent the parent of the widgets + */ + protected void createUsernameFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_user); + + usernameField=new Text(parent, SWT.BORDER); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + } + + /** + * Creates the widgets that represent the entry area. + * + * @param parent the parent of the widgets + */ + protected void createPasswordFields(Composite parent){ + texts=new Text[prompt.length]; + + for(int i=0; i<prompt.length; i++){ + new Label(parent, SWT.NONE).setText(prompt[i]); + int flag=SWT.BORDER; + if(!echo[i]){ + flag|=SWT.PASSWORD; + } + texts[i]=new Text(parent, flag); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + texts[i].setLayoutData(data); + if(!echo[i]){ + texts[i].setEchoChar('*'); + } + } + } + + /** + * Returns the entered values, or null + * if the user canceled. + * + * @return the entered values + */ + public String[] getResult(){ + return result; + } + + /** + * Returns <code>true</code> if the save password checkbox was selected. + * @return <code>true</code> if the save password checkbox was selected and <code>false</code> + * otherwise. + */ + public boolean getAllowCaching(){ + return allowCaching; + } + + /** + * Notifies that the ok button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets + * this dialog's return code to <code>Window.OK</code> + * and closes the dialog. Subclasses may override. + * </p> + */ + @Override protected void okPressed(){ - result=new String[prompt.length]; - for(int i=0; i<texts.length; i++){ - result[i]=texts[i].getText(); - } - super.okPressed(); - } - - /** - * Sets whether or not the username field should be mutable. - * This method must be called before create(), otherwise it - * will be ignored. - * - * @param value whether the username is mutable - */ - public void setUsernameMutable(boolean value){ - isUsernameMutable=value; - } - - /** - * Notifies that the cancel button of this dialog has been pressed. - * <p> - * The default implementation of this framework method sets - * this dialog's return code to <code>Window.CANCEL</code> - * and closes the dialog. Subclasses may override. - * </p> - */ - @Override - protected void cancelPressed(){ - result=null; - super.cancelPressed(); - } - - @Override - public boolean close(){ - if(keyLockImage!=null){ - keyLockImage.dispose(); - } - return super.close(); - } + result=new String[prompt.length]; + for(int i=0; i<texts.length; i++){ + result[i]=texts[i].getText(); + } + super.okPressed(); + } + + /** + * Sets whether or not the username field should be mutable. + * This method must be called before create(), otherwise it + * will be ignored. + * + * @param value whether the username is mutable + */ + public void setUsernameMutable(boolean value){ + isUsernameMutable=value; + } + + /** + * Notifies that the cancel button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets + * this dialog's return code to <code>Window.CANCEL</code> + * and closes the dialog. Subclasses may override. + * </p> + */ + @Override + protected void cancelPressed(){ + result=null; + super.cancelPressed(); + } + + @Override + public boolean close(){ + if(keyLockImage!=null){ + keyLockImage.dispose(); + } + return super.close(); + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java index ea035fb83..f29ad949d 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/UserValidationDialog.java @@ -40,239 +40,239 @@ import org.eclipse.ui.PlatformUI; * @since 1.1 */ public class UserValidationDialog extends TrayDialog{ - // widgets - protected Text usernameField; - protected Text passwordField; - protected Button allowCachingButton; + // widgets + protected Text usernameField; + protected Text passwordField; + protected Button allowCachingButton; - protected String comment; - protected String defaultUsername; - protected String password=null; - protected boolean allowCaching=false; - protected boolean isAllowCaching=false; - protected Image keyLockImage; + protected String comment; + protected String defaultUsername; + protected String password=null; + protected boolean allowCaching=false; + protected boolean isAllowCaching=false; + protected Image keyLockImage; - // whether or not the user name can be changed - protected boolean isUsernameMutable=true; - protected String username=null; - protected String message=null; + // whether or not the user name can be changed + protected boolean isUsernameMutable=true; + protected String username=null; + protected String message=null; - /** - * Creates a new UserValidationDialog. - * - * @param parentShell - * the parent shell - * @param comment - * the location - * @param defaultName - * the default user name - * @param message - * a message to display to the user - * @param isAllowCaching - * a flag to show a check box to save password - */ - public UserValidationDialog(Shell parentShell, String comment, - String defaultName, String message, boolean isAllowCaching){ - super(parentShell); - setShellStyle(getShellStyle()|SWT.RESIZE); - this.defaultUsername=defaultName; - this.comment=comment; - this.message=message; - this.isAllowCaching=isAllowCaching; - } + /** + * Creates a new UserValidationDialog. + * + * @param parentShell + * the parent shell + * @param comment + * the location + * @param defaultName + * the default user name + * @param message + * a message to display to the user + * @param isAllowCaching + * a flag to show a check box to save password + */ + public UserValidationDialog(Shell parentShell, String comment, + String defaultName, String message, boolean isAllowCaching){ + super(parentShell); + setShellStyle(getShellStyle()|SWT.RESIZE); + this.defaultUsername=defaultName; + this.comment=comment; + this.message=message; + this.isAllowCaching=isAllowCaching; + } @Override - protected void configureShell(Shell newShell){ - super.configureShell(newShell); - newShell.setText(Messages.UserValidationDialog_required); - // set F1 help - PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, - IHelpContextIds.USER_VALIDATION_DIALOG); - } + protected void configureShell(Shell newShell){ + super.configureShell(newShell); + newShell.setText(Messages.UserValidationDialog_required); + // set F1 help + PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, + IHelpContextIds.USER_VALIDATION_DIALOG); + } - @Override + @Override public void create(){ - super.create(); - // add some default values - usernameField.setText(defaultUsername); + super.create(); + // add some default values + usernameField.setText(defaultUsername); - if(isUsernameMutable){ - // give focus to user name field - usernameField.selectAll(); - usernameField.setFocus(); - } - else{ - usernameField.setEditable(false); - passwordField.setFocus(); - } - } + if(isUsernameMutable){ + // give focus to user name field + usernameField.selectAll(); + usernameField.setFocus(); + } + else{ + usernameField.setEditable(false); + passwordField.setFocus(); + } + } - @Override + @Override protected Control createDialogArea(Composite parent){ - Composite top=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=2; + Composite top=new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.numColumns=2; - top.setLayout(layout); - top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + top.setLayout(layout); + top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Composite imageComposite=new Composite(top, SWT.NONE); - layout=new GridLayout(); - imageComposite.setLayout(layout); - imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + Composite imageComposite=new Composite(top, SWT.NONE); + layout=new GridLayout(); + imageComposite.setLayout(layout); + imageComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - Composite main=new Composite(top, SWT.NONE); - layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + Composite main=new Composite(top, SWT.NONE); + layout=new GridLayout(); + layout.numColumns=3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Label imageLabel=new Label(imageComposite, SWT.NONE); - keyLockImage=JSchUIPlugin.getImageDescriptor(IUIConstants.IMG_KEY_LOCK) - .createImage(); - imageLabel.setImage(keyLockImage); - GridData data=new GridData(GridData.FILL_HORIZONTAL - |GridData.GRAB_HORIZONTAL); - imageLabel.setLayoutData(data); + Label imageLabel=new Label(imageComposite, SWT.NONE); + keyLockImage=JSchUIPlugin.getImageDescriptor(IUIConstants.IMG_KEY_LOCK) + .createImage(); + imageLabel.setImage(keyLockImage); + GridData data=new GridData(GridData.FILL_HORIZONTAL + |GridData.GRAB_HORIZONTAL); + imageLabel.setLayoutData(data); - if(message!=null){ - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - data.widthHint=400; - messageLabel.setLayoutData(data); - } - if(comment!=null){ - Label label=new Label(main, SWT.WRAP); - if(isUsernameMutable){ - label.setText(NLS.bind(Messages.UserValidationDialog_labelUser, - new String[] {comment})); - } - else{ - label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword, - (new Object[] {defaultUsername, comment}))); - } - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - data.widthHint=400; - label.setLayoutData(data); - } - createUsernameFields(main); - createPasswordFields(main); + if(message!=null){ + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(message); + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + data.widthHint=400; + messageLabel.setLayoutData(data); + } + if(comment!=null){ + Label label=new Label(main, SWT.WRAP); + if(isUsernameMutable){ + label.setText(NLS.bind(Messages.UserValidationDialog_labelUser, + new String[] {comment})); + } + else{ + label.setText(NLS.bind(Messages.UserValidationDialog_labelPassword, + (new Object[] {defaultUsername, comment}))); + } + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + data.widthHint=400; + label.setLayoutData(data); + } + createUsernameFields(main); + createPasswordFields(main); - if(isAllowCaching){ - allowCachingButton=new Button(main, SWT.CHECK); - allowCachingButton.setText(Messages.UserValidationDialog_6); - data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); - data.horizontalSpan=3; - allowCachingButton.setLayoutData(data); - allowCachingButton.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - allowCaching=allowCachingButton.getSelection(); - } - }); - } + if(isAllowCaching){ + allowCachingButton=new Button(main, SWT.CHECK); + allowCachingButton.setText(Messages.UserValidationDialog_6); + data=new GridData(GridData.FILL_HORIZONTAL|GridData.GRAB_HORIZONTAL); + data.horizontalSpan=3; + allowCachingButton.setLayoutData(data); + allowCachingButton.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + allowCaching=allowCachingButton.getSelection(); + } + }); + } - Dialog.applyDialogFont(parent); + Dialog.applyDialogFont(parent); - return main; - } + return main; + } - /** - * Creates the three widgets that represent the password entry area. - * - * @param parent - * the parent of the widgets - */ - protected void createPasswordFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_password); + /** + * Creates the three widgets that represent the password entry area. + * + * @param parent + * the parent of the widgets + */ + protected void createPasswordFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_password); - passwordField=new Text(parent, SWT.BORDER|SWT.PASSWORD); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - passwordField.setLayoutData(data); - } + passwordField=new Text(parent, SWT.BORDER|SWT.PASSWORD); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + passwordField.setLayoutData(data); + } - /** - * Creates the three widgets that represent the user name entry area. - * - * @param parent - * the parent of the widgets - */ - protected void createUsernameFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_user); + /** + * Creates the three widgets that represent the user name entry area. + * + * @param parent + * the parent of the widgets + */ + protected void createUsernameFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.UserValidationDialog_user); - usernameField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - usernameField.setLayoutData(data); - } + usernameField=new Text(parent, SWT.BORDER); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + } - /** - * Returns the password entered by the user, or null if the user canceled. - * - * @return the entered password - */ - public String getPassword(){ - return password; - } + /** + * Returns the password entered by the user, or null if the user canceled. + * + * @return the entered password + */ + public String getPassword(){ + return password; + } - /** - * Returns the username entered by the user, or null if the user canceled. - * - * @return the entered username - */ - public String getUsername(){ - return username; - } + /** + * Returns the username entered by the user, or null if the user canceled. + * + * @return the entered username + */ + public String getUsername(){ + return username; + } - /** - * Returns <code>true</code> if the save password checkbox was selected. - * - * @return <code>true</code> if the save password checkbox was selected and - * <code>false</code> otherwise. - */ - public boolean getAllowCaching(){ - return allowCaching; - } + /** + * Returns <code>true</code> if the save password checkbox was selected. + * + * @return <code>true</code> if the save password checkbox was selected and + * <code>false</code> otherwise. + */ + public boolean getAllowCaching(){ + return allowCaching; + } - /** - * Notifies that the ok button of this dialog has been pressed. - * <p> - * The default implementation of this framework method sets this dialog's - * return code to <code>Window.OK</code> and closes the dialog. Subclasses - * may override. - * </p> - */ - @Override + /** + * Notifies that the ok button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets this dialog's + * return code to <code>Window.OK</code> and closes the dialog. Subclasses + * may override. + * </p> + */ + @Override protected void okPressed(){ - password=passwordField.getText(); - username=usernameField.getText(); + password=passwordField.getText(); + username=usernameField.getText(); - super.okPressed(); - } + super.okPressed(); + } - /** - * Sets whether or not the username field should be mutable. This method must - * be called before create(), otherwise it will be ignored. - * - * @param value - * whether the username is mutable - */ - public void setUsernameMutable(boolean value){ - isUsernameMutable=value; - } + /** + * Sets whether or not the username field should be mutable. This method must + * be called before create(), otherwise it will be ignored. + * + * @param value + * whether the username is mutable + */ + public void setUsernameMutable(boolean value){ + isUsernameMutable=value; + } - @Override - public boolean close(){ - if(keyLockImage!=null){ - keyLockImage.dispose(); - } - return super.close(); - } + @Override + public boolean close(){ + if(keyLockImage!=null){ + keyLockImage.dispose(); + } + return super.close(); + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java index 1276044b2..24672fa49 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/authenticator/WorkbenchUserAuthenticator.java @@ -36,163 +36,163 @@ import org.eclipse.ui.PlatformUI; * @since 1.1 */ public class WorkbenchUserAuthenticator implements IUserAuthenticator{ - /** - * WorkbenchUserAuthenticator constructor. - */ - public WorkbenchUserAuthenticator(){ - super(); - } - - @Override + /** + * WorkbenchUserAuthenticator constructor. + */ + public WorkbenchUserAuthenticator(){ + super(); + } + + @Override public void promptForUserInfo(final IJSchLocation location, - final IUserInfo userinfo, final String message){ - - // ask the user for a password - final String[] result=new String[2]; - Display display=Display.getCurrent(); - final boolean allowCaching[]= {false}; - if(display!=null){ - allowCaching[0]=promptForPassword(location, userinfo.getUsername(), - message, userinfo.isUsernameMutable(), result); - } - else{ - // sync exec in default thread + final IUserInfo userinfo, final String message){ + + // ask the user for a password + final String[] result=new String[2]; + Display display=Display.getCurrent(); + final boolean allowCaching[]= {false}; + if(display!=null){ + allowCaching[0]=promptForPassword(location, userinfo.getUsername(), + message, userinfo.isUsernameMutable(), result); + } + else{ + // sync exec in default thread Display.getDefault().syncExec(() -> allowCaching[0] = promptForPassword(location, userinfo.getUsername(), message, userinfo.isUsernameMutable(), result)); - } - - if(result[0]==null){ - throw new OperationCanceledException( - Messages.WorkbenchUserAuthenticator_cancelled); - } - - if(userinfo.isUsernameMutable()){ - userinfo.setUsername(result[0]); - - } - userinfo.setPassword(result[1]); - - if(location!=null){ - if(userinfo.isUsernameMutable()){ - location.setUsername(result[0]); - } - location.setPassword(result[1]); - if(location.getPasswordStore()!=null){ - if(allowCaching[0]) - location.getPasswordStore().update(location); - else - location.getPasswordStore().clear(location); - } - } - } - - /** - * Asks the user to enter a password. Places the - * results in the supplied string[]. result[0] must - * contain the username, result[1] must contain the password. - * If the user canceled, both values must be zero. - * - * @param location the location to obtain the password for - * @param username the username - * @param message a message to display to the user - * @param userMutable whether the user can be changed in the dialog - * @param result a String array of length two in which to put the result - */ - protected boolean promptForPassword(final IJSchLocation location, - final String username, final String message, final boolean userMutable, - final String[] result){ - String comment=location==null ? null : location.getComment(); - UserValidationDialog dialog=new UserValidationDialog(null, comment, - (username==null) ? "" : username, message, (location!=null && location.getPasswordStore()!=null));//$NON-NLS-1$ - dialog.setUsernameMutable(userMutable); - dialog.open(); - result[0]=dialog.getUsername(); - result[1]=dialog.getPassword(); - return dialog.getAllowCaching(); - } - - /** - * Asks the user to enter values. - * - * @param location the location to obtain the password for - * @param destination the location - * @param name the name - * @param instruction the instruction - * @param prompt the titles for text fields - * @param echo '*' should be used or not - * @return the entered values, or null if user canceled. - */ - @Override + } + + if(result[0]==null){ + throw new OperationCanceledException( + Messages.WorkbenchUserAuthenticator_cancelled); + } + + if(userinfo.isUsernameMutable()){ + userinfo.setUsername(result[0]); + + } + userinfo.setPassword(result[1]); + + if(location!=null){ + if(userinfo.isUsernameMutable()){ + location.setUsername(result[0]); + } + location.setPassword(result[1]); + if(location.getPasswordStore()!=null){ + if(allowCaching[0]) + location.getPasswordStore().update(location); + else + location.getPasswordStore().clear(location); + } + } + } + + /** + * Asks the user to enter a password. Places the + * results in the supplied string[]. result[0] must + * contain the username, result[1] must contain the password. + * If the user canceled, both values must be zero. + * + * @param location the location to obtain the password for + * @param username the username + * @param message a message to display to the user + * @param userMutable whether the user can be changed in the dialog + * @param result a String array of length two in which to put the result + */ + protected boolean promptForPassword(final IJSchLocation location, + final String username, final String message, final boolean userMutable, + final String[] result){ + String comment=location==null ? null : location.getComment(); + UserValidationDialog dialog=new UserValidationDialog(null, comment, + (username==null) ? "" : username, message, (location!=null && location.getPasswordStore()!=null));//$NON-NLS-1$ + dialog.setUsernameMutable(userMutable); + dialog.open(); + result[0]=dialog.getUsername(); + result[1]=dialog.getPassword(); + return dialog.getAllowCaching(); + } + + /** + * Asks the user to enter values. + * + * @param location the location to obtain the password for + * @param destination the location + * @param name the name + * @param instruction the instruction + * @param prompt the titles for text fields + * @param echo '*' should be used or not + * @return the entered values, or null if user canceled. + */ + @Override public String[] promptForKeyboradInteractive( - final IJSchLocation location, final String destination, - final String name, final String instruction, final String[] prompt, - final boolean[] echo){ - final String[][] result=new String[1][]; - final boolean[] allowCaching=new boolean[1]; - Display display=Display.getCurrent(); - if(display!=null){ - result[0]=_promptForUserInteractive(location, destination, name, - instruction, prompt, echo, allowCaching); - } - else{ - // sync exec in default thread + final IJSchLocation location, final String destination, + final String name, final String instruction, final String[] prompt, + final boolean[] echo){ + final String[][] result=new String[1][]; + final boolean[] allowCaching=new boolean[1]; + Display display=Display.getCurrent(); + if(display!=null){ + result[0]=_promptForUserInteractive(location, destination, name, + instruction, prompt, echo, allowCaching); + } + else{ + // sync exec in default thread Display.getDefault().syncExec(() -> result[0] = _promptForUserInteractive(location, destination, name, instruction, prompt, echo, allowCaching)); - } - if(result[0]!=null && location!=null && - prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ - location.setPassword(result[0][0]); - if(location.getPasswordStore()!=null){ - if(allowCaching[0]) - location.getPasswordStore().update(location); - else - location.getPasswordStore().clear(location); - } - } - return result[0]; - } - - protected String[] _promptForUserInteractive( - final IJSchLocation location, final String destination, - final String name, final String instruction, final String[] prompt, - final boolean[] echo, final boolean[] allowCaching){ - String comment=location==null ? null : location.getComment(); - String username=location==null ? "" : location.getUsername(); //$NON-NLS-1$ - KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(null, - comment, destination, name, username, instruction, prompt, echo); - dialog.setUsernameMutable(false); - dialog.open(); - String[] _result=dialog.getResult(); - if(_result!=null) - allowCaching[0]=dialog.getAllowCaching(); - return _result; - } - - - @Override + } + if(result[0]!=null && location!=null && + prompt!=null && prompt.length==1 && prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ + location.setPassword(result[0][0]); + if(location.getPasswordStore()!=null){ + if(allowCaching[0]) + location.getPasswordStore().update(location); + else + location.getPasswordStore().clear(location); + } + } + return result[0]; + } + + protected String[] _promptForUserInteractive( + final IJSchLocation location, final String destination, + final String name, final String instruction, final String[] prompt, + final boolean[] echo, final boolean[] allowCaching){ + String comment=location==null ? null : location.getComment(); + String username=location==null ? "" : location.getUsername(); //$NON-NLS-1$ + KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(null, + comment, destination, name, username, instruction, prompt, echo); + dialog.setUsernameMutable(false); + dialog.open(); + String[] _result=dialog.getResult(); + if(_result!=null) + allowCaching[0]=dialog.getAllowCaching(); + return _result; + } + + + @Override public int prompt(IJSchLocation location, final int promptType, - final String title, final String message, final int[] promptResponses, - final int defaultResponse){ - final Display display=getStandardDisplay(); - final int[] retval=new int[1]; - final String[] buttons=new String[promptResponses.length]; - for(int i=0; i<promptResponses.length; i++){ - int prompt=promptResponses[i]; - switch(prompt){ - case IUserAuthenticator.OK_ID: - buttons[i]=IDialogConstants.OK_LABEL; - break; - case IUserAuthenticator.CANCEL_ID: - buttons[i]=IDialogConstants.CANCEL_LABEL; - break; - case IUserAuthenticator.NO_ID: - buttons[i]=IDialogConstants.NO_LABEL; - break; - case IUserAuthenticator.YES_ID: - buttons[i]=IDialogConstants.YES_LABEL; - break; - } - } + final String title, final String message, final int[] promptResponses, + final int defaultResponse){ + final Display display=getStandardDisplay(); + final int[] retval=new int[1]; + final String[] buttons=new String[promptResponses.length]; + for(int i=0; i<promptResponses.length; i++){ + int prompt=promptResponses[i]; + switch(prompt){ + case IUserAuthenticator.OK_ID: + buttons[i]=IDialogConstants.OK_LABEL; + break; + case IUserAuthenticator.CANCEL_ID: + buttons[i]=IDialogConstants.CANCEL_LABEL; + break; + case IUserAuthenticator.NO_ID: + buttons[i]=IDialogConstants.NO_LABEL; + break; + case IUserAuthenticator.YES_ID: + buttons[i]=IDialogConstants.YES_LABEL; + break; + } + } display.syncExec(() -> { Shell shell = null; @@ -207,35 +207,35 @@ public int prompt(IJSchLocation location, final int promptType, shell = new Shell(display); } final MessageDialog dialog = new MessageDialog(shell, title, - null, message, promptType, buttons, 1); - retval[0]=dialog.open(); + null, message, promptType, buttons, 1); + retval[0]=dialog.open(); }); - return retval[0]; - } + return retval[0]; + } - @Override + @Override public boolean promptForHostKeyChange(final IJSchLocation location){ - final boolean[] openConfirm=new boolean[] {false}; - final Display display=getStandardDisplay(); + final boolean[] openConfirm=new boolean[] {false}; + final Display display=getStandardDisplay(); display.syncExec(() -> openConfirm[0] = MessageDialog.openConfirm(null, Messages.WorkbenchUserAuthenticator_1, NLS.bind(Messages.WorkbenchUserAuthenticator_2, new String[] { location.getHost() }))); - if(!openConfirm[0]){ - throw new OperationCanceledException(); - } - return openConfirm[0]; - } - - /** - * Returns the standard display to be used. The method first checks, if - * the thread calling this method has an associated display. If so, this - * display is returned. Otherwise the method returns the default display. - * @return standard display - */ - private Display getStandardDisplay(){ - Display display=Display.getCurrent(); - if(display==null){ - display=Display.getDefault(); - } - return display; - } + if(!openConfirm[0]){ + throw new OperationCanceledException(); + } + return openConfirm[0]; + } + + /** + * Returns the standard display to be used. The method first checks, if + * the thread calling this method has an associated display. If so, this + * display is returned. Otherwise the method returns the default display. + * @return standard display + */ + private Display getStandardDisplay(){ + Display display=Display.getCurrent(); + if(display==null){ + display=Display.getDefault(); + } + return display; + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/ExportDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/ExportDialog.java index b7cb27825..df4c889aa 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/ExportDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/ExportDialog.java @@ -28,76 +28,76 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; class ExportDialog extends Dialog{ - protected Text field; - protected String target=null; - protected String title=null; - protected String message=null; + protected Text field; + protected String target=null; + protected String title=null; + protected String message=null; - public ExportDialog(Shell parentShell, String title, String message){ - super(parentShell); - this.title=title; - this.message=message; - } + public ExportDialog(Shell parentShell, String title, String message){ + super(parentShell); + this.title=title; + this.message=message; + } - protected void configureShell(Shell newShell){ - super.configureShell(newShell); - newShell.setText(title); - } + protected void configureShell(Shell newShell){ + super.configureShell(newShell); + newShell.setText(title); + } - public void create(){ - super.create(); - field.setFocus(); - } + public void create(){ + super.create(); + field.setFocus(); + } - protected Control createDialogArea(Composite parent){ - initializeDialogUnits(parent); - Composite main=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=2; - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); + protected Control createDialogArea(Composite parent){ + initializeDialogUnits(parent); + Composite main=new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.numColumns=2; + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_BOTH)); - if(message!=null){ - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=2; - messageLabel.setLayoutData(data); - } + if(message!=null){ + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(message); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=2; + messageLabel.setLayoutData(data); + } - createTargetFields(main); - Dialog.applyDialogFont(main); - return main; - } + createTargetFields(main); + Dialog.applyDialogFont(main); + return main; + } - protected void createTargetFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.CVSSSH2PreferencePage_125); + protected void createTargetFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.CVSSSH2PreferencePage_125); - field=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - field.setLayoutData(data); - } + field=new Text(parent, SWT.BORDER); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + field.setLayoutData(data); + } - public String getTarget(){ - return target; - } + public String getTarget(){ + return target; + } - protected void okPressed(){ - String _target=field.getText(); - if(_target==null||_target.length()==0){ - return; - } - target=_target; - super.okPressed(); - } + protected void okPressed(){ + String _target=field.getText(); + if(_target==null||_target.length()==0){ + return; + } + target=_target; + super.okPressed(); + } - protected void cancelPressed(){ - target=null; - super.cancelPressed(); - } + protected void cancelPressed(){ + target=null; + super.cancelPressed(); + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PassphraseDialog.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PassphraseDialog.java index bd092f433..e30f18d4c 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PassphraseDialog.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PassphraseDialog.java @@ -28,77 +28,77 @@ import org.eclipse.swt.widgets.Text; class PassphraseDialog extends Dialog{ - protected Text passphraseField; - protected String passphrase=null; - protected String message=null; + protected Text passphraseField; + protected String passphrase=null; + protected String message=null; - public PassphraseDialog(Shell parentShell, String message){ - super(parentShell); - this.message=message; - } + public PassphraseDialog(Shell parentShell, String message){ + super(parentShell); + this.message=message; + } - protected void configureShell(Shell newShell){ - super.configureShell(newShell); - newShell.setText(message); - } + protected void configureShell(Shell newShell){ + super.configureShell(newShell); + newShell.setText(message); + } - public void create(){ - super.create(); - passphraseField.setFocus(); - } + public void create(){ + super.create(); + passphraseField.setFocus(); + } - protected Control createDialogArea(Composite parent){ - initializeDialogUnits(parent); - Composite main=new Composite(parent, SWT.NONE); + protected Control createDialogArea(Composite parent){ + initializeDialogUnits(parent); + Composite main=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); + GridLayout layout=new GridLayout(); + layout.numColumns=3; + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_BOTH)); - if(message!=null){ - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } + if(message!=null){ + Label messageLabel=new Label(main, SWT.WRAP); + messageLabel.setText(message); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan=3; + messageLabel.setLayoutData(data); + } - createPassphraseFields(main); - Dialog.applyDialogFont(main); - return main; - } + createPassphraseFields(main); + Dialog.applyDialogFont(main); + return main; + } - protected void createPassphraseFields(Composite parent){ - new Label(parent, SWT.NONE).setText(Messages.CVSSSH2PreferencePage_127); - passphraseField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - passphraseField.setLayoutData(data); - passphraseField.setEchoChar('*'); + protected void createPassphraseFields(Composite parent){ + new Label(parent, SWT.NONE).setText(Messages.CVSSSH2PreferencePage_127); + passphraseField=new Text(parent, SWT.BORDER); + GridData data=new GridData(GridData.FILL_HORIZONTAL); + data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + passphraseField.setLayoutData(data); + passphraseField.setEchoChar('*'); - new Label(parent, SWT.NONE); - } + new Label(parent, SWT.NONE); + } - public String getPassphrase(){ - return passphrase; - } + public String getPassphrase(){ + return passphrase; + } - protected void okPressed(){ - String _passphrase=passphraseField.getText(); - if(_passphrase==null||_passphrase.length()==0){ - return; - } - passphrase=_passphrase; - super.okPressed(); - } + protected void okPressed(){ + String _passphrase=passphraseField.getText(); + if(_passphrase==null||_passphrase.length()==0){ + return; + } + passphrase=_passphrase; + super.okPressed(); + } - protected void cancelPressed(){ - passphrase=null; - super.cancelPressed(); - } + protected void cancelPressed(){ + passphrase=null; + super.cancelPressed(); + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PixelConverter.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PixelConverter.java index 73198c8c5..4a6fc150c 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PixelConverter.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PixelConverter.java @@ -25,12 +25,12 @@ public class PixelConverter { public PixelConverter(Control control) { GC gc = new GC(control); - try { - gc.setFont(control.getFont()); - fFontMetrics= gc.getFontMetrics(); - } finally { - gc.dispose(); - } + try { + gc.setFont(control.getFont()); + fFontMetrics= gc.getFontMetrics(); + } finally { + gc.dispose(); + } } public int convertHeightInCharsToPixels(int chars) { diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java index 5685e34c0..6544592a8 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java @@ -86,416 +86,416 @@ import com.jcraft.jsch.SftpATTRS; import com.jcraft.jsch.SftpException; public class PreferencePage extends org.eclipse.jface.preference.PreferencePage - implements IWorkbenchPreferencePage{ - - private static final String SSH2_PREFERENCE_PAGE_CONTEXT="org.eclipse.jsch.ui.ssh2_preference_page_context"; //$NON-NLS-1$ - - private Label ssh2HomeLabel; - private Label privateKeyLabel; - Text ssh2HomeText; - Text privateKeyText; - private Button privateKeyAdd; - - private Button ssh2HomeBrowse; - Button keyGenerateDSA; - Button keyGenerateRSA; - private Button keyLoad; - private Button keyExport; - Button saveKeyPair; - private Label keyCommentLabel; - Text keyCommentText; - private Label keyFingerPrintLabel; - Text keyFingerPrintText; - private Label keyPassphrase1Label; - Text keyPassphrase1Text; - private Label keyPassphrase2Label; - Text keyPassphrase2Text; - private Label publicKeylabel; - Text publicKeyText; - KeyPair kpair=null; - String kpairComment; - - public static final String AUTH_SCHEME="";//$NON-NLS-1$ - - public PreferencePage(){ - setDescription(Messages.CVSSSH2PreferencePage_18); - } - - @Override + implements IWorkbenchPreferencePage{ + + private static final String SSH2_PREFERENCE_PAGE_CONTEXT="org.eclipse.jsch.ui.ssh2_preference_page_context"; //$NON-NLS-1$ + + private Label ssh2HomeLabel; + private Label privateKeyLabel; + Text ssh2HomeText; + Text privateKeyText; + private Button privateKeyAdd; + + private Button ssh2HomeBrowse; + Button keyGenerateDSA; + Button keyGenerateRSA; + private Button keyLoad; + private Button keyExport; + Button saveKeyPair; + private Label keyCommentLabel; + Text keyCommentText; + private Label keyFingerPrintLabel; + Text keyFingerPrintText; + private Label keyPassphrase1Label; + Text keyPassphrase1Text; + private Label keyPassphrase2Label; + Text keyPassphrase2Text; + private Label publicKeylabel; + Text publicKeyText; + KeyPair kpair=null; + String kpairComment; + + public static final String AUTH_SCHEME="";//$NON-NLS-1$ + + public PreferencePage(){ + setDescription(Messages.CVSSSH2PreferencePage_18); + } + + @Override protected Control createContents(Composite parent){ - Composite container=new Composite(parent, SWT.NULL); - GridLayout layout=new GridLayout(); - container.setLayout(layout); - initializeDialogUnits(container); - - CTabFolder tabFolder=new CTabFolder(container, SWT.NONE); - tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); - - CTabItem tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_19); - tabItem.setControl(createGeneralPage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_21); - tabItem.setControl(createKeyManagementPage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_133); - tabItem.setControl(createHostKeyManagementPage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_137); - tabItem.setControl(createPreferredAuthenticationPage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_144); - tabItem.setControl(createPreferredKeyExchangePage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_145); - tabItem.setControl(createPreferredMACPage(tabFolder)); - - tabItem=new CTabItem(tabFolder, SWT.NONE); - tabItem.setText(Messages.CVSSSH2PreferencePage_146); - tabItem.setControl(createPreferredSSHAgentPage(tabFolder)); - tabFolder.setSelection(0); - initControls(); - - Dialog.applyDialogFont(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), - SSH2_PREFERENCE_PAGE_CONTEXT); - return container; - } - - private Control createGeneralPage(Composite parent){ - Composite group=new Composite(parent, SWT.NULL); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - group.setLayout(layout); - GridData data=new GridData(); - data.horizontalAlignment=GridData.FILL; - group.setLayoutData(data); - - ssh2HomeLabel=new Label(group, SWT.NONE); - ssh2HomeLabel.setText(Messages.CVSSSH2PreferencePage_23); - - ssh2HomeText=new Text(group, SWT.SINGLE|SWT.BORDER); - ssh2HomeText.setFont(group.getFont()); - GridData gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=1; - ssh2HomeText.setLayoutData(gd); - - ssh2HomeBrowse=new Button(group, SWT.NULL); - ssh2HomeBrowse.setText(Messages.CVSSSH2PreferencePage_24); - gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan=1; - ssh2HomeBrowse.setLayoutData(gd); - - createSpacer(group, 3); - - privateKeyLabel=new Label(group, SWT.NONE); - privateKeyLabel.setText(Messages.CVSSSH2PreferencePage_25); - - privateKeyText=new Text(group, SWT.SINGLE|SWT.BORDER); - privateKeyText.setFont(group.getFont()); - gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=1; - privateKeyText.setLayoutData(gd); - - privateKeyAdd=new Button(group, SWT.NULL); - privateKeyAdd.setText(Messages.CVSSSH2PreferencePage_26); - gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gd.horizontalSpan=1; - privateKeyAdd.setLayoutData(gd); - - ssh2HomeBrowse.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - String home=ssh2HomeText.getText(); - - if(!new File(home).exists()){ - while(true){ - int foo=home.lastIndexOf(java.io.File.separator, home.length()); - if(foo==-1) - break; - home=home.substring(0, foo); - if(new File(home).exists()) - break; - } - } - - DirectoryDialog dd=new DirectoryDialog(getShell()); - dd.setFilterPath(home); - dd.setMessage(Messages.CVSSSH2PreferencePage_27); - String dir=dd.open(); - if(dir==null){ // cancel - return; - } - ssh2HomeText.setText(dir); - } - }); - - privateKeyAdd.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - String home=ssh2HomeText.getText(); - - FileDialog fd=new FileDialog(getShell(), SWT.OPEN|SWT.MULTI); - fd.setFilterPath(home); - Object o=fd.open(); - if(o==null){ // cancel - return; - } - String[] files=fd.getFileNames(); - String keys=privateKeyText.getText(); - String dir=fd.getFilterPath(); - if(dir.equals(home)){ - dir="";} //$NON-NLS-1$ - else{ - dir+=java.io.File.separator; - } - - for(int i=0; i<files.length; i++){ - String foo=files[i]; - if(keys.length()!=0) - keys=keys+","; //$NON-NLS-1$ - keys=keys+dir+foo; - } - privateKeyText.setText(keys); - } - }); - - return group; - } - - private Control createKeyManagementPage(Composite parent){ - int columnSpan=3; - Composite group=new Composite(parent, SWT.NULL); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - group.setLayout(layout); - GridData gd=new GridData(); - gd.horizontalAlignment=GridData.FILL; - group.setLayoutData(gd); - - keyGenerateDSA=new Button(group, SWT.NULL); - keyGenerateDSA.setText(Messages.CVSSSH2PreferencePage_131); - gd=new GridData(); - gd.horizontalSpan=1; - keyGenerateDSA.setLayoutData(gd); - - keyGenerateRSA=new Button(group, SWT.NULL); - keyGenerateRSA.setText(Messages.CVSSSH2PreferencePage_132); - gd=new GridData(); - gd.horizontalSpan=1; - keyGenerateRSA.setLayoutData(gd); - - keyLoad=new Button(group, SWT.NULL); - keyLoad.setText(Messages.CVSSSH2PreferencePage_128); - gd=new GridData(); - gd.horizontalSpan=1; - keyLoad.setLayoutData(gd); - - publicKeylabel=new Label(group, SWT.NONE); - publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39); - gd=new GridData(); - gd.horizontalSpan=columnSpan; - publicKeylabel.setLayoutData(gd); - - publicKeyText=new Text(group, SWT.MULTI|SWT.BORDER|SWT.V_SCROLL|SWT.WRAP|SWT.LEFT_TO_RIGHT); - publicKeyText.setText(""); //$NON-NLS-1$ - publicKeyText.setEditable(false); - gd=new GridData(); - gd.horizontalSpan=columnSpan; - gd.horizontalAlignment=GridData.FILL; - gd.verticalAlignment=GridData.FILL; - gd.grabExcessHorizontalSpace=true; - gd.grabExcessVerticalSpace=true; - publicKeyText.setLayoutData(gd); - - keyFingerPrintLabel=new Label(group, SWT.NONE); - keyFingerPrintLabel.setText(Messages.CVSSSH2PreferencePage_41); - keyFingerPrintText=new Text(group, SWT.SINGLE|SWT.BORDER|SWT.LEFT_TO_RIGHT); - keyFingerPrintText.setFont(group.getFont()); - keyFingerPrintText.setEditable(false); - gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=2; - keyFingerPrintText.setLayoutData(gd); - - keyCommentLabel=new Label(group, SWT.NONE); - keyCommentLabel.setText(Messages.CVSSSH2PreferencePage_42); - keyCommentText=new Text(group, SWT.SINGLE|SWT.BORDER); - keyCommentText.setFont(group.getFont()); - gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=2; - keyCommentText.setLayoutData(gd); + Composite container=new Composite(parent, SWT.NULL); + GridLayout layout=new GridLayout(); + container.setLayout(layout); + initializeDialogUnits(container); + + CTabFolder tabFolder=new CTabFolder(container, SWT.NONE); + tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); + + CTabItem tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_19); + tabItem.setControl(createGeneralPage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_21); + tabItem.setControl(createKeyManagementPage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_133); + tabItem.setControl(createHostKeyManagementPage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_137); + tabItem.setControl(createPreferredAuthenticationPage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_144); + tabItem.setControl(createPreferredKeyExchangePage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_145); + tabItem.setControl(createPreferredMACPage(tabFolder)); + + tabItem=new CTabItem(tabFolder, SWT.NONE); + tabItem.setText(Messages.CVSSSH2PreferencePage_146); + tabItem.setControl(createPreferredSSHAgentPage(tabFolder)); + tabFolder.setSelection(0); + initControls(); + + Dialog.applyDialogFont(parent); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), + SSH2_PREFERENCE_PAGE_CONTEXT); + return container; + } + + private Control createGeneralPage(Composite parent){ + Composite group=new Composite(parent, SWT.NULL); + GridLayout layout=new GridLayout(); + layout.numColumns=3; + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + group.setLayout(layout); + GridData data=new GridData(); + data.horizontalAlignment=GridData.FILL; + group.setLayoutData(data); + + ssh2HomeLabel=new Label(group, SWT.NONE); + ssh2HomeLabel.setText(Messages.CVSSSH2PreferencePage_23); + + ssh2HomeText=new Text(group, SWT.SINGLE|SWT.BORDER); + ssh2HomeText.setFont(group.getFont()); + GridData gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=1; + ssh2HomeText.setLayoutData(gd); + + ssh2HomeBrowse=new Button(group, SWT.NULL); + ssh2HomeBrowse.setText(Messages.CVSSSH2PreferencePage_24); + gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan=1; + ssh2HomeBrowse.setLayoutData(gd); + + createSpacer(group, 3); + + privateKeyLabel=new Label(group, SWT.NONE); + privateKeyLabel.setText(Messages.CVSSSH2PreferencePage_25); + + privateKeyText=new Text(group, SWT.SINGLE|SWT.BORDER); + privateKeyText.setFont(group.getFont()); + gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=1; + privateKeyText.setLayoutData(gd); + + privateKeyAdd=new Button(group, SWT.NULL); + privateKeyAdd.setText(Messages.CVSSSH2PreferencePage_26); + gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan=1; + privateKeyAdd.setLayoutData(gd); + + ssh2HomeBrowse.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + String home=ssh2HomeText.getText(); + + if(!new File(home).exists()){ + while(true){ + int foo=home.lastIndexOf(java.io.File.separator, home.length()); + if(foo==-1) + break; + home=home.substring(0, foo); + if(new File(home).exists()) + break; + } + } + + DirectoryDialog dd=new DirectoryDialog(getShell()); + dd.setFilterPath(home); + dd.setMessage(Messages.CVSSSH2PreferencePage_27); + String dir=dd.open(); + if(dir==null){ // cancel + return; + } + ssh2HomeText.setText(dir); + } + }); + + privateKeyAdd.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + String home=ssh2HomeText.getText(); + + FileDialog fd=new FileDialog(getShell(), SWT.OPEN|SWT.MULTI); + fd.setFilterPath(home); + Object o=fd.open(); + if(o==null){ // cancel + return; + } + String[] files=fd.getFileNames(); + String keys=privateKeyText.getText(); + String dir=fd.getFilterPath(); + if(dir.equals(home)){ + dir="";} //$NON-NLS-1$ + else{ + dir+=java.io.File.separator; + } + + for(int i=0; i<files.length; i++){ + String foo=files[i]; + if(keys.length()!=0) + keys=keys+","; //$NON-NLS-1$ + keys=keys+dir+foo; + } + privateKeyText.setText(keys); + } + }); + + return group; + } + + private Control createKeyManagementPage(Composite parent){ + int columnSpan=3; + Composite group=new Composite(parent, SWT.NULL); + GridLayout layout=new GridLayout(); + layout.numColumns=3; + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + group.setLayout(layout); + GridData gd=new GridData(); + gd.horizontalAlignment=GridData.FILL; + group.setLayoutData(gd); + + keyGenerateDSA=new Button(group, SWT.NULL); + keyGenerateDSA.setText(Messages.CVSSSH2PreferencePage_131); + gd=new GridData(); + gd.horizontalSpan=1; + keyGenerateDSA.setLayoutData(gd); + + keyGenerateRSA=new Button(group, SWT.NULL); + keyGenerateRSA.setText(Messages.CVSSSH2PreferencePage_132); + gd=new GridData(); + gd.horizontalSpan=1; + keyGenerateRSA.setLayoutData(gd); + + keyLoad=new Button(group, SWT.NULL); + keyLoad.setText(Messages.CVSSSH2PreferencePage_128); + gd=new GridData(); + gd.horizontalSpan=1; + keyLoad.setLayoutData(gd); + + publicKeylabel=new Label(group, SWT.NONE); + publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39); + gd=new GridData(); + gd.horizontalSpan=columnSpan; + publicKeylabel.setLayoutData(gd); + + publicKeyText=new Text(group, SWT.MULTI|SWT.BORDER|SWT.V_SCROLL|SWT.WRAP|SWT.LEFT_TO_RIGHT); + publicKeyText.setText(""); //$NON-NLS-1$ + publicKeyText.setEditable(false); + gd=new GridData(); + gd.horizontalSpan=columnSpan; + gd.horizontalAlignment=GridData.FILL; + gd.verticalAlignment=GridData.FILL; + gd.grabExcessHorizontalSpace=true; + gd.grabExcessVerticalSpace=true; + publicKeyText.setLayoutData(gd); + + keyFingerPrintLabel=new Label(group, SWT.NONE); + keyFingerPrintLabel.setText(Messages.CVSSSH2PreferencePage_41); + keyFingerPrintText=new Text(group, SWT.SINGLE|SWT.BORDER|SWT.LEFT_TO_RIGHT); + keyFingerPrintText.setFont(group.getFont()); + keyFingerPrintText.setEditable(false); + gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=2; + keyFingerPrintText.setLayoutData(gd); + + keyCommentLabel=new Label(group, SWT.NONE); + keyCommentLabel.setText(Messages.CVSSSH2PreferencePage_42); + keyCommentText=new Text(group, SWT.SINGLE|SWT.BORDER); + keyCommentText.setFont(group.getFont()); + gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=2; + keyCommentText.setLayoutData(gd); keyCommentText.addModifyListener(e -> { - if(kpair==null) - return; - try{ - ByteArrayOutputStream out=new ByteArrayOutputStream(); - kpairComment = keyCommentText.getText(); - kpair.writePublicKey(out, kpairComment); - out.close(); - publicKeyText.setText(out.toString()); - } - catch(IOException ee){ - // Ignore - } + if(kpair==null) + return; + try{ + ByteArrayOutputStream out=new ByteArrayOutputStream(); + kpairComment = keyCommentText.getText(); + kpair.writePublicKey(out, kpairComment); + out.close(); + publicKeyText.setText(out.toString()); + } + catch(IOException ee){ + // Ignore + } }); - keyPassphrase1Label=new Label(group, SWT.NONE); - keyPassphrase1Label.setText(Messages.CVSSSH2PreferencePage_43); - keyPassphrase1Text=new Text(group, SWT.SINGLE|SWT.BORDER); - keyPassphrase1Text.setFont(group.getFont()); - keyPassphrase1Text.setEchoChar('*'); - gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=2; - keyPassphrase1Text.setLayoutData(gd); - - keyPassphrase2Label=new Label(group, SWT.NONE); - keyPassphrase2Label.setText(Messages.CVSSSH2PreferencePage_44); - keyPassphrase2Text=new Text(group, SWT.SINGLE|SWT.BORDER); - keyPassphrase2Text.setFont(group.getFont()); - keyPassphrase2Text.setEchoChar('*'); - gd=new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan=2; - keyPassphrase2Text.setLayoutData(gd); + keyPassphrase1Label=new Label(group, SWT.NONE); + keyPassphrase1Label.setText(Messages.CVSSSH2PreferencePage_43); + keyPassphrase1Text=new Text(group, SWT.SINGLE|SWT.BORDER); + keyPassphrase1Text.setFont(group.getFont()); + keyPassphrase1Text.setEchoChar('*'); + gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=2; + keyPassphrase1Text.setLayoutData(gd); + + keyPassphrase2Label=new Label(group, SWT.NONE); + keyPassphrase2Label.setText(Messages.CVSSSH2PreferencePage_44); + keyPassphrase2Text=new Text(group, SWT.SINGLE|SWT.BORDER); + keyPassphrase2Text.setFont(group.getFont()); + keyPassphrase2Text.setEchoChar('*'); + gd=new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan=2; + keyPassphrase2Text.setLayoutData(gd); keyPassphrase1Text.addModifyListener(e -> { - String pass1=keyPassphrase1Text.getText(); - String pass2=keyPassphrase2Text.getText(); - if(kpair!=null&&pass1.equals(pass2)){ - saveKeyPair.setEnabled(true); - } - else{ - saveKeyPair.setEnabled(false); - } - if(pass2.length()==0){ - setErrorMessage(null); - return; - } - if(pass1.equals(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } + String pass1=keyPassphrase1Text.getText(); + String pass2=keyPassphrase2Text.getText(); + if(kpair!=null&&pass1.equals(pass2)){ + saveKeyPair.setEnabled(true); + } + else{ + saveKeyPair.setEnabled(false); + } + if(pass2.length()==0){ + setErrorMessage(null); + return; + } + if(pass1.equals(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } }); keyPassphrase2Text.addModifyListener(e -> { - String pass1=keyPassphrase1Text.getText(); - String pass2=keyPassphrase2Text.getText(); - if(kpair!=null&&pass1.equals(pass2)){ - saveKeyPair.setEnabled(true); - } - else{ - saveKeyPair.setEnabled(false); - } - if(pass2.length()<pass1.length()){ - if(pass1.startsWith(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } - return; - } - if(pass1.equals(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } + String pass1=keyPassphrase1Text.getText(); + String pass2=keyPassphrase2Text.getText(); + if(kpair!=null&&pass1.equals(pass2)){ + saveKeyPair.setEnabled(true); + } + else{ + saveKeyPair.setEnabled(false); + } + if(pass2.length()<pass1.length()){ + if(pass1.startsWith(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } + return; + } + if(pass1.equals(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } }); - keyPassphrase2Text.addFocusListener(new FocusListener(){ - @Override - public void focusGained(FocusEvent e){ - String pass1=keyPassphrase1Text.getText(); - String pass2=keyPassphrase2Text.getText(); - if(pass2.length()<pass1.length()){ - if(pass1.startsWith(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } - return; - } - if(pass1.equals(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } - } - - @Override - public void focusLost(FocusEvent e){ - String pass1=keyPassphrase1Text.getText(); - String pass2=keyPassphrase2Text.getText(); - if(pass1.equals(pass2)){ - setErrorMessage(null); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_48); - } - } - }); - - Composite buttons=new Composite(group, SWT.NONE); - layout=new GridLayout(2, true); - layout.marginWidth=0; - layout.marginHeight=0; - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - buttons.setLayout(layout); - gd=new GridData(GridData.HORIZONTAL_ALIGN_END); - gd.horizontalSpan=columnSpan; - buttons.setLayoutData(gd); - - keyExport=new Button(buttons, SWT.NULL); - keyExport.setText(Messages.CVSSSH2PreferencePage_105); - gd=new GridData(GridData.FILL_BOTH); - keyExport.setLayoutData(gd); - - saveKeyPair=new Button(buttons, SWT.NULL); - saveKeyPair.setText(Messages.CVSSSH2PreferencePage_45); - gd=new GridData(GridData.FILL_BOTH); - saveKeyPair.setLayoutData(gd); - - SelectionAdapter keygenadapter=new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - boolean ok=true; - String _type=""; //$NON-NLS-1$ - - try{ - int type=0; - if(e.widget==keyGenerateDSA){ - type=KeyPair.DSA; - _type=IConstants.DSA; - } - else if(e.widget==keyGenerateRSA){ - type=KeyPair.RSA; - _type=IConstants.RSA; - } - else{ - return; - } - - final KeyPair[] _kpair=new KeyPair[1]; - final int __type=type; - final JSchException[] _e=new JSchException[1]; + keyPassphrase2Text.addFocusListener(new FocusListener(){ + @Override + public void focusGained(FocusEvent e){ + String pass1=keyPassphrase1Text.getText(); + String pass2=keyPassphrase2Text.getText(); + if(pass2.length()<pass1.length()){ + if(pass1.startsWith(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } + return; + } + if(pass1.equals(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } + } + + @Override + public void focusLost(FocusEvent e){ + String pass1=keyPassphrase1Text.getText(); + String pass2=keyPassphrase2Text.getText(); + if(pass1.equals(pass2)){ + setErrorMessage(null); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_48); + } + } + }); + + Composite buttons=new Composite(group, SWT.NONE); + layout=new GridLayout(2, true); + layout.marginWidth=0; + layout.marginHeight=0; + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + buttons.setLayout(layout); + gd=new GridData(GridData.HORIZONTAL_ALIGN_END); + gd.horizontalSpan=columnSpan; + buttons.setLayoutData(gd); + + keyExport=new Button(buttons, SWT.NULL); + keyExport.setText(Messages.CVSSSH2PreferencePage_105); + gd=new GridData(GridData.FILL_BOTH); + keyExport.setLayoutData(gd); + + saveKeyPair=new Button(buttons, SWT.NULL); + saveKeyPair.setText(Messages.CVSSSH2PreferencePage_45); + gd=new GridData(GridData.FILL_BOTH); + saveKeyPair.setLayoutData(gd); + + SelectionAdapter keygenadapter=new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + boolean ok=true; + String _type=""; //$NON-NLS-1$ + + try{ + int type=0; + if(e.widget==keyGenerateDSA){ + type=KeyPair.DSA; + _type=IConstants.DSA; + } + else if(e.widget==keyGenerateRSA){ + type=KeyPair.RSA; + _type=IConstants.RSA; + } + else{ + return; + } + + final KeyPair[] _kpair=new KeyPair[1]; + final int __type=type; + final JSchException[] _e=new JSchException[1]; BusyIndicator.showWhile(getShell().getDisplay(), () -> { try { _kpair[0] = KeyPair.genKeyPair(getJSch(), __type); @@ -503,148 +503,148 @@ protected Control createContents(Composite parent){ _e[0] = e1; } }); - if(_e[0]!=null){ - throw _e[0]; - } - kpair=_kpair[0]; - - ByteArrayOutputStream out=new ByteArrayOutputStream(); - kpairComment=_type+"-1024"; //$NON-NLS-1$ - kpair.writePublicKey(out, kpairComment); - out.close(); - publicKeyText.setText(out.toString()); - keyFingerPrintText.setText(kpair.getFingerPrint()); - keyCommentText.setText(kpairComment); - keyPassphrase1Text.setText(""); //$NON-NLS-1$ - keyPassphrase2Text.setText(""); //$NON-NLS-1$ - updateControls(); - } - catch(IOException ee){ - ok=false; - } - catch(JSchException ee){ - ok=false; - } - if(!ok){ - MessageDialog.openError(getShell(), - Messages.CVSSSH2PreferencePage_error, - Messages.CVSSSH2PreferencePage_47); - } - } - }; - keyGenerateDSA.addSelectionListener(keygenadapter); - keyGenerateRSA.addSelectionListener(keygenadapter); - - keyLoad.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - boolean ok=true; - String home=ssh2HomeText.getText(); - FileDialog fd=new FileDialog(getShell(), SWT.OPEN); - fd.setFilterPath(home); - Object o=fd.open(); - if(o==null){ // cancel - return; - } - String pkey=fd.getFileName(); - String pkeyab=(new File(fd.getFilterPath(), pkey)).getAbsolutePath(); - try{ - KeyPair _kpair=KeyPair.load(getJSch(), pkeyab); - PassphrasePrompt prompt=null; - while(_kpair.isEncrypted()){ - if(prompt==null){ - prompt=new PassphrasePrompt(NLS.bind( - Messages.CVSSSH2PreferencePage_126, new String[] {pkey})); - } - Display.getDefault().syncExec(prompt); - String passphrase=prompt.getPassphrase(); - if(passphrase==null) - break; - if(_kpair.decrypt(passphrase)){ - break; - } - MessageDialog.openError(getShell(), - Messages.CVSSSH2PreferencePage_error, NLS.bind( - Messages.CVSSSH2PreferencePage_129, new String[] {pkey})); - } - if(_kpair.isEncrypted()){ - return; - } - kpair=_kpair; - String _type=(kpair.getKeyType()==KeyPair.DSA) ? IConstants.DSA - : IConstants.RSA; - kpairComment=_type+"-1024"; //$NON-NLS-1$ - - // TODO Bug 351094 The comment should be from kpair object, - // but the JSch API does not provided such a method. - // In the version 0.1.45, JSch will support such a method, - // and the following code should be replaced with it at that time. - java.io.FileInputStream fis=null; - try{ - java.io.File f=new java.io.File(pkeyab+".pub"); //$NON-NLS-1$ - int i=0; - fis=new java.io.FileInputStream(f); - byte[] buf=new byte[(int)f.length()]; - while(i<buf.length){ - int j=fis.read(buf, i, buf.length-i); - if(j<=0) - break; - i+=j; - } - String pubkey=new String(buf); - if(pubkey.indexOf(' ')>0 - &&pubkey.indexOf(' ', pubkey.indexOf(' ')+1)>0){ - int j=pubkey.indexOf(' ', pubkey.indexOf(' ')+1)+1; - kpairComment=pubkey.substring(j); - if(kpairComment.indexOf('\n')>0){ - kpairComment=kpairComment.substring(0, - kpairComment.indexOf('\n')); - } - } - } - catch(IOException ioe){ - // ignore if public-key does not exist. - } - finally{ - if(fis!=null) - fis.close(); - } - - ByteArrayOutputStream out=new ByteArrayOutputStream(); - - kpair.writePublicKey(out, kpairComment); - out.close(); - publicKeyText.setText(out.toString()); - keyFingerPrintText.setText(kpair.getFingerPrint()); - keyCommentText.setText(kpairComment); - keyPassphrase1Text.setText(""); //$NON-NLS-1$ - keyPassphrase2Text.setText(""); //$NON-NLS-1$ - updateControls(); - } - catch(IOException ee){ - ok=false; - } - catch(JSchException ee){ - ok=false; - } - if(!ok){ - MessageDialog.openError(getShell(), - Messages.CVSSSH2PreferencePage_error, - Messages.CVSSSH2PreferencePage_130); - } - } - }); - - keyExport.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e){ - if(kpair==null) - return; + if(_e[0]!=null){ + throw _e[0]; + } + kpair=_kpair[0]; + + ByteArrayOutputStream out=new ByteArrayOutputStream(); + kpairComment=_type+"-1024"; //$NON-NLS-1$ + kpair.writePublicKey(out, kpairComment); + out.close(); + publicKeyText.setText(out.toString()); + keyFingerPrintText.setText(kpair.getFingerPrint()); + keyCommentText.setText(kpairComment); + keyPassphrase1Text.setText(""); //$NON-NLS-1$ + keyPassphrase2Text.setText(""); //$NON-NLS-1$ + updateControls(); + } + catch(IOException ee){ + ok=false; + } + catch(JSchException ee){ + ok=false; + } + if(!ok){ + MessageDialog.openError(getShell(), + Messages.CVSSSH2PreferencePage_error, + Messages.CVSSSH2PreferencePage_47); + } + } + }; + keyGenerateDSA.addSelectionListener(keygenadapter); + keyGenerateRSA.addSelectionListener(keygenadapter); + + keyLoad.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + boolean ok=true; + String home=ssh2HomeText.getText(); + FileDialog fd=new FileDialog(getShell(), SWT.OPEN); + fd.setFilterPath(home); + Object o=fd.open(); + if(o==null){ // cancel + return; + } + String pkey=fd.getFileName(); + String pkeyab=(new File(fd.getFilterPath(), pkey)).getAbsolutePath(); + try{ + KeyPair _kpair=KeyPair.load(getJSch(), pkeyab); + PassphrasePrompt prompt=null; + while(_kpair.isEncrypted()){ + if(prompt==null){ + prompt=new PassphrasePrompt(NLS.bind( + Messages.CVSSSH2PreferencePage_126, new String[] {pkey})); + } + Display.getDefault().syncExec(prompt); + String passphrase=prompt.getPassphrase(); + if(passphrase==null) + break; + if(_kpair.decrypt(passphrase)){ + break; + } + MessageDialog.openError(getShell(), + Messages.CVSSSH2PreferencePage_error, NLS.bind( + Messages.CVSSSH2PreferencePage_129, new String[] {pkey})); + } + if(_kpair.isEncrypted()){ + return; + } + kpair=_kpair; + String _type=(kpair.getKeyType()==KeyPair.DSA) ? IConstants.DSA + : IConstants.RSA; + kpairComment=_type+"-1024"; //$NON-NLS-1$ + + // TODO Bug 351094 The comment should be from kpair object, + // but the JSch API does not provided such a method. + // In the version 0.1.45, JSch will support such a method, + // and the following code should be replaced with it at that time. + java.io.FileInputStream fis=null; + try{ + java.io.File f=new java.io.File(pkeyab+".pub"); //$NON-NLS-1$ + int i=0; + fis=new java.io.FileInputStream(f); + byte[] buf=new byte[(int)f.length()]; + while(i<buf.length){ + int j=fis.read(buf, i, buf.length-i); + if(j<=0) + break; + i+=j; + } + String pubkey=new String(buf); + if(pubkey.indexOf(' ')>0 + &&pubkey.indexOf(' ', pubkey.indexOf(' ')+1)>0){ + int j=pubkey.indexOf(' ', pubkey.indexOf(' ')+1)+1; + kpairComment=pubkey.substring(j); + if(kpairComment.indexOf('\n')>0){ + kpairComment=kpairComment.substring(0, + kpairComment.indexOf('\n')); + } + } + } + catch(IOException ioe){ + // ignore if public-key does not exist. + } + finally{ + if(fis!=null) + fis.close(); + } + + ByteArrayOutputStream out=new ByteArrayOutputStream(); + + kpair.writePublicKey(out, kpairComment); + out.close(); + publicKeyText.setText(out.toString()); + keyFingerPrintText.setText(kpair.getFingerPrint()); + keyCommentText.setText(kpairComment); + keyPassphrase1Text.setText(""); //$NON-NLS-1$ + keyPassphrase2Text.setText(""); //$NON-NLS-1$ + updateControls(); + } + catch(IOException ee){ + ok=false; + } + catch(JSchException ee){ + ok=false; + } + if(!ok){ + MessageDialog.openError(getShell(), + Messages.CVSSSH2PreferencePage_error, + Messages.CVSSSH2PreferencePage_130); + } + } + }); + + keyExport.addSelectionListener(new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e){ + if(kpair==null) + return; - setErrorMessage(null); + setErrorMessage(null); - final String[] target=new String[1]; - final String title=Messages.CVSSSH2PreferencePage_106; + final String[] target=new String[1]; + final String title=Messages.CVSSSH2PreferencePage_106; final String message = Messages.CVSSSH2PreferencePage_107; Display.getDefault().syncExec(() -> { Display display = Display.getCurrent(); @@ -657,1043 +657,1043 @@ protected Control createContents(Composite parent){ if (target[0] == null) { return; } - String user=""; //$NON-NLS-1$ - String host=""; //$NON-NLS-1$ - int port=22; - - if(target[0].indexOf('@')>0){ - user=target[0].substring(0, target[0].indexOf('@')); - host=target[0].substring(target[0].indexOf('@')+1); - } - if(host.indexOf(':')>0){ - try{ - port=Integer.parseInt(host.substring(host.indexOf(':')+1)); - } - catch(NumberFormatException ee){ - port=-1; - } - host=host.substring(0, host.indexOf(':')); - } - - if(user.length()==0||host.length()==0||port==-1){ - setErrorMessage(NLS.bind(Messages.CVSSSH2PreferencePage_108, - new String[] {target[0]})); - return; - } - - String options=""; //$NON-NLS-1$ - try{ - ByteArrayOutputStream bos=new ByteArrayOutputStream(); - if(options.length()!=0){ - try{ - bos.write((options+" ").getBytes());} //$NON-NLS-1$ - catch(IOException eeee){ - // Ignore - } - } - kpair.writePublicKey(bos, kpairComment); - bos.close(); - export_via_sftp(user, host, port, /* ".ssh/authorized_keys", //$NON-NLS-1$ */ - bos.toByteArray()); - } - catch(IOException ee){ - // Ignore - } - catch(JSchException ee){ - setErrorMessage(Messages.CVSSSH2PreferencePage_111); - } - } - }); - - saveKeyPair.addSelectionListener(new SelectionAdapter(){ - @Override + String user=""; //$NON-NLS-1$ + String host=""; //$NON-NLS-1$ + int port=22; + + if(target[0].indexOf('@')>0){ + user=target[0].substring(0, target[0].indexOf('@')); + host=target[0].substring(target[0].indexOf('@')+1); + } + if(host.indexOf(':')>0){ + try{ + port=Integer.parseInt(host.substring(host.indexOf(':')+1)); + } + catch(NumberFormatException ee){ + port=-1; + } + host=host.substring(0, host.indexOf(':')); + } + + if(user.length()==0||host.length()==0||port==-1){ + setErrorMessage(NLS.bind(Messages.CVSSSH2PreferencePage_108, + new String[] {target[0]})); + return; + } + + String options=""; //$NON-NLS-1$ + try{ + ByteArrayOutputStream bos=new ByteArrayOutputStream(); + if(options.length()!=0){ + try{ + bos.write((options+" ").getBytes());} //$NON-NLS-1$ + catch(IOException eeee){ + // Ignore + } + } + kpair.writePublicKey(bos, kpairComment); + bos.close(); + export_via_sftp(user, host, port, /* ".ssh/authorized_keys", //$NON-NLS-1$ */ + bos.toByteArray()); + } + catch(IOException ee){ + // Ignore + } + catch(JSchException ee){ + setErrorMessage(Messages.CVSSSH2PreferencePage_111); + } + } + }); + + saveKeyPair.addSelectionListener(new SelectionAdapter(){ + @Override public void widgetSelected(SelectionEvent e){ - if(kpair==null) - return; - - String pass=keyPassphrase1Text.getText(); - /* - * if(!pass.equals(keyPassphrase2Text.getText())){ - * setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); - * //$NON-NLS-1$ return; } - */ - if(pass.length()==0){ - if(!MessageDialog.openConfirm(getShell(), - Messages.CVSSSH2PreferencePage_confirmation, - Messages.CVSSSH2PreferencePage_49)){ - return; - } - } - - kpair.setPassphrase(pass); - - String home=ssh2HomeText.getText(); - - File _home=new File(home); - - if(!_home.exists()){ - if(!MessageDialog.openConfirm(getShell(), - Messages.CVSSSH2PreferencePage_confirmation, NLS.bind( - Messages.CVSSSH2PreferencePage_50, new String[] {home}))){ - return; - } - if(!_home.mkdirs()){ - setErrorMessage(Messages.CVSSSH2PreferencePage_100+home); - return; - } - } - - FileDialog fd=new FileDialog(getShell(), SWT.SAVE); - fd.setFilterPath(home); - String file=(kpair.getKeyType()==KeyPair.RSA) ? "id_rsa" : "id_dsa"; //$NON-NLS-1$ //$NON-NLS-2$ - fd.setFileName(file); - file=fd.open(); - if(file==null){ // cancel - return; - } - - if(new File(file).exists()){ - if(!MessageDialog.openConfirm(getShell(), - Messages.CVSSSH2PreferencePage_confirmation, // - NLS.bind(Messages.CVSSSH2PreferencePage_53, new String[] {file}))){ - return; - } - } - - boolean ok=true; - try{ - kpair.writePrivateKey(file); - kpair.writePublicKey(file+".pub", kpairComment); //$NON-NLS-1$ - } - catch(Exception ee){ - ok=false; - } - - if(ok){ - MessageDialog.openInformation(getShell(), - Messages.CVSSSH2PreferencePage_information, - Messages.CVSSSH2PreferencePage_55+"\n"+ //$NON-NLS-1$ - Messages.CVSSSH2PreferencePage_57+file+"\n"+ //$NON-NLS-1$ - Messages.CVSSSH2PreferencePage_59+file+".pub"); //$NON-NLS-1$ - } - else{ - return; - } - - // The generated key should be added to privateKeyText. - - String dir=fd.getFilterPath(); - File mypkey=new java.io.File(dir, fd.getFileName()); - String pkeys=privateKeyText.getText(); - - // Check if the generated key has been included in pkeys? - String[] pkeysa=pkeys.split(","); //$NON-NLS-1$ - for(int i=0; i<pkeysa.length; i++){ - File pkey=new java.io.File(pkeysa[i]); - if(!pkey.isAbsolute()){ - pkey=new java.io.File(home, pkeysa[i]); - } - if(pkey.equals(mypkey)) - return; - } - - if(dir.equals(home)){ - dir="";} //$NON-NLS-1$ - else{ - dir+=java.io.File.separator; - } - if(pkeys.length()>0) - pkeys+=","; //$NON-NLS-1$ - pkeys=pkeys+dir+fd.getFileName(); - privateKeyText.setText(pkeys); - } - }); - - return group; - } - - private TableViewer viewer; - private Button removeHostKeyButton; - - Table preferedAuthMethodTable; - Table preferedSSHAgentTable; - Table preferedKeyExchangeMethodTable; - Table preferedMACMethodTable; - - Button up; - Button down; - Button kex_up; - Button kex_down; - Button mac_up; - Button mac_down; - - class TableLabelProvider extends LabelProvider implements ITableLabelProvider{ - @Override - public String getColumnText(Object element, int columnIndex){ - HostKey entry=(HostKey)element; - switch(columnIndex){ - case 0: - return entry.getHost(); - case 1: - return entry.getType(); - case 2: - return entry.getFingerPrint(getJSch()); - default: - return null; - } - } - - @Override - public Image getColumnImage(Object element, int columnIndex){ - return null; - } - } - - private Control createHostKeyManagementPage(Composite parent){ - Composite group=new Composite(parent, SWT.NULL); - GridLayout layout=new GridLayout(); - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.numColumns=2; - group.setLayout(layout); - GridData gd=new GridData(); - gd.horizontalAlignment=GridData.FILL; - gd.verticalAlignment=GridData.FILL; - group.setLayoutData(gd); - - Label label=new Label(group, SWT.NONE); - label.setText(Messages.CVSSSH2PreferencePage_139); - gd=new GridData(); - gd.horizontalSpan=2; - label.setLayoutData(gd); - - viewer=new TableViewer(group, SWT.MULTI|SWT.FULL_SELECTION|SWT.H_SCROLL - |SWT.V_SCROLL|SWT.BORDER); - Table table=viewer.getTable(); - new TableEditor(table); - table.setHeaderVisible(true); - table.setLinesVisible(true); - gd=new GridData(GridData.FILL_BOTH); - gd.widthHint=convertWidthInCharsToPixels(30); - /* - * The hardcoded hint does not look elegant, but in reality it does not make - * anything bound to this 100-pixel value, because in any case the tree on - * the left is taller and that's what really determines the height. - */ - gd.heightHint=100; - table.setLayoutData(gd); + if(kpair==null) + return; + + String pass=keyPassphrase1Text.getText(); + /* + * if(!pass.equals(keyPassphrase2Text.getText())){ + * setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); + * //$NON-NLS-1$ return; } + */ + if(pass.length()==0){ + if(!MessageDialog.openConfirm(getShell(), + Messages.CVSSSH2PreferencePage_confirmation, + Messages.CVSSSH2PreferencePage_49)){ + return; + } + } + + kpair.setPassphrase(pass); + + String home=ssh2HomeText.getText(); + + File _home=new File(home); + + if(!_home.exists()){ + if(!MessageDialog.openConfirm(getShell(), + Messages.CVSSSH2PreferencePage_confirmation, NLS.bind( + Messages.CVSSSH2PreferencePage_50, new String[] {home}))){ + return; + } + if(!_home.mkdirs()){ + setErrorMessage(Messages.CVSSSH2PreferencePage_100+home); + return; + } + } + + FileDialog fd=new FileDialog(getShell(), SWT.SAVE); + fd.setFilterPath(home); + String file=(kpair.getKeyType()==KeyPair.RSA) ? "id_rsa" : "id_dsa"; //$NON-NLS-1$ //$NON-NLS-2$ + fd.setFileName(file); + file=fd.open(); + if(file==null){ // cancel + return; + } + + if(new File(file).exists()){ + if(!MessageDialog.openConfirm(getShell(), + Messages.CVSSSH2PreferencePage_confirmation, // + NLS.bind(Messages.CVSSSH2PreferencePage_53, new String[] {file}))){ + return; + } + } + + boolean ok=true; + try{ + kpair.writePrivateKey(file); + kpair.writePublicKey(file+".pub", kpairComment); //$NON-NLS-1$ + } + catch(Exception ee){ + ok=false; + } + + if(ok){ + MessageDialog.openInformation(getShell(), + Messages.CVSSSH2PreferencePage_information, + Messages.CVSSSH2PreferencePage_55+"\n"+ //$NON-NLS-1$ + Messages.CVSSSH2PreferencePage_57+file+"\n"+ //$NON-NLS-1$ + Messages.CVSSSH2PreferencePage_59+file+".pub"); //$NON-NLS-1$ + } + else{ + return; + } + + // The generated key should be added to privateKeyText. + + String dir=fd.getFilterPath(); + File mypkey=new java.io.File(dir, fd.getFileName()); + String pkeys=privateKeyText.getText(); + + // Check if the generated key has been included in pkeys? + String[] pkeysa=pkeys.split(","); //$NON-NLS-1$ + for(int i=0; i<pkeysa.length; i++){ + File pkey=new java.io.File(pkeysa[i]); + if(!pkey.isAbsolute()){ + pkey=new java.io.File(home, pkeysa[i]); + } + if(pkey.equals(mypkey)) + return; + } + + if(dir.equals(home)){ + dir="";} //$NON-NLS-1$ + else{ + dir+=java.io.File.separator; + } + if(pkeys.length()>0) + pkeys+=","; //$NON-NLS-1$ + pkeys=pkeys+dir+fd.getFileName(); + privateKeyText.setText(pkeys); + } + }); + + return group; + } + + private TableViewer viewer; + private Button removeHostKeyButton; + + Table preferedAuthMethodTable; + Table preferedSSHAgentTable; + Table preferedKeyExchangeMethodTable; + Table preferedMACMethodTable; + + Button up; + Button down; + Button kex_up; + Button kex_down; + Button mac_up; + Button mac_down; + + class TableLabelProvider extends LabelProvider implements ITableLabelProvider{ + @Override + public String getColumnText(Object element, int columnIndex){ + HostKey entry=(HostKey)element; + switch(columnIndex){ + case 0: + return entry.getHost(); + case 1: + return entry.getType(); + case 2: + return entry.getFingerPrint(getJSch()); + default: + return null; + } + } + + @Override + public Image getColumnImage(Object element, int columnIndex){ + return null; + } + } + + private Control createHostKeyManagementPage(Composite parent){ + Composite group=new Composite(parent, SWT.NULL); + GridLayout layout=new GridLayout(); + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns=2; + group.setLayout(layout); + GridData gd=new GridData(); + gd.horizontalAlignment=GridData.FILL; + gd.verticalAlignment=GridData.FILL; + group.setLayoutData(gd); + + Label label=new Label(group, SWT.NONE); + label.setText(Messages.CVSSSH2PreferencePage_139); + gd=new GridData(); + gd.horizontalSpan=2; + label.setLayoutData(gd); + + viewer=new TableViewer(group, SWT.MULTI|SWT.FULL_SELECTION|SWT.H_SCROLL + |SWT.V_SCROLL|SWT.BORDER); + Table table=viewer.getTable(); + new TableEditor(table); + table.setHeaderVisible(true); + table.setLinesVisible(true); + gd=new GridData(GridData.FILL_BOTH); + gd.widthHint=convertWidthInCharsToPixels(30); + /* + * The hardcoded hint does not look elegant, but in reality it does not make + * anything bound to this 100-pixel value, because in any case the tree on + * the left is taller and that's what really determines the height. + */ + gd.heightHint=100; + table.setLayoutData(gd); table.addListener(SWT.Selection, e -> handleSelection()); - // Create the table columns - new TableColumn(table, SWT.NULL); - new TableColumn(table, SWT.NULL); - new TableColumn(table, SWT.NULL); - TableColumn[] columns=table.getColumns(); - columns[0].setText(Messages.CVSSSH2PreferencePage_134); - columns[1].setText(Messages.CVSSSH2PreferencePage_135); - columns[2].setText(Messages.CVSSSH2PreferencePage_136); - viewer.setColumnProperties(new String[] { - Messages.CVSSSH2PreferencePage_134, // - Messages.CVSSSH2PreferencePage_135, // - Messages.CVSSSH2PreferencePage_136}); - viewer.setLabelProvider(new TableLabelProvider()); - viewer.setContentProvider(new IStructuredContentProvider(){ - @Override - public void dispose(){ - // nothing to do - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput){ - // nothing to do - } - - @Override - public Object[] getElements(Object inputElement){ - if(inputElement==null) - return null; - return (Object[])inputElement; - } - }); - TableLayout tl=new TableLayout(); - tl.addColumnData(new ColumnWeightData(30)); - tl.addColumnData(new ColumnWeightData(20)); - tl.addColumnData(new ColumnWeightData(70)); - table.setLayout(tl); - - Composite buttons=new Composite(group, SWT.NULL); - buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - layout=new GridLayout(); - layout.marginHeight=0; - layout.marginWidth=0; - buttons.setLayout(layout); - - removeHostKeyButton=new Button(buttons, SWT.PUSH); - removeHostKeyButton.setText(Messages.CVSSSH2PreferencePage_138); - int buttonWidth=SWTUtils - .calculateControlSize(SWTUtils.createDialogPixelConverter(parent), - new Button[] {removeHostKeyButton}); - removeHostKeyButton.setLayoutData(SWTUtils.createGridData(buttonWidth, - SWT.DEFAULT, SWT.END, SWT.CENTER, false, false)); - removeHostKeyButton.setEnabled(false); + // Create the table columns + new TableColumn(table, SWT.NULL); + new TableColumn(table, SWT.NULL); + new TableColumn(table, SWT.NULL); + TableColumn[] columns=table.getColumns(); + columns[0].setText(Messages.CVSSSH2PreferencePage_134); + columns[1].setText(Messages.CVSSSH2PreferencePage_135); + columns[2].setText(Messages.CVSSSH2PreferencePage_136); + viewer.setColumnProperties(new String[] { + Messages.CVSSSH2PreferencePage_134, // + Messages.CVSSSH2PreferencePage_135, // + Messages.CVSSSH2PreferencePage_136}); + viewer.setLabelProvider(new TableLabelProvider()); + viewer.setContentProvider(new IStructuredContentProvider(){ + @Override + public void dispose(){ + // nothing to do + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput){ + // nothing to do + } + + @Override + public Object[] getElements(Object inputElement){ + if(inputElement==null) + return null; + return (Object[])inputElement; + } + }); + TableLayout tl=new TableLayout(); + tl.addColumnData(new ColumnWeightData(30)); + tl.addColumnData(new ColumnWeightData(20)); + tl.addColumnData(new ColumnWeightData(70)); + table.setLayout(tl); + + Composite buttons=new Composite(group, SWT.NULL); + buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + layout=new GridLayout(); + layout.marginHeight=0; + layout.marginWidth=0; + buttons.setLayout(layout); + + removeHostKeyButton=new Button(buttons, SWT.PUSH); + removeHostKeyButton.setText(Messages.CVSSSH2PreferencePage_138); + int buttonWidth=SWTUtils + .calculateControlSize(SWTUtils.createDialogPixelConverter(parent), + new Button[] {removeHostKeyButton}); + removeHostKeyButton.setLayoutData(SWTUtils.createGridData(buttonWidth, + SWT.DEFAULT, SWT.END, SWT.CENTER, false, false)); + removeHostKeyButton.setEnabled(false); removeHostKeyButton.addListener(SWT.Selection, e -> removeHostKey()); - Dialog.applyDialogFont(parent); - - // JSchSession.loadKnownHosts(JSchContext.getDefaultContext().getJSch()); - JSchCorePlugin.getPlugin().loadKnownHosts(); - HostKeyRepository hkr=getJSch().getHostKeyRepository(); - viewer.setInput(hkr.getHostKey()); - handleSelection(); - - return group; - } - - private Control createPreferredAuthenticationPage(Composite parent){ - Composite root = new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.numColumns = 2; - root.setLayout(layout); - - Label label=new Label(root, SWT.NONE); - GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); - textLayoutData.horizontalSpan = 2; - label.setLayoutData(textLayoutData); - label.setText(Messages.CVSSSH2PreferencePage_4); - - preferedAuthMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); - GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); - layoutData.verticalSpan = 3; - preferedAuthMethodTable.setLayoutData(layoutData); - layoutData.minimumHeight = 150; - layoutData.minimumWidth = 200; - populateAuthMethods(); - - up=new Button(root, SWT.PUSH); - up.setText(Messages.CVSSSH2PreferencePage_2); - up.setEnabled(false); - setButtonLayoutData(up); - - down=new Button(root, SWT.PUSH); - down.setText(Messages.CVSSSH2PreferencePage_3); - down.setEnabled(false); - setButtonLayoutData(down); - - preferedAuthMethodTable.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - boolean anySelected = false; - for(int i = 0; i < preferedAuthMethodTable.getItemCount(); i++){ - anySelected |= preferedAuthMethodTable.getItem(i).getChecked(); - } - - if(anySelected){ - setErrorMessage(null); - setValid(true); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_5); - setValid(false); - } - up.setEnabled(preferedAuthMethodTable.getSelectionIndex()>0); - down - .setEnabled(preferedAuthMethodTable.getSelectionIndex()<preferedAuthMethodTable - .getItemCount()-1); - } - - }); - up.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedAuthMethodTable.getSelectionIndex(); - if(selectedIndex == 1){ //this is the last possible swap - up.setEnabled(false); - } - down.setEnabled(true); - TableItem sourceItem = preferedAuthMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedAuthMethodTable.getItem(selectedIndex-1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedAuthMethodTable.setSelection(targetItem); - } - }); - - down.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedAuthMethodTable.getSelectionIndex(); - if(selectedIndex == preferedAuthMethodTable.getItemCount()-2){ //this is the last possible swap - down.setEnabled(false); - } - up.setEnabled(true); - TableItem sourceItem = preferedAuthMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedAuthMethodTable.getItem(selectedIndex+1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedAuthMethodTable.setSelection(targetItem); - } - }); - - return root; - } - - private void populateAuthMethods(){ - preferedAuthMethodTable.removeAll(); - String[] methods = Utils.getEnabledPreferredAuthMethods().split(","); //$NON-NLS-1$ + Dialog.applyDialogFont(parent); + + // JSchSession.loadKnownHosts(JSchContext.getDefaultContext().getJSch()); + JSchCorePlugin.getPlugin().loadKnownHosts(); + HostKeyRepository hkr=getJSch().getHostKeyRepository(); + viewer.setInput(hkr.getHostKey()); + handleSelection(); + + return group; + } + + private Control createPreferredAuthenticationPage(Composite parent){ + Composite root = new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns = 2; + root.setLayout(layout); + + Label label=new Label(root, SWT.NONE); + GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); + textLayoutData.horizontalSpan = 2; + label.setLayoutData(textLayoutData); + label.setText(Messages.CVSSSH2PreferencePage_4); + + preferedAuthMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); + GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); + layoutData.verticalSpan = 3; + preferedAuthMethodTable.setLayoutData(layoutData); + layoutData.minimumHeight = 150; + layoutData.minimumWidth = 200; + populateAuthMethods(); + + up=new Button(root, SWT.PUSH); + up.setText(Messages.CVSSSH2PreferencePage_2); + up.setEnabled(false); + setButtonLayoutData(up); + + down=new Button(root, SWT.PUSH); + down.setText(Messages.CVSSSH2PreferencePage_3); + down.setEnabled(false); + setButtonLayoutData(down); + + preferedAuthMethodTable.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + boolean anySelected = false; + for(int i = 0; i < preferedAuthMethodTable.getItemCount(); i++){ + anySelected |= preferedAuthMethodTable.getItem(i).getChecked(); + } + + if(anySelected){ + setErrorMessage(null); + setValid(true); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_5); + setValid(false); + } + up.setEnabled(preferedAuthMethodTable.getSelectionIndex()>0); + down + .setEnabled(preferedAuthMethodTable.getSelectionIndex()<preferedAuthMethodTable + .getItemCount()-1); + } + + }); + up.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedAuthMethodTable.getSelectionIndex(); + if(selectedIndex == 1){ //this is the last possible swap + up.setEnabled(false); + } + down.setEnabled(true); + TableItem sourceItem = preferedAuthMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedAuthMethodTable.getItem(selectedIndex-1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedAuthMethodTable.setSelection(targetItem); + } + }); + + down.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedAuthMethodTable.getSelectionIndex(); + if(selectedIndex == preferedAuthMethodTable.getItemCount()-2){ //this is the last possible swap + down.setEnabled(false); + } + up.setEnabled(true); + TableItem sourceItem = preferedAuthMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedAuthMethodTable.getItem(selectedIndex+1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedAuthMethodTable.setSelection(targetItem); + } + }); + + return root; + } + + private void populateAuthMethods(){ + preferedAuthMethodTable.removeAll(); + String[] methods = Utils.getEnabledPreferredAuthMethods().split(","); //$NON-NLS-1$ Set<String> smethods = new HashSet<>(Arrays.asList(methods)); - String[] order = Utils.getMethodsOrder().split(","); //$NON-NLS-1$ - - for(int i=0; i<order.length; i++){ - TableItem tableItem= new TableItem(preferedAuthMethodTable, SWT.NONE); - tableItem.setText(0, order[i]); - if(smethods.contains(order[i])){ - tableItem.setChecked(true); - } - } - } - - private Control createPreferredKeyExchangePage(Composite parent){ - Composite root = new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.numColumns = 2; - root.setLayout(layout); - - Label label=new Label(root, SWT.NONE); - GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); - textLayoutData.horizontalSpan = 2; - label.setLayoutData(textLayoutData); - label.setText(Messages.CVSSSH2PreferencePage_140); - - preferedKeyExchangeMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); - GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); - layoutData.verticalSpan = 3; - preferedKeyExchangeMethodTable.setLayoutData(layoutData); - layoutData.minimumHeight = 150; - layoutData.minimumWidth = 200; - populateAuthMethods(); - - kex_up=new Button(root, SWT.PUSH); - kex_up.setText(Messages.CVSSSH2PreferencePage_2); - kex_up.setEnabled(false); - setButtonLayoutData(kex_up); - - kex_down=new Button(root, SWT.PUSH); - kex_down.setText(Messages.CVSSSH2PreferencePage_3); - kex_down.setEnabled(false); - setButtonLayoutData(kex_down); - - preferedKeyExchangeMethodTable.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - boolean anySelected = false; - for(int i = 0; i < preferedKeyExchangeMethodTable.getItemCount(); i++){ - anySelected |= preferedKeyExchangeMethodTable.getItem(i).getChecked(); - } - - if(anySelected){ - setErrorMessage(null); - setValid(true); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_142); - setValid(false); - } - kex_up.setEnabled(preferedKeyExchangeMethodTable.getSelectionIndex()>0); - kex_down - .setEnabled(preferedKeyExchangeMethodTable.getSelectionIndex()<preferedKeyExchangeMethodTable - .getItemCount()-1); - } - - }); - kex_up.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedKeyExchangeMethodTable.getSelectionIndex(); - if(selectedIndex == 1){ //this is the last possible swap - kex_up.setEnabled(false); - } - kex_down.setEnabled(true); - TableItem sourceItem = preferedKeyExchangeMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedKeyExchangeMethodTable.getItem(selectedIndex-1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedKeyExchangeMethodTable.setSelection(targetItem); - } - }); - - kex_down.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedKeyExchangeMethodTable.getSelectionIndex(); - if(selectedIndex == preferedKeyExchangeMethodTable.getItemCount()-2){ //this is the last possible swap - kex_down.setEnabled(false); - } - kex_up.setEnabled(true); - TableItem sourceItem = preferedKeyExchangeMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedKeyExchangeMethodTable.getItem(selectedIndex+1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedKeyExchangeMethodTable.setSelection(targetItem); - } - }); - - return root; - } - - private void populateKeyExchangeMethods(){ - preferedKeyExchangeMethodTable.removeAll(); - String[] methods = Utils.getEnabledPreferredKEXMethods().split(","); //$NON-NLS-1$ - Set<String> smethods = new HashSet<>(Arrays.asList(methods)); - - String[] order = Utils.getKEXMethodsOrder().split(","); //$NON-NLS-1$ - - for(int i=0; i<order.length; i++){ - TableItem tableItem= new TableItem(preferedKeyExchangeMethodTable, SWT.NONE); - tableItem.setText(0, order[i]); - if(smethods.contains(order[i])){ - tableItem.setChecked(true); - } - } - } - - private Control createPreferredMACPage(Composite parent){ - Composite root = new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.numColumns = 2; - root.setLayout(layout); - - Label label=new Label(root, SWT.NONE); - GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); - textLayoutData.horizontalSpan = 2; - label.setLayoutData(textLayoutData); - label.setText(Messages.CVSSSH2PreferencePage_141); - - preferedMACMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); - GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); - layoutData.verticalSpan = 3; - preferedMACMethodTable.setLayoutData(layoutData); - layoutData.minimumHeight = 150; - layoutData.minimumWidth = 200; - populateMACMethods(); - - mac_up=new Button(root, SWT.PUSH); - mac_up.setText(Messages.CVSSSH2PreferencePage_2); - mac_up.setEnabled(false); - setButtonLayoutData(mac_up); - - mac_down=new Button(root, SWT.PUSH); - mac_down.setText(Messages.CVSSSH2PreferencePage_3); - mac_down.setEnabled(false); - setButtonLayoutData(mac_down); - - preferedMACMethodTable.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - boolean anySelected = false; - for(int i = 0; i < preferedMACMethodTable.getItemCount(); i++){ - anySelected |= preferedMACMethodTable.getItem(i).getChecked(); - } - - if(anySelected){ - setErrorMessage(null); - setValid(true); - } - else{ - setErrorMessage(Messages.CVSSSH2PreferencePage_143); - setValid(false); - } - mac_up.setEnabled(preferedMACMethodTable.getSelectionIndex()>0); - mac_down - .setEnabled(preferedMACMethodTable.getSelectionIndex()<preferedMACMethodTable - .getItemCount()-1); - } - - }); - mac_up.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedMACMethodTable.getSelectionIndex(); - if(selectedIndex == 1){ //this is the last possible swap - mac_up.setEnabled(false); - } - mac_down.setEnabled(true); - TableItem sourceItem = preferedMACMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedMACMethodTable.getItem(selectedIndex-1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedMACMethodTable.setSelection(targetItem); - } - }); - - mac_down.addSelectionListener(new SelectionAdapter(){ - - @Override - public void widgetSelected(SelectionEvent e){ - int selectedIndex=preferedMACMethodTable.getSelectionIndex(); - if(selectedIndex == preferedMACMethodTable.getItemCount()-2){ //this is the last possible swap - mac_down.setEnabled(false); - } - mac_up.setEnabled(true); - TableItem sourceItem = preferedMACMethodTable.getItem(selectedIndex); - TableItem targetItem = preferedMACMethodTable.getItem(selectedIndex+1); - - //switch text - String stemp = targetItem.getText(); - targetItem.setText(sourceItem.getText()); - sourceItem.setText(stemp); - - //switch selection - boolean btemp = targetItem.getChecked(); - targetItem.setChecked(sourceItem.getChecked()); - sourceItem.setChecked(btemp); - - preferedMACMethodTable.setSelection(targetItem); - } - }); - - return root; - } - - private Control createPreferredSSHAgentPage(Composite parent){ - Composite root = new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.numColumns = 2; - root.setLayout(layout); - - Label label=new Label(root, SWT.NONE); - GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); - textLayoutData.horizontalSpan = 2; - label.setLayoutData(textLayoutData); - label.setText(Messages.CVSSSH2PreferencePage_147); - - preferedSSHAgentTable=new Table(root, SWT.CHECK | SWT.BORDER); - GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); - layoutData.verticalSpan = 3; - preferedSSHAgentTable.setLayoutData(layoutData); - layoutData.minimumHeight = 150; - layoutData.minimumWidth = 200; - populateSSHAgents(); - return root; - } - - private void populateSSHAgents(){ - preferedSSHAgentTable.removeAll(); - String[] methods = Utils.getAvailableSSHAgents().split(","); //$NON-NLS-1$ - String[] selected = Utils.getSelectedSSHAgent().split(","); //$NON-NLS-1$ - - for(int i=0; i<methods.length; i++){ - if(methods[i].length()==0) - continue; - TableItem tableItem= new TableItem(preferedSSHAgentTable, SWT.NONE); - tableItem.setText(0, methods[i]); - for(int j=0; j<selected.length; j++){ - if(selected[j].equals(methods[i])){ - tableItem.setChecked(true); - break; - } - } - } - } - - private void populateMACMethods(){ - preferedMACMethodTable.removeAll(); - String[] methods = Utils.getEnabledPreferredMACMethods().split(","); //$NON-NLS-1$ - Set<String> smethods = new HashSet<>(Arrays.asList(methods)); - - String[] order = Utils.getMACMethodsOrder().split(","); //$NON-NLS-1$ - - for(int i=0; i<order.length; i++){ - TableItem tableItem= new TableItem(preferedMACMethodTable, SWT.NONE); - tableItem.setText(0, order[i]); - if(smethods.contains(order[i])){ - tableItem.setChecked(true); - } - } - } - - void handleSelection(){ - boolean empty=viewer.getSelection().isEmpty(); - removeHostKeyButton.setEnabled(!empty); - } - - void removeHostKey(){ - IStructuredSelection selection=viewer.getStructuredSelection(); - HostKeyRepository hkr=getJSch().getHostKeyRepository(); - for(Iterator<?> iterator=selection.iterator(); iterator.hasNext();){ - HostKey hostkey=(HostKey)iterator.next(); - hkr.remove(hostkey.getHost(), hostkey.getType()); - viewer.remove(hostkey); - } - } - - void export_via_sftp(String user, String host, int port, byte[] pkey) throws JSchException{ - try{ - - int timeout = 60000; - IJSchService service = JSchUIPlugin.getPlugin().getJSchService(); - if (service == null) { - MessageDialog.openInformation(getShell(), Messages.PreferencePage_0, Messages.PreferencePage_1); - return; - } - - IJSchLocation location=service.getLocation(user, host, port); - // We hope that prompts for jsch are given by IJSchService, so "null" should be passed. - Session session = service.createSession(location, null); - session.setTimeout(timeout); - try { - service.connect(session, timeout, new NullProgressMonitor()); - if(session.getServerVersion().indexOf("OpenSSH")==-1){ //$NON-NLS-1$ - setErrorMessage(Messages.CVSSSH2PreferencePage_110); - return; - } - Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ - channel.connect(); - ChannelSftp c=(ChannelSftp)channel; - - SftpATTRS attr=null; - - try{ - attr=c.stat(".ssh");} //$NON-NLS-1$ - catch(SftpException ee){ - // Ignore - } - if(attr==null){ - try{ - c.mkdir(".ssh");} //$NON-NLS-1$ - catch(SftpException ee){ - setErrorMessage(ee.getMessage()); - return; - } - } - try{ - c.cd(".ssh");} //$NON-NLS-1$ - catch(SftpException ee){ - setErrorMessage(ee.getMessage()); - return; - } - - try{ - ByteArrayInputStream bis=new ByteArrayInputStream(pkey); - c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$ - bis.close(); - checkPermission(c, "authorized_keys"); //$NON-NLS-1$ - checkPermission(c, "."); // .ssh //$NON-NLS-1$ - c.cd(".."); //$NON-NLS-1$ - checkPermission(c, "."); // home directory //$NON-NLS-1$ - } - catch(SftpException ee){ - // setErrorMessage(debug+ee.message); - } - - MessageDialog.openInformation(getShell(), - Messages.CVSSSH2PreferencePage_information, - NLS.bind(Messages.CVSSSH2PreferencePage_109, (user - +"@"+host+(port==22 ? "" : ":"+port)+":~/.ssh/authorized_keys"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - - c.quit(); - c.disconnect(); - } finally { - session.disconnect(); - } - } catch(IOException eee){ - setErrorMessage(eee.toString()); - } - } - - private void checkPermission(ChannelSftp c, String path) throws SftpException{ - SftpATTRS attr=c.stat(path); - int permissions=attr.getPermissions(); - if((permissions&00022)!=0){ - permissions&=~00022; - c.chmod(permissions, path); - } - } - - void updateControls(){ - boolean enable=(kpair!=null); - publicKeylabel.setEnabled(enable); - publicKeyText.setEnabled(enable); - keyFingerPrintLabel.setEnabled(enable); - keyFingerPrintText.setEnabled(enable); - keyCommentLabel.setEnabled(enable); - keyCommentText.setEnabled(enable); - keyPassphrase1Label.setEnabled(enable); - keyPassphrase1Text.setEnabled(enable); - keyPassphrase2Label.setEnabled(enable); - keyPassphrase2Text.setEnabled(enable); - keyExport.setEnabled(enable); - saveKeyPair.setEnabled(enable); - populateAuthMethods(); - populateKeyExchangeMethods(); - populateMACMethods(); - up.setEnabled(false); - down.setEnabled(false); - kex_up.setEnabled(false); - kex_down.setEnabled(false); - mac_up.setEnabled(false); - mac_down.setEnabled(false); - } - - @Override + String[] order = Utils.getMethodsOrder().split(","); //$NON-NLS-1$ + + for(int i=0; i<order.length; i++){ + TableItem tableItem= new TableItem(preferedAuthMethodTable, SWT.NONE); + tableItem.setText(0, order[i]); + if(smethods.contains(order[i])){ + tableItem.setChecked(true); + } + } + } + + private Control createPreferredKeyExchangePage(Composite parent){ + Composite root = new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns = 2; + root.setLayout(layout); + + Label label=new Label(root, SWT.NONE); + GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); + textLayoutData.horizontalSpan = 2; + label.setLayoutData(textLayoutData); + label.setText(Messages.CVSSSH2PreferencePage_140); + + preferedKeyExchangeMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); + GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); + layoutData.verticalSpan = 3; + preferedKeyExchangeMethodTable.setLayoutData(layoutData); + layoutData.minimumHeight = 150; + layoutData.minimumWidth = 200; + populateAuthMethods(); + + kex_up=new Button(root, SWT.PUSH); + kex_up.setText(Messages.CVSSSH2PreferencePage_2); + kex_up.setEnabled(false); + setButtonLayoutData(kex_up); + + kex_down=new Button(root, SWT.PUSH); + kex_down.setText(Messages.CVSSSH2PreferencePage_3); + kex_down.setEnabled(false); + setButtonLayoutData(kex_down); + + preferedKeyExchangeMethodTable.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + boolean anySelected = false; + for(int i = 0; i < preferedKeyExchangeMethodTable.getItemCount(); i++){ + anySelected |= preferedKeyExchangeMethodTable.getItem(i).getChecked(); + } + + if(anySelected){ + setErrorMessage(null); + setValid(true); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_142); + setValid(false); + } + kex_up.setEnabled(preferedKeyExchangeMethodTable.getSelectionIndex()>0); + kex_down + .setEnabled(preferedKeyExchangeMethodTable.getSelectionIndex()<preferedKeyExchangeMethodTable + .getItemCount()-1); + } + + }); + kex_up.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedKeyExchangeMethodTable.getSelectionIndex(); + if(selectedIndex == 1){ //this is the last possible swap + kex_up.setEnabled(false); + } + kex_down.setEnabled(true); + TableItem sourceItem = preferedKeyExchangeMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedKeyExchangeMethodTable.getItem(selectedIndex-1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedKeyExchangeMethodTable.setSelection(targetItem); + } + }); + + kex_down.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedKeyExchangeMethodTable.getSelectionIndex(); + if(selectedIndex == preferedKeyExchangeMethodTable.getItemCount()-2){ //this is the last possible swap + kex_down.setEnabled(false); + } + kex_up.setEnabled(true); + TableItem sourceItem = preferedKeyExchangeMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedKeyExchangeMethodTable.getItem(selectedIndex+1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedKeyExchangeMethodTable.setSelection(targetItem); + } + }); + + return root; + } + + private void populateKeyExchangeMethods(){ + preferedKeyExchangeMethodTable.removeAll(); + String[] methods = Utils.getEnabledPreferredKEXMethods().split(","); //$NON-NLS-1$ + Set<String> smethods = new HashSet<>(Arrays.asList(methods)); + + String[] order = Utils.getKEXMethodsOrder().split(","); //$NON-NLS-1$ + + for(int i=0; i<order.length; i++){ + TableItem tableItem= new TableItem(preferedKeyExchangeMethodTable, SWT.NONE); + tableItem.setText(0, order[i]); + if(smethods.contains(order[i])){ + tableItem.setChecked(true); + } + } + } + + private Control createPreferredMACPage(Composite parent){ + Composite root = new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns = 2; + root.setLayout(layout); + + Label label=new Label(root, SWT.NONE); + GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); + textLayoutData.horizontalSpan = 2; + label.setLayoutData(textLayoutData); + label.setText(Messages.CVSSSH2PreferencePage_141); + + preferedMACMethodTable=new Table(root, SWT.CHECK | SWT.BORDER); + GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); + layoutData.verticalSpan = 3; + preferedMACMethodTable.setLayoutData(layoutData); + layoutData.minimumHeight = 150; + layoutData.minimumWidth = 200; + populateMACMethods(); + + mac_up=new Button(root, SWT.PUSH); + mac_up.setText(Messages.CVSSSH2PreferencePage_2); + mac_up.setEnabled(false); + setButtonLayoutData(mac_up); + + mac_down=new Button(root, SWT.PUSH); + mac_down.setText(Messages.CVSSSH2PreferencePage_3); + mac_down.setEnabled(false); + setButtonLayoutData(mac_down); + + preferedMACMethodTable.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + boolean anySelected = false; + for(int i = 0; i < preferedMACMethodTable.getItemCount(); i++){ + anySelected |= preferedMACMethodTable.getItem(i).getChecked(); + } + + if(anySelected){ + setErrorMessage(null); + setValid(true); + } + else{ + setErrorMessage(Messages.CVSSSH2PreferencePage_143); + setValid(false); + } + mac_up.setEnabled(preferedMACMethodTable.getSelectionIndex()>0); + mac_down + .setEnabled(preferedMACMethodTable.getSelectionIndex()<preferedMACMethodTable + .getItemCount()-1); + } + + }); + mac_up.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedMACMethodTable.getSelectionIndex(); + if(selectedIndex == 1){ //this is the last possible swap + mac_up.setEnabled(false); + } + mac_down.setEnabled(true); + TableItem sourceItem = preferedMACMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedMACMethodTable.getItem(selectedIndex-1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedMACMethodTable.setSelection(targetItem); + } + }); + + mac_down.addSelectionListener(new SelectionAdapter(){ + + @Override + public void widgetSelected(SelectionEvent e){ + int selectedIndex=preferedMACMethodTable.getSelectionIndex(); + if(selectedIndex == preferedMACMethodTable.getItemCount()-2){ //this is the last possible swap + mac_down.setEnabled(false); + } + mac_up.setEnabled(true); + TableItem sourceItem = preferedMACMethodTable.getItem(selectedIndex); + TableItem targetItem = preferedMACMethodTable.getItem(selectedIndex+1); + + //switch text + String stemp = targetItem.getText(); + targetItem.setText(sourceItem.getText()); + sourceItem.setText(stemp); + + //switch selection + boolean btemp = targetItem.getChecked(); + targetItem.setChecked(sourceItem.getChecked()); + sourceItem.setChecked(btemp); + + preferedMACMethodTable.setSelection(targetItem); + } + }); + + return root; + } + + private Control createPreferredSSHAgentPage(Composite parent){ + Composite root = new Composite(parent, SWT.NONE); + GridLayout layout=new GridLayout(); + layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.numColumns = 2; + root.setLayout(layout); + + Label label=new Label(root, SWT.NONE); + GridData textLayoutData=new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false); + textLayoutData.horizontalSpan = 2; + label.setLayoutData(textLayoutData); + label.setText(Messages.CVSSSH2PreferencePage_147); + + preferedSSHAgentTable=new Table(root, SWT.CHECK | SWT.BORDER); + GridData layoutData=new GridData(SWT.FILL, SWT.BEGINNING, true, true); + layoutData.verticalSpan = 3; + preferedSSHAgentTable.setLayoutData(layoutData); + layoutData.minimumHeight = 150; + layoutData.minimumWidth = 200; + populateSSHAgents(); + return root; + } + + private void populateSSHAgents(){ + preferedSSHAgentTable.removeAll(); + String[] methods = Utils.getAvailableSSHAgents().split(","); //$NON-NLS-1$ + String[] selected = Utils.getSelectedSSHAgent().split(","); //$NON-NLS-1$ + + for(int i=0; i<methods.length; i++){ + if(methods[i].length()==0) + continue; + TableItem tableItem= new TableItem(preferedSSHAgentTable, SWT.NONE); + tableItem.setText(0, methods[i]); + for(int j=0; j<selected.length; j++){ + if(selected[j].equals(methods[i])){ + tableItem.setChecked(true); + break; + } + } + } + } + + private void populateMACMethods(){ + preferedMACMethodTable.removeAll(); + String[] methods = Utils.getEnabledPreferredMACMethods().split(","); //$NON-NLS-1$ + Set<String> smethods = new HashSet<>(Arrays.asList(methods)); + + String[] order = Utils.getMACMethodsOrder().split(","); //$NON-NLS-1$ + + for(int i=0; i<order.length; i++){ + TableItem tableItem= new TableItem(preferedMACMethodTable, SWT.NONE); + tableItem.setText(0, order[i]); + if(smethods.contains(order[i])){ + tableItem.setChecked(true); + } + } + } + + void handleSelection(){ + boolean empty=viewer.getSelection().isEmpty(); + removeHostKeyButton.setEnabled(!empty); + } + + void removeHostKey(){ + IStructuredSelection selection=viewer.getStructuredSelection(); + HostKeyRepository hkr=getJSch().getHostKeyRepository(); + for(Iterator<?> iterator=selection.iterator(); iterator.hasNext();){ + HostKey hostkey=(HostKey)iterator.next(); + hkr.remove(hostkey.getHost(), hostkey.getType()); + viewer.remove(hostkey); + } + } + + void export_via_sftp(String user, String host, int port, byte[] pkey) throws JSchException{ + try{ + + int timeout = 60000; + IJSchService service = JSchUIPlugin.getPlugin().getJSchService(); + if (service == null) { + MessageDialog.openInformation(getShell(), Messages.PreferencePage_0, Messages.PreferencePage_1); + return; + } + + IJSchLocation location=service.getLocation(user, host, port); + // We hope that prompts for jsch are given by IJSchService, so "null" should be passed. + Session session = service.createSession(location, null); + session.setTimeout(timeout); + try { + service.connect(session, timeout, new NullProgressMonitor()); + if(session.getServerVersion().indexOf("OpenSSH")==-1){ //$NON-NLS-1$ + setErrorMessage(Messages.CVSSSH2PreferencePage_110); + return; + } + Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ + channel.connect(); + ChannelSftp c=(ChannelSftp)channel; + + SftpATTRS attr=null; + + try{ + attr=c.stat(".ssh");} //$NON-NLS-1$ + catch(SftpException ee){ + // Ignore + } + if(attr==null){ + try{ + c.mkdir(".ssh");} //$NON-NLS-1$ + catch(SftpException ee){ + setErrorMessage(ee.getMessage()); + return; + } + } + try{ + c.cd(".ssh");} //$NON-NLS-1$ + catch(SftpException ee){ + setErrorMessage(ee.getMessage()); + return; + } + + try{ + ByteArrayInputStream bis=new ByteArrayInputStream(pkey); + c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$ + bis.close(); + checkPermission(c, "authorized_keys"); //$NON-NLS-1$ + checkPermission(c, "."); // .ssh //$NON-NLS-1$ + c.cd(".."); //$NON-NLS-1$ + checkPermission(c, "."); // home directory //$NON-NLS-1$ + } + catch(SftpException ee){ + // setErrorMessage(debug+ee.message); + } + + MessageDialog.openInformation(getShell(), + Messages.CVSSSH2PreferencePage_information, + NLS.bind(Messages.CVSSSH2PreferencePage_109, (user + +"@"+host+(port==22 ? "" : ":"+port)+":~/.ssh/authorized_keys"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + + c.quit(); + c.disconnect(); + } finally { + session.disconnect(); + } + } catch(IOException eee){ + setErrorMessage(eee.toString()); + } + } + + private void checkPermission(ChannelSftp c, String path) throws SftpException{ + SftpATTRS attr=c.stat(path); + int permissions=attr.getPermissions(); + if((permissions&00022)!=0){ + permissions&=~00022; + c.chmod(permissions, path); + } + } + + void updateControls(){ + boolean enable=(kpair!=null); + publicKeylabel.setEnabled(enable); + publicKeyText.setEnabled(enable); + keyFingerPrintLabel.setEnabled(enable); + keyFingerPrintText.setEnabled(enable); + keyCommentLabel.setEnabled(enable); + keyCommentText.setEnabled(enable); + keyPassphrase1Label.setEnabled(enable); + keyPassphrase1Text.setEnabled(enable); + keyPassphrase2Label.setEnabled(enable); + keyPassphrase2Text.setEnabled(enable); + keyExport.setEnabled(enable); + saveKeyPair.setEnabled(enable); + populateAuthMethods(); + populateKeyExchangeMethods(); + populateMACMethods(); + up.setEnabled(false); + down.setEnabled(false); + kex_up.setEnabled(false); + kex_down.setEnabled(false); + mac_up.setEnabled(false); + mac_down.setEnabled(false); + } + + @Override public void init(IWorkbench workbench){ - // super.init(workbench); - // initControls(); - } - - public void initialize(){ - initControls(); - } - - private void initControls(){ - Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); - ssh2HomeText.setText(preferences - .getString(org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME)); - privateKeyText.setText(preferences - .getString(org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY)); - updateControls(); - } - - @Override + // super.init(workbench); + // initControls(); + } + + public void initialize(){ + initControls(); + } + + private void initControls(){ + Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); + ssh2HomeText.setText(preferences + .getString(org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME)); + privateKeyText.setText(preferences + .getString(org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY)); + updateControls(); + } + + @Override public boolean performOk(){ - boolean result=super.performOk(); - storeAuthenticationMethodSettings(); - storeSSHAgentSettings(); - storeKeyExchangeMethodSettings(); - storeMACMethodSettings(); - - if(result){ - setErrorMessage(null); - String home=ssh2HomeText.getText(); - File _home=new File(home); - if(!_home.exists()){ - if(MessageDialog.openQuestion(getShell(), - Messages.CVSSSH2PreferencePage_question, NLS.bind( - Messages.CVSSSH2PreferencePage_99, new String[] {home}))){ - if(!(_home.mkdirs())){ - setErrorMessage(Messages.CVSSSH2PreferencePage_100+home); - return false; - } - } - } - - Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); - preferences.setValue( - org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME, home); - preferences.setValue( - org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY, - privateKeyText.getText()); - } - JSchCorePlugin.getPlugin().setNeedToLoadKnownHosts(true); - JSchCorePlugin.getPlugin().setNeedToLoadKeys(true); - JSchCorePlugin.getPlugin().setIdentityRepository(); - JSchCorePlugin.getPlugin().savePluginPreferences(); - return result; - } - - private void storeAuthenticationMethodSettings(){ - String selected = null; - String order = null; - for(int i = 0; i < preferedAuthMethodTable.getItemCount(); i++){ - TableItem item=preferedAuthMethodTable.getItem(i); - if(item.getChecked()){ - if(selected==null){ - selected=item.getText(); - } - else{ - selected+=","+item.getText(); //$NON-NLS-1$ - } - } - if(order == null){ - order = item.getText(); - } else { - order += "," + item.getText(); //$NON-NLS-1$ - } - } - Utils.setEnabledPreferredAuthMethods(selected, order); - } - - private void storeSSHAgentSettings(){ - String selected = ""; //$NON-NLS-1$ - for(int i = 0; i < preferedSSHAgentTable.getItemCount(); i++){ - TableItem item=preferedSSHAgentTable.getItem(i); - if(item.getChecked()){ - if(selected.length()==0){ - selected=item.getText(); - } - else{ - selected+=","+item.getText(); //$NON-NLS-1$ - } - } - } - Utils.setSelectedSSHAgents(selected); - } - - private void storeKeyExchangeMethodSettings(){ - String selected = null; - String order = null; - for(int i = 0; i < preferedKeyExchangeMethodTable.getItemCount(); i++){ - TableItem item=preferedKeyExchangeMethodTable.getItem(i); - if(item.getChecked()){ - if(selected==null){ - selected=item.getText(); - } - else{ - selected+=","+item.getText(); //$NON-NLS-1$ - } - } - if(order == null){ - order = item.getText(); - } else { - order += "," + item.getText(); //$NON-NLS-1$ - } - } - Utils.setEnabledPreferredKEXMethods(selected, order); - } - - private void storeMACMethodSettings(){ - String selected = null; - String order = null; - for(int i = 0; i < preferedMACMethodTable.getItemCount(); i++){ - TableItem item=preferedMACMethodTable.getItem(i); - if(item.getChecked()){ - if(selected==null){ - selected=item.getText(); - } - else{ - selected+=","+item.getText(); //$NON-NLS-1$ - } - } - if(order == null){ - order = item.getText(); - } else { - order += "," + item.getText(); //$NON-NLS-1$ - } - } - Utils.setEnabledPreferredMACMethods(selected, order); - } - - @Override + boolean result=super.performOk(); + storeAuthenticationMethodSettings(); + storeSSHAgentSettings(); + storeKeyExchangeMethodSettings(); + storeMACMethodSettings(); + + if(result){ + setErrorMessage(null); + String home=ssh2HomeText.getText(); + File _home=new File(home); + if(!_home.exists()){ + if(MessageDialog.openQuestion(getShell(), + Messages.CVSSSH2PreferencePage_question, NLS.bind( + Messages.CVSSSH2PreferencePage_99, new String[] {home}))){ + if(!(_home.mkdirs())){ + setErrorMessage(Messages.CVSSSH2PreferencePage_100+home); + return false; + } + } + } + + Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); + preferences.setValue( + org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME, home); + preferences.setValue( + org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY, + privateKeyText.getText()); + } + JSchCorePlugin.getPlugin().setNeedToLoadKnownHosts(true); + JSchCorePlugin.getPlugin().setNeedToLoadKeys(true); + JSchCorePlugin.getPlugin().setIdentityRepository(); + JSchCorePlugin.getPlugin().savePluginPreferences(); + return result; + } + + private void storeAuthenticationMethodSettings(){ + String selected = null; + String order = null; + for(int i = 0; i < preferedAuthMethodTable.getItemCount(); i++){ + TableItem item=preferedAuthMethodTable.getItem(i); + if(item.getChecked()){ + if(selected==null){ + selected=item.getText(); + } + else{ + selected+=","+item.getText(); //$NON-NLS-1$ + } + } + if(order == null){ + order = item.getText(); + } else { + order += "," + item.getText(); //$NON-NLS-1$ + } + } + Utils.setEnabledPreferredAuthMethods(selected, order); + } + + private void storeSSHAgentSettings(){ + String selected = ""; //$NON-NLS-1$ + for(int i = 0; i < preferedSSHAgentTable.getItemCount(); i++){ + TableItem item=preferedSSHAgentTable.getItem(i); + if(item.getChecked()){ + if(selected.length()==0){ + selected=item.getText(); + } + else{ + selected+=","+item.getText(); //$NON-NLS-1$ + } + } + } + Utils.setSelectedSSHAgents(selected); + } + + private void storeKeyExchangeMethodSettings(){ + String selected = null; + String order = null; + for(int i = 0; i < preferedKeyExchangeMethodTable.getItemCount(); i++){ + TableItem item=preferedKeyExchangeMethodTable.getItem(i); + if(item.getChecked()){ + if(selected==null){ + selected=item.getText(); + } + else{ + selected+=","+item.getText(); //$NON-NLS-1$ + } + } + if(order == null){ + order = item.getText(); + } else { + order += "," + item.getText(); //$NON-NLS-1$ + } + } + Utils.setEnabledPreferredKEXMethods(selected, order); + } + + private void storeMACMethodSettings(){ + String selected = null; + String order = null; + for(int i = 0; i < preferedMACMethodTable.getItemCount(); i++){ + TableItem item=preferedMACMethodTable.getItem(i); + if(item.getChecked()){ + if(selected==null){ + selected=item.getText(); + } + else{ + selected+=","+item.getText(); //$NON-NLS-1$ + } + } + if(order == null){ + order = item.getText(); + } else { + order += "," + item.getText(); //$NON-NLS-1$ + } + } + Utils.setEnabledPreferredMACMethods(selected, order); + } + + @Override public void performApply(){ - performOk(); - } + performOk(); + } - @Override + @Override protected void performDefaults(){ - super.performDefaults(); - Utils.setEnabledPreferredAuthMethods(Utils.getDefaultAuthMethods(), Utils - .getDefaultAuthMethods()); - Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); - ssh2HomeText - .setText(preferences - .getDefaultString(org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME)); - privateKeyText - .setText(preferences - .getDefaultString(org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY)); - updateControls(); - } - - protected void createSpacer(Composite composite, int columnSpan){ - Label label=new Label(composite, SWT.NONE); - GridData gd=new GridData(); - gd.horizontalSpan=columnSpan; - label.setLayoutData(gd); - } - - JSch getJSch(){ - return JSchCorePlugin.getPlugin().getJSch(); - } - - class PassphrasePrompt implements Runnable{ - private String message; - private String passphrase; - - PassphrasePrompt(String message){ - this.message=message; - } - - @Override - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - PassphraseDialog dialog=new PassphraseDialog(shell, message); - dialog.open(); - shell.dispose(); - passphrase=dialog.getPassphrase(); - } - - public String getPassphrase(){ - return passphrase; - } - } + super.performDefaults(); + Utils.setEnabledPreferredAuthMethods(Utils.getDefaultAuthMethods(), Utils + .getDefaultAuthMethods()); + Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); + ssh2HomeText + .setText(preferences + .getDefaultString(org.eclipse.jsch.internal.core.IConstants.KEY_SSH2HOME)); + privateKeyText + .setText(preferences + .getDefaultString(org.eclipse.jsch.internal.core.IConstants.KEY_PRIVATEKEY)); + updateControls(); + } + + protected void createSpacer(Composite composite, int columnSpan){ + Label label=new Label(composite, SWT.NONE); + GridData gd=new GridData(); + gd.horizontalSpan=columnSpan; + label.setLayoutData(gd); + } + + JSch getJSch(){ + return JSchCorePlugin.getPlugin().getJSch(); + } + + class PassphrasePrompt implements Runnable{ + private String message; + private String passphrase; + + PassphrasePrompt(String message){ + this.message=message; + } + + @Override + public void run(){ + Display display=Display.getCurrent(); + Shell shell=new Shell(display); + PassphraseDialog dialog=new PassphraseDialog(shell, message); + dialog.open(); + shell.dispose(); + passphrase=dialog.getPassphrase(); + } + + public String getPassphrase(){ + return passphrase; + } + } } diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/SWTUtils.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/SWTUtils.java index 8a5ace145..8523a9c16 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/SWTUtils.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/SWTUtils.java @@ -31,96 +31,96 @@ public class SWTUtils { public static final int MARGINS_DIALOG= 1; public static PreferenceLinkArea createPreferenceLink(IWorkbenchPreferenceContainer container, Composite parent, String pageId, String text) { - final PreferenceLinkArea area = new PreferenceLinkArea(parent, SWT.NONE, pageId, text, container, null); - return area; - } - - public static GridData createGridData(int width, int height, boolean hFill, boolean vFill) { - return createGridData(width, height, hFill ? SWT.FILL : SWT.BEGINNING, vFill ? SWT.FILL : SWT.CENTER, hFill, vFill); - } - - public static GridData createGridData(int width, int height, int hAlign, int vAlign, boolean hGrab, boolean vGrab) { - final GridData gd= new GridData(hAlign, vAlign, hGrab, vGrab); - gd.widthHint= width; - gd.heightHint= height; - return gd; - } - - public static GridData createHFillGridData() { - return createHFillGridData(1); - } - - public static GridData createHFillGridData(int span) { - final GridData gd= createGridData(0, SWT.DEFAULT, SWT.FILL, SWT.CENTER, true, false); - gd.horizontalSpan= span; - return gd; - } - - public static Composite createHFillComposite(Composite parent, int margins) { - return createHFillComposite(parent, margins, 1); - } - - public static Composite createHFillComposite(Composite parent, int margins, int columns) { - final Composite composite= new Composite(parent, SWT.NONE); - composite.setFont(parent.getFont()); - composite.setLayoutData(createHFillGridData()); - composite.setLayout(createGridLayout(columns, new PixelConverter(parent), margins)); - return composite; - } - - public static Composite createHVFillComposite(Composite parent, int margins) { - return createHVFillComposite(parent, margins, 1); - } - - public static Composite createHVFillComposite(Composite parent, int margins, int columns) { - final Composite composite= new Composite(parent, SWT.NONE); - composite.setFont(parent.getFont()); - composite.setLayoutData(createHVFillGridData()); - composite.setLayout(createGridLayout(columns, new PixelConverter(parent), margins)); - return composite; - } - - - public static Group createHFillGroup(Composite parent, String text, int margins) { - return createHFillGroup(parent, text, margins, 1); - } - - public static Group createHFillGroup(Composite parent, String text, int margins, int rows) { - final Group group= new Group(parent, SWT.NONE); - group.setFont(parent.getFont()); - group.setLayoutData(createHFillGridData()); - if (text != null) - group.setText(text); - group.setLayout(createGridLayout(rows, new PixelConverter(parent), margins)); - return group; - } - - public static Group createHVFillGroup(Composite parent, String text, int margins) { - return createHVFillGroup(parent, text, margins, 1); - } - - public static Group createHVFillGroup(Composite parent, String text, int margins, int rows) { - final Group group= new Group(parent, SWT.NONE); - group.setFont(parent.getFont()); - group.setLayoutData(createHVFillGridData()); - if (text != null) - group.setText(text); - group.setLayout(createGridLayout(rows, new PixelConverter(parent), margins)); - return group; - } - - public static GridData createHVFillGridData() { - return createHVFillGridData(1); - } - - public static GridData createHVFillGridData(int span) { - final GridData gd= createGridData(0, 0, true, true); - gd.horizontalSpan= span; - return gd; - } - - - /** + final PreferenceLinkArea area = new PreferenceLinkArea(parent, SWT.NONE, pageId, text, container, null); + return area; + } + + public static GridData createGridData(int width, int height, boolean hFill, boolean vFill) { + return createGridData(width, height, hFill ? SWT.FILL : SWT.BEGINNING, vFill ? SWT.FILL : SWT.CENTER, hFill, vFill); + } + + public static GridData createGridData(int width, int height, int hAlign, int vAlign, boolean hGrab, boolean vGrab) { + final GridData gd= new GridData(hAlign, vAlign, hGrab, vGrab); + gd.widthHint= width; + gd.heightHint= height; + return gd; + } + + public static GridData createHFillGridData() { + return createHFillGridData(1); + } + + public static GridData createHFillGridData(int span) { + final GridData gd= createGridData(0, SWT.DEFAULT, SWT.FILL, SWT.CENTER, true, false); + gd.horizontalSpan= span; + return gd; + } + + public static Composite createHFillComposite(Composite parent, int margins) { + return createHFillComposite(parent, margins, 1); + } + + public static Composite createHFillComposite(Composite parent, int margins, int columns) { + final Composite composite= new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + composite.setLayoutData(createHFillGridData()); + composite.setLayout(createGridLayout(columns, new PixelConverter(parent), margins)); + return composite; + } + + public static Composite createHVFillComposite(Composite parent, int margins) { + return createHVFillComposite(parent, margins, 1); + } + + public static Composite createHVFillComposite(Composite parent, int margins, int columns) { + final Composite composite= new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + composite.setLayoutData(createHVFillGridData()); + composite.setLayout(createGridLayout(columns, new PixelConverter(parent), margins)); + return composite; + } + + + public static Group createHFillGroup(Composite parent, String text, int margins) { + return createHFillGroup(parent, text, margins, 1); + } + + public static Group createHFillGroup(Composite parent, String text, int margins, int rows) { + final Group group= new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setLayoutData(createHFillGridData()); + if (text != null) + group.setText(text); + group.setLayout(createGridLayout(rows, new PixelConverter(parent), margins)); + return group; + } + + public static Group createHVFillGroup(Composite parent, String text, int margins) { + return createHVFillGroup(parent, text, margins, 1); + } + + public static Group createHVFillGroup(Composite parent, String text, int margins, int rows) { + final Group group= new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setLayoutData(createHVFillGridData()); + if (text != null) + group.setText(text); + group.setLayout(createGridLayout(rows, new PixelConverter(parent), margins)); + return group; + } + + public static GridData createHVFillGridData() { + return createHVFillGridData(1); + } + + public static GridData createHVFillGridData(int span) { + final GridData gd= createGridData(0, 0, true, true); + gd.horizontalSpan= span; + return gd; + } + + + /** * Create a grid layout with the specified number of columns and the * standard spacings. * @@ -133,96 +133,96 @@ public class SWTUtils { * <code>MARGINS_NONE</code> or <code>MARGINS_DIALOG</code>. * @return the grid layout */ - public static GridLayout createGridLayout(int numColumns, PixelConverter converter, int margins) { - Assert.isTrue(margins == MARGINS_DEFAULT || margins == MARGINS_NONE || margins == MARGINS_DIALOG); - - final GridLayout layout= new GridLayout(numColumns, false); - layout.horizontalSpacing= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.verticalSpacing= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - - switch (margins) { - case MARGINS_NONE: - layout.marginLeft= layout.marginRight= 0; - layout.marginTop= layout.marginBottom= 0; - break; - case MARGINS_DIALOG: - layout.marginLeft= layout.marginRight= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.marginTop= layout.marginBottom= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - break; - case MARGINS_DEFAULT: - layout.marginLeft= layout.marginRight= layout.marginWidth; - layout.marginTop= layout.marginBottom= layout.marginHeight; - } - layout.marginWidth= layout.marginHeight= 0; - return layout; - } - - - public static Label createLabel(Composite parent, String message) { - return createLabel(parent, message, 1); - } - - public static Label createLabel(Composite parent, String message, int span) { - final Label label= new Label(parent, SWT.WRAP); - if (message != null) - label.setText(message); - label.setLayoutData(createHFillGridData(span)); - return label; - } - - public static Button createCheckBox(Composite parent, String message) { - return createCheckBox(parent, message, 1); - } - - public static Button createCheckBox(Composite parent, String message, int span) { - final Button button= new Button(parent, SWT.CHECK); - button.setText(message); - button.setLayoutData(createHFillGridData(span)); - return button; - } - - public static Button createRadioButton(Composite parent, String message) { - return createRadioButton(parent, message, 1); - } - - public static Button createRadioButton(Composite parent, String message, int span) { - final Button button= new Button(parent, SWT.RADIO); - button.setText(message); - button.setLayoutData(createHFillGridData(span)); - return button; - } - - - public static Text createText(Composite parent) { - return createText(parent, 1); - } - - public static Text createText(Composite parent, int span) { - final Text text= new Text(parent, SWT.SINGLE | SWT.BORDER); - text.setLayoutData(createHFillGridData(span)); - return text; - } - - - public static Control createPlaceholder(Composite parent, int heightInChars, int span) { - Assert.isTrue(heightInChars > 0); - final Control placeHolder= new Composite(parent, SWT.NONE); - final GridData gd= new GridData(SWT.BEGINNING, SWT.TOP, false, false); - gd.heightHint= new PixelConverter(parent).convertHeightInCharsToPixels(heightInChars); - gd.horizontalSpan= span; - placeHolder.setLayoutData(gd); - return placeHolder; - } - - - public static Control createPlaceholder(Composite parent, int heightInChars) { - return createPlaceholder(parent, heightInChars, 1); - } - - public static PixelConverter createDialogPixelConverter(Control control) { - Dialog.applyDialogFont(control); - return new PixelConverter(control); - } + public static GridLayout createGridLayout(int numColumns, PixelConverter converter, int margins) { + Assert.isTrue(margins == MARGINS_DEFAULT || margins == MARGINS_NONE || margins == MARGINS_DIALOG); + + final GridLayout layout= new GridLayout(numColumns, false); + layout.horizontalSpacing= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + layout.verticalSpacing= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + + switch (margins) { + case MARGINS_NONE: + layout.marginLeft= layout.marginRight= 0; + layout.marginTop= layout.marginBottom= 0; + break; + case MARGINS_DIALOG: + layout.marginLeft= layout.marginRight= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.marginTop= layout.marginBottom= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + break; + case MARGINS_DEFAULT: + layout.marginLeft= layout.marginRight= layout.marginWidth; + layout.marginTop= layout.marginBottom= layout.marginHeight; + } + layout.marginWidth= layout.marginHeight= 0; + return layout; + } + + + public static Label createLabel(Composite parent, String message) { + return createLabel(parent, message, 1); + } + + public static Label createLabel(Composite parent, String message, int span) { + final Label label= new Label(parent, SWT.WRAP); + if (message != null) + label.setText(message); + label.setLayoutData(createHFillGridData(span)); + return label; + } + + public static Button createCheckBox(Composite parent, String message) { + return createCheckBox(parent, message, 1); + } + + public static Button createCheckBox(Composite parent, String message, int span) { + final Button button= new Button(parent, SWT.CHECK); + button.setText(message); + button.setLayoutData(createHFillGridData(span)); + return button; + } + + public static Button createRadioButton(Composite parent, String message) { + return createRadioButton(parent, message, 1); + } + + public static Button createRadioButton(Composite parent, String message, int span) { + final Button button= new Button(parent, SWT.RADIO); + button.setText(message); + button.setLayoutData(createHFillGridData(span)); + return button; + } + + + public static Text createText(Composite parent) { + return createText(parent, 1); + } + + public static Text createText(Composite parent, int span) { + final Text text= new Text(parent, SWT.SINGLE | SWT.BORDER); + text.setLayoutData(createHFillGridData(span)); + return text; + } + + + public static Control createPlaceholder(Composite parent, int heightInChars, int span) { + Assert.isTrue(heightInChars > 0); + final Control placeHolder= new Composite(parent, SWT.NONE); + final GridData gd= new GridData(SWT.BEGINNING, SWT.TOP, false, false); + gd.heightHint= new PixelConverter(parent).convertHeightInCharsToPixels(heightInChars); + gd.horizontalSpan= span; + placeHolder.setLayoutData(gd); + return placeHolder; + } + + + public static Control createPlaceholder(Composite parent, int heightInChars) { + return createPlaceholder(parent, heightInChars, 1); + } + + public static PixelConverter createDialogPixelConverter(Control control) { + Dialog.applyDialogFont(control); + return new PixelConverter(control); + } public static int calculateControlSize(PixelConverter converter, Control [] controls) { return calculateControlSize(converter, controls, 0, controls.length - 1); diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/ui/UserInfoPrompter.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/ui/UserInfoPrompter.java index 85791a697..c22515f2c 100644 --- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/ui/UserInfoPrompter.java +++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/ui/UserInfoPrompter.java @@ -40,227 +40,227 @@ import com.jcraft.jsch.UserInfo; */ public class UserInfoPrompter implements UserInfo, UIKeyboardInteractive{ - private String passphrase; - private String password; - private final Session session; - private int attemptCount; + private String passphrase; + private String password; + private final Session session; + private int attemptCount; - /** - * Create a prompter for the given session. This constructor will associate - * this prompter with the session using {@link Session#setUserInfo(UserInfo)}. - * - * @param session - * the session - */ - public UserInfoPrompter(Session session){ - super(); - this.session=session; - session.setUserInfo(this); - } + /** + * Create a prompter for the given session. This constructor will associate + * this prompter with the session using {@link Session#setUserInfo(UserInfo)}. + * + * @param session + * the session + */ + public UserInfoPrompter(Session session){ + super(); + this.session=session; + session.setUserInfo(this); + } - /** - * Return the session to which this prompter is assigned. - * - * @return the session to which this prompter is assigned - */ - public Session getSession(){ - return session; - } + /** + * Return the session to which this prompter is assigned. + * + * @return the session to which this prompter is assigned + */ + public Session getSession(){ + return session; + } - @Override + @Override public String getPassphrase(){ - return passphrase; - } + return passphrase; + } - @Override + @Override public String getPassword(){ - return password; - } + return password; + } - /** - * Set the pass phrase to be used when connecting the session. Return - * <code>null</code> if the pass phrase is not known. - * - * @param passphrase - * the pass phrase to be used when connecting the session or - * <code>null</code> - */ - public void setPassphrase(String passphrase){ - this.passphrase=passphrase; - } + /** + * Set the pass phrase to be used when connecting the session. Return + * <code>null</code> if the pass phrase is not known. + * + * @param passphrase + * the pass phrase to be used when connecting the session or + * <code>null</code> + */ + public void setPassphrase(String passphrase){ + this.passphrase=passphrase; + } - /** - * Set the password to be used when connecting the session. Return - * <code>null</code> if the password is not known. - * - * @param password - * the password to be used when connecting the session or - * <code>null</code> - */ - public void setPassword(String password){ - this.password=password; - } + /** + * Set the password to be used when connecting the session. Return + * <code>null</code> if the password is not known. + * + * @param password + * the password to be used when connecting the session or + * <code>null</code> + */ + public void setPassword(String password){ + this.password=password; + } - @Override + @Override public boolean promptPassphrase(String message){ - String _passphrase=promptSecret(message); - if(_passphrase!=null){ - setPassphrase(_passphrase); - } - return _passphrase!=null; - } + String _passphrase=promptSecret(message); + if(_passphrase!=null){ + setPassphrase(_passphrase); + } + return _passphrase!=null; + } - @Override + @Override public boolean promptPassword(String message){ - String _password=promptSecret(message); - if(_password!=null){ - setPassword(_password); - } - return _password!=null; - } + String _password=promptSecret(message); + if(_password!=null){ + setPassword(_password); + } + return _password!=null; + } - private String promptSecret(final String message){ - // ask the user for a password - final String[] result=new String[1]; - Display display=Display.getCurrent(); - if(display!=null){ - result[0]=promptForPassword(message); - } - else{ - // sync exec in default thread + private String promptSecret(final String message){ + // ask the user for a password + final String[] result=new String[1]; + Display display=Display.getCurrent(); + if(display!=null){ + result[0]=promptForPassword(message); + } + else{ + // sync exec in default thread Display.getDefault().syncExec(() -> result[0] = promptForPassword(message)); - } + } - if(result[0]==null){ - throw new OperationCanceledException(); - } - return result[0]; - } + if(result[0]==null){ + throw new OperationCanceledException(); + } + return result[0]; + } - /* package */String promptForPassword(final String message){ - String username=getSession().getUserName(); - UserValidationDialog dialog=new UserValidationDialog(null, null, - (username==null) ? "" : username, message); //$NON-NLS-1$ - dialog.setUsernameMutable(false); - dialog.open(); - return dialog.getPassword(); - } + /* package */String promptForPassword(final String message){ + String username=getSession().getUserName(); + UserValidationDialog dialog=new UserValidationDialog(null, null, + (username==null) ? "" : username, message); //$NON-NLS-1$ + dialog.setUsernameMutable(false); + dialog.open(); + return dialog.getPassword(); + } - @Override + @Override public String[] promptKeyboardInteractive(String destination, String name, - String instruction, String[] prompt, boolean[] echo){ - if(prompt.length==0){ - // No need to prompt, just return an empty String array - return new String[0]; - } - try{ - if(attemptCount==0&&password!=null&&prompt.length==1 - &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ - // Return the provided password the first time but always prompt on - // subsequent tries - attemptCount++; - return new String[] {password}; - } - String[] result=promptForKeyboradInteractiveInUI(destination, name, - instruction, prompt, echo); - if(result==null) - return null; // canceled - if(result.length==1&&prompt.length==1 - &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ - password=result[0]; - } - attemptCount++; - return result; - } - catch(OperationCanceledException e){ - return null; - } - } + String instruction, String[] prompt, boolean[] echo){ + if(prompt.length==0){ + // No need to prompt, just return an empty String array + return new String[0]; + } + try{ + if(attemptCount==0&&password!=null&&prompt.length==1 + &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ + // Return the provided password the first time but always prompt on + // subsequent tries + attemptCount++; + return new String[] {password}; + } + String[] result=promptForKeyboradInteractiveInUI(destination, name, + instruction, prompt, echo); + if(result==null) + return null; // canceled + if(result.length==1&&prompt.length==1 + &&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$ + password=result[0]; + } + attemptCount++; + return result; + } + catch(OperationCanceledException e){ + return null; + } + } - private String[] promptForKeyboradInteractiveInUI(final String destination, - final String name, final String instruction, final String[] prompt, - final boolean[] echo){ - final String[][] result=new String[1][]; - Display display=Display.getCurrent(); - if(display!=null){ - result[0]=internalPromptForUserInteractive(destination, name, - instruction, prompt, echo); - } - else{ - // sync exec in default thread + private String[] promptForKeyboradInteractiveInUI(final String destination, + final String name, final String instruction, final String[] prompt, + final boolean[] echo){ + final String[][] result=new String[1][]; + Display display=Display.getCurrent(); + if(display!=null){ + result[0]=internalPromptForUserInteractive(destination, name, + instruction, prompt, echo); + } + else{ + // sync exec in default thread Display.getDefault().syncExec( () -> result[0] = internalPromptForUserInteractive(destination, name, instruction, prompt, echo)); - } - return result[0]; - } + } + return result[0]; + } - /* package */ String[] internalPromptForUserInteractive(String destination, - String name, String instruction, String[] prompt, boolean[] echo){ - String domain=null; - String userName=getSession().getUserName(); - KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(null, - domain, destination, name, userName, instruction, prompt, echo); - dialog.open(); - String[] _result=dialog.getResult(); - return _result; - } + /* package */ String[] internalPromptForUserInteractive(String destination, + String name, String instruction, String[] prompt, boolean[] echo){ + String domain=null; + String userName=getSession().getUserName(); + KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(null, + domain, destination, name, userName, instruction, prompt, echo); + dialog.open(); + String[] _result=dialog.getResult(); + return _result; + } - @Override + @Override public boolean promptYesNo(String question){ - int prompt=prompt(MessageDialog.QUESTION, Messages.UserInfoPrompter_0, - question, new int[] {IDialogConstants.YES_ID, IDialogConstants.NO_ID}, - 0 // yes - // the - // default - ); - return prompt==0; - } + int prompt=prompt(MessageDialog.QUESTION, Messages.UserInfoPrompter_0, + question, new int[] {IDialogConstants.YES_ID, IDialogConstants.NO_ID}, + 0 // yes + // the + // default + ); + return prompt==0; + } - @Override + @Override public void showMessage(String message){ - prompt(MessageDialog.INFORMATION, Messages.UserInfoPrompter_1, message, - new int[] {IDialogConstants.OK_ID}, 0); - } + prompt(MessageDialog.INFORMATION, Messages.UserInfoPrompter_1, message, + new int[] {IDialogConstants.OK_ID}, 0); + } - private int prompt(final int promptType, final String title, - final String message, final int[] promptResponses, - final int defaultResponse){ - final Display display=getStandardDisplay(); - final int[] retval=new int[1]; - final String[] buttons=new String[promptResponses.length]; - for(int i=0; i<promptResponses.length; i++){ - int prompt=promptResponses[i]; - switch(prompt){ - case IDialogConstants.OK_ID: - buttons[i]=IDialogConstants.OK_LABEL; - break; - case IDialogConstants.CANCEL_ID: - buttons[i]=IDialogConstants.CANCEL_LABEL; - break; - case IDialogConstants.NO_ID: - buttons[i]=IDialogConstants.NO_LABEL; - break; - case IDialogConstants.YES_ID: - buttons[i]=IDialogConstants.YES_LABEL; - break; - } - } + private int prompt(final int promptType, final String title, + final String message, final int[] promptResponses, + final int defaultResponse){ + final Display display=getStandardDisplay(); + final int[] retval=new int[1]; + final String[] buttons=new String[promptResponses.length]; + for(int i=0; i<promptResponses.length; i++){ + int prompt=promptResponses[i]; + switch(prompt){ + case IDialogConstants.OK_ID: + buttons[i]=IDialogConstants.OK_LABEL; + break; + case IDialogConstants.CANCEL_ID: + buttons[i]=IDialogConstants.CANCEL_LABEL; + break; + case IDialogConstants.NO_ID: + buttons[i]=IDialogConstants.NO_LABEL; + break; + case IDialogConstants.YES_ID: + buttons[i]=IDialogConstants.YES_LABEL; + break; + } + } display.syncExec(() -> { - final MessageDialog dialog=new MessageDialog(new Shell(display), title, - null /* title image */, message, promptType, buttons, - defaultResponse); - retval[0]=dialog.open(); + final MessageDialog dialog=new MessageDialog(new Shell(display), title, + null /* title image */, message, promptType, buttons, + defaultResponse); + retval[0]=dialog.open(); }); - return retval[0]; - } + return retval[0]; + } - private Display getStandardDisplay(){ - Display display=Display.getCurrent(); - if(display==null){ - display=Display.getDefault(); - } - return display; - } + private Display getStandardDisplay(){ + Display display=Display.getCurrent(); + if(display==null){ + display=Display.getDefault(); + } + return display; + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileContentManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileContentManager.java index e8c63f69c..bbc9a275c 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileContentManager.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileContentManager.java @@ -46,145 +46,145 @@ import org.eclipse.core.resources.IStorage; */ public interface IFileContentManager { - /** - * Get the content type for a given instance of <code>IStorage</code>. User-defined mappings - * take precedence over plugin-contributed mappings; further, mappings for the entire file name - * take precedence over mappings for the file extension only. - * - * @param storage the instance of <code>IStorage</code>. - * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. - * - * @since 3.1 - */ - int getType(IStorage storage); - - /** - * Check whether the given file name is assigned to a specific type in the content type registry. - * @param filename the file name to check for - * @return True if the file name is registered in the system and assigned to a content type, false - * if the file name is unknown. - * - * @since 3.1 - */ - boolean isKnownFilename(String filename); - - /** - * Check whether the given file extension is assigned to a specific type in the content type registry. - * @param extension the extension to check for - * @return True if the extension is registered in the system and assigned to a content type, false - * if the extension is unknown. - * - * @since 3.1 - */ - boolean isKnownExtension(String extension); - - /** - * Get the content type for a given file name. - * @param filename The file name - * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. - * - * @since 3.1 - */ - int getTypeForName(String filename); - - /** - * Get the content type for a given file extension. - * @param extension The extension - * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. - * - * @since 3.1 - */ - int getTypeForExtension(String extension); - - /** - * Map a set of file names to a set of content types and save the mappings in - * the preferences. Already existing mappings for these file names are updated - * with the new ones, other mappings will be preserved. - * - * @param names The file names - * @param types The corresponding types, each one being one of - * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or - * <code>Team.BINARY</code>. - * - * @since 3.1 - */ - void addNameMappings(String[] names, int[] types); - - /** - * Map a set of file extensions to a set of content types and save the mapping in - * the preferences. Already existing mappings for these extensions are updated - * with the new ones, other mappings will be preserved. - * - * @param extensions The extensions - * @param types The corresponding types, each one being one of - * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or - * <code>Team.BINARY</code>. - * - * @since 3.1 - */ - void addExtensionMappings(String[] extensions, int[] types); - - /** - * Map a set of file names to a set of content types and save the mappings in - * the preferences. All existing user-defined mappings for <b>any - * </b> file names are deleted and replaced by the new ones. - * - * @param names The file names - * @param types The corresponding types, each one being one of - * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or - * <code>Team.BINARY</code>. - * - * @since 3.1 - */ - void setNameMappings(String[] names, int[] types); - - /** - * Map a set of file extensions to a set of content types and save the - * mapping in the preferences. All existing user-defined mappings for <b>any - * </b> file extensions are deleted and replaced by the new ones. - * - * @param extensions The extensions - * @param types The corresponding types, each one being one of - * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or - * <code>Team.BINARY</code>. - * - * @since 3.1 - */ - void setExtensionMappings(String[] extensions, int[] types); - - /** - * Get all the currently defined mappings from file names to content types. - * - * @return the mappings - * - * @since 3.1 - */ - IStringMapping [] getNameMappings(); - - /** - * Get all the currently defined mappings from file names to content types. - * - * @return the mappings - * - * @since 3.1 - */ - IStringMapping [] getExtensionMappings(); - - /** - * Get all the plugin-contributed mappings from file names to content types. - * - * @return the mappings - * - * @since 3.1 - */ - IStringMapping [] getDefaultNameMappings(); - - /** - * Get all the plugin-contributed mappings from file extensions to content types. - * - * @return the mappings - - * @since 3.1 - */ - IStringMapping [] getDefaultExtensionMappings(); + /** + * Get the content type for a given instance of <code>IStorage</code>. User-defined mappings + * take precedence over plugin-contributed mappings; further, mappings for the entire file name + * take precedence over mappings for the file extension only. + * + * @param storage the instance of <code>IStorage</code>. + * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. + * + * @since 3.1 + */ + int getType(IStorage storage); + + /** + * Check whether the given file name is assigned to a specific type in the content type registry. + * @param filename the file name to check for + * @return True if the file name is registered in the system and assigned to a content type, false + * if the file name is unknown. + * + * @since 3.1 + */ + boolean isKnownFilename(String filename); + + /** + * Check whether the given file extension is assigned to a specific type in the content type registry. + * @param extension the extension to check for + * @return True if the extension is registered in the system and assigned to a content type, false + * if the extension is unknown. + * + * @since 3.1 + */ + boolean isKnownExtension(String extension); + + /** + * Get the content type for a given file name. + * @param filename The file name + * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. + * + * @since 3.1 + */ + int getTypeForName(String filename); + + /** + * Get the content type for a given file extension. + * @param extension The extension + * @return one of <code>Team.UNKNOWN</code>, <code>Team.TEXT</code> or <code>Team.BINARY</code>. + * + * @since 3.1 + */ + int getTypeForExtension(String extension); + + /** + * Map a set of file names to a set of content types and save the mappings in + * the preferences. Already existing mappings for these file names are updated + * with the new ones, other mappings will be preserved. + * + * @param names The file names + * @param types The corresponding types, each one being one of + * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or + * <code>Team.BINARY</code>. + * + * @since 3.1 + */ + void addNameMappings(String[] names, int[] types); + + /** + * Map a set of file extensions to a set of content types and save the mapping in + * the preferences. Already existing mappings for these extensions are updated + * with the new ones, other mappings will be preserved. + * + * @param extensions The extensions + * @param types The corresponding types, each one being one of + * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or + * <code>Team.BINARY</code>. + * + * @since 3.1 + */ + void addExtensionMappings(String[] extensions, int[] types); + + /** + * Map a set of file names to a set of content types and save the mappings in + * the preferences. All existing user-defined mappings for <b>any + * </b> file names are deleted and replaced by the new ones. + * + * @param names The file names + * @param types The corresponding types, each one being one of + * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or + * <code>Team.BINARY</code>. + * + * @since 3.1 + */ + void setNameMappings(String[] names, int[] types); + + /** + * Map a set of file extensions to a set of content types and save the + * mapping in the preferences. All existing user-defined mappings for <b>any + * </b> file extensions are deleted and replaced by the new ones. + * + * @param extensions The extensions + * @param types The corresponding types, each one being one of + * <code>Team.UNKNOWN</code>,<code>Team.TEXT</code> or + * <code>Team.BINARY</code>. + * + * @since 3.1 + */ + void setExtensionMappings(String[] extensions, int[] types); + + /** + * Get all the currently defined mappings from file names to content types. + * + * @return the mappings + * + * @since 3.1 + */ + IStringMapping [] getNameMappings(); + + /** + * Get all the currently defined mappings from file names to content types. + * + * @return the mappings + * + * @since 3.1 + */ + IStringMapping [] getExtensionMappings(); + + /** + * Get all the plugin-contributed mappings from file names to content types. + * + * @return the mappings + * + * @since 3.1 + */ + IStringMapping [] getDefaultNameMappings(); + + /** + * Get all the plugin-contributed mappings from file extensions to content types. + * + * @return the mappings + + * @since 3.1 + */ + IStringMapping [] getDefaultExtensionMappings(); } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IStringMapping.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IStringMapping.java index f62bbe399..ac54d1ddd 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IStringMapping.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IStringMapping.java @@ -24,21 +24,21 @@ package org.eclipse.team.core; */ public interface IStringMapping { - /** - * The string part of the mapping - * - * @return the string - * - * @since 3.1 - */ - String getString(); + /** + * The string part of the mapping + * + * @return the string + * + * @since 3.1 + */ + String getString(); - /** - * The content type associated with the string - * - * @return the content type - * - * @since 3.1 - */ - int getType(); + /** + * The content type associated with the string + * + * @return the content type + * + * @since 3.1 + */ + int getType(); } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java index e2a5c5e19..b6473385a 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java @@ -244,9 +244,9 @@ public abstract class ProjectSetCapability { IProject eachProj = projects[i]; if (eachProj.exists()) { existingProjects.add(eachProj); - } else if (new File(eachProj.getParent().getLocation().toFile(), eachProj.getName()).exists()) { - existingProjects.add(eachProj); - } + } else if (new File(eachProj.getParent().getLocation().toFile(), eachProj.getName()).exists()) { + existingProjects.add(eachProj); + } } if (existingProjects.size() == 0) return projects; diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java index d2f4c70f9..8e4ba1259 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java @@ -100,8 +100,8 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { // lock to ensure that map/unmap and getProvider support concurrency private static final ILock mappingLock = Job.getJobManager().newLock(); - // Session property used to identify projects that are not mapped - private static final Object NOT_MAPPED = new Object(); + // Session property used to identify projects that are not mapped + private static final Object NOT_MAPPED = new Object(); /** * Instantiate a new RepositoryProvider with concrete class by given providerID @@ -330,10 +330,10 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { */ private static RepositoryProvider lookupProviderProp(IProject project) throws CoreException { Object provider = project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY); - if (provider instanceof RepositoryProvider) { - return (RepositoryProvider) provider; - } - return null; + if (provider instanceof RepositoryProvider) { + return (RepositoryProvider) provider; + } + return null; } @@ -394,12 +394,12 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { /** * Returns an <code>IFileModificationValidator</code> for pre-checking operations - * that modify the contents of files. - * Returns <code>null</code> if the provider does not wish to participate in - * file modification validation. + * that modify the contents of files. + * Returns <code>null</code> if the provider does not wish to participate in + * file modification validation. * @return an <code>IFileModificationValidator</code> for pre-checking operations - * that modify the contents of files - * + * that modify the contents of files + * * @see org.eclipse.core.resources.IFileModificationValidator * @deprecated use {@link #getFileModificationValidator2()} */ @@ -460,7 +460,7 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { * @since 3.2 */ public IFileHistoryProvider getFileHistoryProvider(){ - return null; + return null; } /** @@ -532,10 +532,10 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { RepositoryProvider provider = lookupProviderProp(project); if(provider != null) return provider; - // Do a quick check to see it the project is known to be unshared. - // This is done to avoid accessing the persistent property store - if (isMarkedAsUnshared(project)) - return null; + // Do a quick check to see it the project is known to be unshared. + // This is done to avoid accessing the persistent property store + if (isMarkedAsUnshared(project)) + return null; // ----------------------------- //Next, check if it has the ID as a persistent property, if yes then instantiate provider @@ -603,10 +603,10 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { return null; } } - // Do a quick check to see it the project is known to be unshared. - // This is done to avoid accessing the persistent property store - if (isMarkedAsUnshared(project)) - return null; + // Do a quick check to see it the project is known to be unshared. + // This is done to avoid accessing the persistent property store + if (isMarkedAsUnshared(project)) + return null; // There isn't one so check the persistent property String existingID = project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY); @@ -666,14 +666,14 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { if (!project.isAccessible()) return false; try { if (lookupProviderProp(project) != null) return true; - // Do a quick check to see it the project is known to be unshared. - // This is done to avoid accessing the persistent property store - if (isMarkedAsUnshared(project)) - return false; + // Do a quick check to see it the project is known to be unshared. + // This is done to avoid accessing the persistent property store + if (isMarkedAsUnshared(project)) + return false; boolean shared = project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY) != null; - if (!shared) - markAsUnshared(project); - return shared; + if (!shared) + markAsUnshared(project); + return shared; } catch (CoreException e) { TeamPlugin.log(e); return false; @@ -681,20 +681,20 @@ public abstract class RepositoryProvider implements IProjectNature, IAdaptable { } private static boolean isMarkedAsUnshared(IProject project) { - try { - return project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY) == NOT_MAPPED; - } catch (CoreException e) { - return false; - } - } - - private static void markAsUnshared(IProject project) { - try { - project.setSessionProperty(TeamPlugin.PROVIDER_PROP_KEY, NOT_MAPPED); - } catch (CoreException e) { - // Just ignore the error as this is just an optimization - } - } + try { + return project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY) == NOT_MAPPED; + } catch (CoreException e) { + return false; + } + } + + private static void markAsUnshared(IProject project) { + try { + project.setSessionProperty(TeamPlugin.PROVIDER_PROP_KEY, NOT_MAPPED); + } catch (CoreException e) { + // Just ignore the error as this is just an optimization + } + } @Override public IProject getProject() { diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java index 219100a99..62ca83791 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java @@ -233,9 +233,9 @@ public abstract class RepositoryProviderType extends PlatformObject { * or in any way modify workspace resources (including auto-sharing the project). However, * auto-sharing (or other modification) could be performed by a background job scheduled from * this callback. - * - * @since 3.1 - * + * + * @since 3.1 + * * @param project the project that contains the detected meta-files. * @param containers the folders (possibly including the project folder) in which meta-files were found */ diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java index 480c90177..d65e49f24 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java @@ -65,25 +65,25 @@ import org.eclipse.team.internal.core.importing.BundleImporterExtension; */ public final class Team { - private static class StringMappingWrapper implements IFileTypeInfo { + private static class StringMappingWrapper implements IFileTypeInfo { - private final IStringMapping fMapping; + private final IStringMapping fMapping; - public StringMappingWrapper(IStringMapping mapping) { - fMapping= mapping; - } + public StringMappingWrapper(IStringMapping mapping) { + fMapping= mapping; + } - @Override + @Override public String getExtension() { - return fMapping.getString(); - } + return fMapping.getString(); + } - @Override + @Override public int getType() { - return fMapping.getType(); - } + return fMapping.getType(); + } - } + } private static final String PREF_TEAM_IGNORES = "ignore_files"; //$NON-NLS-1$ private static final String PREF_TEAM_SEPARATOR = "\n"; //$NON-NLS-1$ @@ -99,19 +99,19 @@ public final class Team { protected static SortedMap<String, Boolean> globalIgnore, pluginIgnore; private static StringMatcher[] ignoreMatchers; - private final static FileContentManager fFileContentManager; + private final static FileContentManager fFileContentManager; private static List<IBundleImporter> fBundleImporters; - static { - fFileContentManager= new FileContentManager(); - } + static { + fFileContentManager= new FileContentManager(); + } /** - * Return the type of the given IStorage. First, we check whether a mapping has - * been defined for the name of the IStorage. If this is not the case, we check for - * a mapping with the extension. If no mapping is defined, UNKNOWN is returned. + * Return the type of the given IStorage. First, we check whether a mapping has + * been defined for the name of the IStorage. If this is not the case, we check for + * a mapping with the extension. If no mapping is defined, UNKNOWN is returned. * * Valid return values are: * Team.TEXT @@ -120,12 +120,12 @@ public final class Team { * * @param storage the IStorage * @return whether the given IStorage is TEXT, BINARY, or UNKNOWN - * - * @deprecated Use <code>getFileContentManager().getType(IStorage storage)</code> instead. + * + * @deprecated Use <code>getFileContentManager().getType(IStorage storage)</code> instead. */ @Deprecated public static int getType(IStorage storage) { - return fFileContentManager.getType(storage); + return fFileContentManager.getType(storage); } /** @@ -179,19 +179,19 @@ public final class Team { /** - * Return all known file types. + * Return all known file types. * * @return all known file types - * @deprecated Use <code>getFileContentManager().getExtensionMappings()</code> instead. + * @deprecated Use <code>getFileContentManager().getExtensionMappings()</code> instead. */ @Deprecated public static IFileTypeInfo[] getAllTypes() { - final IStringMapping [] mappings= fFileContentManager.getExtensionMappings(); - final IFileTypeInfo [] infos= new IFileTypeInfo[mappings.length]; - for (int i = 0; i < infos.length; i++) { - infos[i]= new StringMappingWrapper(mappings[i]); - } - return infos; + final IStringMapping [] mappings= fFileContentManager.getExtensionMappings(); + final IFileTypeInfo [] infos= new IFileTypeInfo[mappings.length]; + for (int i = 0; i < infos.length; i++) { + infos[i]= new StringMappingWrapper(mappings[i]); + } + return infos; } /** @@ -262,8 +262,8 @@ public final class Team { /** - * Set the file type for the give extensions. This - * will replace the existing file types with this new list. + * Set the file type for the give extensions. This + * will replace the existing file types with this new list. * * Valid types are: * Team.TEXT @@ -272,12 +272,12 @@ public final class Team { * * @param extensions the file extensions * @param types the file types - * - * @deprecated Use <code>getFileContentManager().setExtensionMappings()</code> instead. + * + * @deprecated Use <code>getFileContentManager().setExtensionMappings()</code> instead. */ @Deprecated public static void setAllTypes(String[] extensions, int[] types) { - fFileContentManager.addExtensionMappings(extensions, types); + fFileContentManager.addExtensionMappings(extensions, types); } /** @@ -529,40 +529,40 @@ public final class Team { } /** - * TODO: change to file content manager + * TODO: change to file content manager * Return the default file type bindings * (i.e. those that are specified in * plugin manifests). * @return the default file type bindings * @since 3.0 - * @deprecated Use Team.getFileContentManager().getDefaultExtensionMappings() instead. + * @deprecated Use Team.getFileContentManager().getDefaultExtensionMappings() instead. */ @Deprecated public static IFileTypeInfo[] getDefaultTypes() { - return asFileTypeInfo(getFileContentManager().getDefaultExtensionMappings()); + return asFileTypeInfo(getFileContentManager().getDefaultExtensionMappings()); } - private static IFileTypeInfo [] asFileTypeInfo(IStringMapping [] mappings) { - final IFileTypeInfo [] infos= new IFileTypeInfo[mappings.length]; - for (int i = 0; i < infos.length; i++) { - infos[i]= new StringMappingWrapper(mappings[i]); - } - return infos; - } - - /** - * Get the file content manager which implements the API for manipulating the mappings between - * file names, file extensions and content types. - * - * @return an instance of IFileContentManager - * - * @see IFileContentManager - * - * @since 3.1 - */ - public static IFileContentManager getFileContentManager() { - return fFileContentManager; - } + private static IFileTypeInfo [] asFileTypeInfo(IStringMapping [] mappings) { + final IFileTypeInfo [] infos= new IFileTypeInfo[mappings.length]; + for (int i = 0; i < infos.length; i++) { + infos[i]= new StringMappingWrapper(mappings[i]); + } + return infos; + } + + /** + * Get the file content manager which implements the API for manipulating the mappings between + * file names, file extensions and content types. + * + * @return an instance of IFileContentManager + * + * @see IFileContentManager + * + * @since 3.1 + */ + public static IFileContentManager getFileContentManager() { + return fFileContentManager; + } /** * Creates a storage merger for the given content type. @@ -574,9 +574,9 @@ public final class Team { * * @since 3.4 */ - public static IStorageMerger createMerger(IContentType type) { - return StorageMergerRegistry.getInstance().createStreamMerger(type); - } + public static IStorageMerger createMerger(IContentType type) { + return StorageMergerRegistry.getInstance().createStreamMerger(type); + } /** * Creates a storage merger for the given file extension. @@ -588,9 +588,9 @@ public final class Team { * * @since 3.4 */ - public static IStorageMerger createMerger(String extension) { - return StorageMergerRegistry.getInstance().createStreamMerger(extension); - } + public static IStorageMerger createMerger(String extension) { + return StorageMergerRegistry.getInstance().createStreamMerger(extension); + } /** * Creates a storage merger for the given content type. @@ -602,10 +602,10 @@ public final class Team { * @deprecated Use {@link #createMerger(IContentType)} instead. * @since 3.2 */ - @Deprecated + @Deprecated public IStorageMerger createStorageMerger(IContentType type) { - return createMerger(type); - } + return createMerger(type); + } /** * Creates a storage merger for the given file extension. @@ -617,10 +617,10 @@ public final class Team { * @deprecated Use {@link #createMerger(String)} instead. * @since 3.2 */ - @Deprecated + @Deprecated public IStorageMerger createStorageMerger(String extension) { - return createMerger(extension); - } + return createMerger(extension); + } /** * Returns the available bundle importers. diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java index 1a9cb6870..d97a47cb6 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java @@ -32,10 +32,10 @@ import org.eclipse.team.internal.core.TeamPlugin; */ public class TeamException extends CoreException { - // Field required to avoid compiler warning + // Field required to avoid compiler warning private static final long serialVersionUID = 1L; - // The operation completed successfully. + // The operation completed successfully. public static final int OK = 0; // The operation failed because the resource is not checked-in. diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/history/IFileRevision.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/history/IFileRevision.java index a4bdf84c3..80fcc52ea 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/history/IFileRevision.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/history/IFileRevision.java @@ -102,8 +102,8 @@ public interface IFileRevision { * Returns the branches names of file revision. * * @return an array of ITag's if branch names exist for this revision - * or an empty ITag array if no names exist - * @since 3.6 + * or an empty ITag array if no names exist + * @since 3.6 */ public ITag[] getBranches(); diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingMerger.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingMerger.java index 36a95954f..1180d7bdf 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingMerger.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IResourceMappingMerger.java @@ -49,7 +49,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; */ public interface IResourceMappingMerger { - /** + /** * Attempt to automatically merge the mappings of the merge context(<code>MergeContext#getMappings()</code>). * The merge context provides access to the out-of-sync resources (<code>MergeContext#getSyncInfoTree()</code>) * associated with the mappings to be merged. The set of provided mappings @@ -86,48 +86,48 @@ public interface IResourceMappingMerger { * <code>MergeStatus#getConflictingMappings()</code> * @throws CoreException if errors occurred */ - public IStatus merge(IMergeContext mergeContext, - IProgressMonitor monitor) throws CoreException; + public IStatus merge(IMergeContext mergeContext, + IProgressMonitor monitor) throws CoreException; - /** - * Return the scheduling rule that is required to merge - * all the changes that apply to this merger in the given - * context. When calling {@link #merge(IMergeContext, IProgressMonitor)}, - * clients must ensure that they either have obtained - * a rule that covers the rule returned by this method or - * they must not hold any rule. - * @param context the context that contains the changes to be merged - * @return the scheduling rule required by this merger to merge all - * the changes in the given context belonging to the merger's - * model provider. - */ - public ISchedulingRule getMergeRule(IMergeContext context); + /** + * Return the scheduling rule that is required to merge + * all the changes that apply to this merger in the given + * context. When calling {@link #merge(IMergeContext, IProgressMonitor)}, + * clients must ensure that they either have obtained + * a rule that covers the rule returned by this method or + * they must not hold any rule. + * @param context the context that contains the changes to be merged + * @return the scheduling rule required by this merger to merge all + * the changes in the given context belonging to the merger's + * model provider. + */ + public ISchedulingRule getMergeRule(IMergeContext context); - /** - * Validate an auto-merge for the given context. This - * method must be invoked for all mergers involved - * in the merge before the auto-merge is attempted. - * The purpose of the validation is to indicate whether there - * are conditions in the merge context that make an auto-merge - * undesirable. The purpose is not to indicate that conflicts - * exist (this is done by the <code>merge</code> method) but instead - * to indicate that the nature of one of more incoming changes - * is such that performing an auto-merge may be undesirable. - * <p> - * Clients should validate before performing the merge and, if - * any of the returned status are not OK, should prompt the - * user to make them aware of the potential side effects. - * The user may still decide to attempt an auto-merge, in which case - * the client may still invoke the <code>merge</code> method. - * + /** + * Validate an auto-merge for the given context. This + * method must be invoked for all mergers involved + * in the merge before the auto-merge is attempted. + * The purpose of the validation is to indicate whether there + * are conditions in the merge context that make an auto-merge + * undesirable. The purpose is not to indicate that conflicts + * exist (this is done by the <code>merge</code> method) but instead + * to indicate that the nature of one of more incoming changes + * is such that performing an auto-merge may be undesirable. + * <p> + * Clients should validate before performing the merge and, if + * any of the returned status are not OK, should prompt the + * user to make them aware of the potential side effects. + * The user may still decide to attempt an auto-merge, in which case + * the client may still invoke the <code>merge</code> method. + * * @param mergeContext a context that provides access to the resources * involved in the merge. The context must not be * <code>null</code>. * @param monitor a progress monitor - * @return a status indicating any potential side effects of - * performing an auto-merge. - */ - public IStatus validateMerge(IMergeContext mergeContext, - IProgressMonitor monitor); + * @return a status indicating any potential side effects of + * performing an auto-merge. + */ + public IStatus validateMerge(IMergeContext mergeContext, + IProgressMonitor monitor); } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IStorageMerger.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IStorageMerger.java index 5fcbdd1c0..53d3327ab 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IStorageMerger.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/IStorageMerger.java @@ -33,46 +33,46 @@ import org.eclipse.core.runtime.IStatus; */ public interface IStorageMerger { - /** - * Indicates the successful completion of the merge operation (value <code>IStatus.OK</code>) - */ - public static final int OK= IStatus.OK; + /** + * Indicates the successful completion of the merge operation (value <code>IStatus.OK</code>) + */ + public static final int OK= IStatus.OK; - /** - * Indicates that a change conflict prevented the merge from successful completion (value <code>1</code>) - */ - public static final int CONFLICT= 1; + /** + * Indicates that a change conflict prevented the merge from successful completion (value <code>1</code>) + */ + public static final int CONFLICT= 1; - /** - * Status code describing an internal error (value <code>2</code>) - */ - public static final int INTERNAL_ERROR= 2; + /** + * Status code describing an internal error (value <code>2</code>) + */ + public static final int INTERNAL_ERROR= 2; - /** - * Indicates that at least one of the encodings associated with the input was unsupported (value <code>3</code>) - */ - public static final int UNSUPPORTED_ENCODING= 3; + /** + * Indicates that at least one of the encodings associated with the input was unsupported (value <code>3</code>) + */ + public static final int UNSUPPORTED_ENCODING= 3; - /** - * Performs a merge operation on the given storage instances and writes the merge result to the output stream. - * On success a status <code>IStatus.OK</code> is returned, on error a status <code>IStatus.ERROR</code>. - * If the merge operation cannot deal with conflicts, the code of the error status has the value <code>IStreamMerger.CONFLICT</code>. - * For text oriented mergers the encoding for the input and output is honored if they implement - * {@link IEncodedStorage}. - * It is the responsibility of callers to close the output stream. - * <p> - * The provided ancestor may be <code>null</code> if this merger - * returns <code>true</code> from {@link #canMergeWithoutAncestor()}. - * - * @param output the byte stream to which the merge result is written; the merger will not close the stream - * @param outputEncoding the encoding to use when writing to the output stream - * @param ancestor the storage from which the common ancestor is read - * @param target the storage containing the target of the merge - * @param other the storage containing the target of the merge - * @param monitor reports progress of the merge operation - * @return returns the completion status of the operation - * @throws CoreException if an error occurs - */ + /** + * Performs a merge operation on the given storage instances and writes the merge result to the output stream. + * On success a status <code>IStatus.OK</code> is returned, on error a status <code>IStatus.ERROR</code>. + * If the merge operation cannot deal with conflicts, the code of the error status has the value <code>IStreamMerger.CONFLICT</code>. + * For text oriented mergers the encoding for the input and output is honored if they implement + * {@link IEncodedStorage}. + * It is the responsibility of callers to close the output stream. + * <p> + * The provided ancestor may be <code>null</code> if this merger + * returns <code>true</code> from {@link #canMergeWithoutAncestor()}. + * + * @param output the byte stream to which the merge result is written; the merger will not close the stream + * @param outputEncoding the encoding to use when writing to the output stream + * @param ancestor the storage from which the common ancestor is read + * @param target the storage containing the target of the merge + * @param other the storage containing the target of the merge + * @param monitor reports progress of the merge operation + * @return returns the completion status of the operation + * @throws CoreException if an error occurs + */ IStatus merge(OutputStream output, String outputEncoding, IStorage ancestor, IStorage target, IStorage other, IProgressMonitor monitor) throws CoreException; diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ResourceMappingMerger.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ResourceMappingMerger.java index 37ef3cbcd..b3c994661 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ResourceMappingMerger.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/ResourceMappingMerger.java @@ -61,10 +61,10 @@ public abstract class ResourceMappingMerger implements IResourceMappingMerger { * changes in the context for the model provider of this merger. * By default, return a rule that covers all the projects for the mappings * that belong to the model provider of this merger. - * @param context the context that contains the changes to be merged - * @return the scheduling rule required by this merger to merge all - * the changes in the given context belonging to the merger's - * model provider. + * @param context the context that contains the changes to be merged + * @return the scheduling rule required by this merger to merge all + * the changes in the given context belonging to the merger's + * model provider. * @see org.eclipse.team.core.mapping.IResourceMappingMerger#getMergeRule(org.eclipse.team.core.mapping.IMergeContext) */ @Override diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java index f30286846..5a29fe4ea 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeContext.java @@ -79,11 +79,11 @@ public abstract class MergeContext extends SynchronizationContext implements IMe * @param type the type of synchronization (ONE_WAY or TWO_WAY) * @param deltaTree the sync info tree that contains all out-of-sync resources */ - protected MergeContext(ISynchronizationScopeManager manager, int type, IResourceDiffTree deltaTree) { - super(manager, type, deltaTree); - } + protected MergeContext(ISynchronizationScopeManager manager, int type, IResourceDiffTree deltaTree) { + super(manager, type, deltaTree); + } - @Override + @Override public void reject(final IDiff[] diffs, IProgressMonitor monitor) throws CoreException { run(monitor1 -> { for (int i = 0; i < diffs.length; i++) { @@ -91,9 +91,9 @@ public abstract class MergeContext extends SynchronizationContext implements IMe reject(node, monitor1); } }, getMergeRule(diffs), IResource.NONE, monitor); - } + } - @Override + @Override public void markAsMerged(final IDiff[] nodes, final boolean inSyncHint, IProgressMonitor monitor) throws CoreException { run(monitor1 -> { for (int i = 0; i < nodes.length; i++) { @@ -101,9 +101,9 @@ public abstract class MergeContext extends SynchronizationContext implements IMe markAsMerged(node, inSyncHint, monitor1); } }, getMergeRule(nodes), IResource.NONE, monitor); - } + } - @Override + @Override public IStatus merge(final IDiff[] deltas, final boolean force, IProgressMonitor monitor) throws CoreException { final List<IFile> failedFiles = new ArrayList<>(); run(monitor1 -> { @@ -129,7 +129,7 @@ public abstract class MergeContext extends SynchronizationContext implements IMe } else { return new MergeStatus(TeamPlugin.ID, Messages.MergeContext_0, failedFiles.toArray(new IFile[failedFiles.size()])); } - } + } @Override public IStatus merge(IDiff diff, boolean ignoreLocalChanges, IProgressMonitor monitor) throws CoreException { @@ -156,30 +156,30 @@ public abstract class MergeContext extends SynchronizationContext implements IMe } return Status.OK_STATUS; } - if (diff instanceof IThreeWayDiff && !ignoreLocalChanges && getMergeType() == THREE_WAY) { + if (diff instanceof IThreeWayDiff && !ignoreLocalChanges && getMergeType() == THREE_WAY) { IThreeWayDiff twDelta = (IThreeWayDiff) diff; - int direction = twDelta.getDirection(); - if (direction == IThreeWayDiff.OUTGOING) { - // There's nothing to do so return OK - return Status.OK_STATUS; - } - if (direction == IThreeWayDiff.INCOMING) { - // Just copy the stream since there are no conflicts - performReplace(diff, monitor); - return Status.OK_STATUS; - } + int direction = twDelta.getDirection(); + if (direction == IThreeWayDiff.OUTGOING) { + // There's nothing to do so return OK + return Status.OK_STATUS; + } + if (direction == IThreeWayDiff.INCOMING) { + // Just copy the stream since there are no conflicts + performReplace(diff, monitor); + return Status.OK_STATUS; + } // direction == SyncInfo.CONFLICTING - int type = twDelta.getKind(); - if (type == IDiff.REMOVE) { - makeInSync(diff, monitor); - return Status.OK_STATUS; - } + int type = twDelta.getKind(); + if (type == IDiff.REMOVE) { + makeInSync(diff, monitor); + return Status.OK_STATUS; + } // type == SyncInfo.CHANGE IResourceDiff remoteChange = (IResourceDiff)twDelta.getRemoteChange(); IFileRevision remote = null; - if (remoteChange != null) { - remote = remoteChange.getAfterState(); - } + if (remoteChange != null) { + remote = remoteChange.getAfterState(); + } if (remote == null || !getLocalFile(diff).exists()) { // Nothing we can do so return a conflict status // TODO: Should we handle the case where the local and remote have the same contents for a conflicting addition? @@ -187,11 +187,11 @@ public abstract class MergeContext extends SynchronizationContext implements IMe } // We have a conflict, a local, base and remote so we can do // a three-way merge - return performThreeWayMerge(twDelta, monitor); - } else { - performReplace(diff, monitor); - return Status.OK_STATUS; - } + return performThreeWayMerge(twDelta, monitor); + } else { + performReplace(diff, monitor); + return Status.OK_STATUS; + } } @@ -236,70 +236,70 @@ public abstract class MergeContext extends SynchronizationContext implements IMe status = new MergeStatus(status.getPlugin(), status.getMessage(), new IFile[]{file}); } result[0] = status; - } finally { - disposeTempOutputStream(file, os); - } - monitor1.done(); + } finally { + disposeTempOutputStream(file, os); + } + monitor1.done(); }, getMergeRule(diff), IWorkspace.AVOID_UPDATE, monitor); return result[0]; } - private void disposeTempOutputStream(IFile file, OutputStream output) { - if (output instanceof ByteArrayOutputStream) - return; - // We created a temporary file so we need to clean it up - try { - // First make sure the output stream is closed - // so that file deletion will not fail because of that. - if (output != null) - output.close(); - } catch (IOException e) { - // Ignore - } - File tmpFile = getTempFile(file); - if (tmpFile.exists()) - tmpFile.delete(); - } + private void disposeTempOutputStream(IFile file, OutputStream output) { + if (output instanceof ByteArrayOutputStream) + return; + // We created a temporary file so we need to clean it up + try { + // First make sure the output stream is closed + // so that file deletion will not fail because of that. + if (output != null) + output.close(); + } catch (IOException e) { + // Ignore + } + File tmpFile = getTempFile(file); + if (tmpFile.exists()) + tmpFile.delete(); + } - private OutputStream getTempOutputStream(IFile file) throws CoreException { - File tmpFile = getTempFile(file); - if (tmpFile.exists()) - tmpFile.delete(); - File parent = tmpFile.getParentFile(); - if (!parent.exists()) - parent.mkdirs(); - try { - return new BufferedOutputStream(new FileOutputStream(tmpFile)); - } catch (FileNotFoundException e) { - TeamPlugin.log(IStatus.ERROR, NLS.bind("Could not open temporary file {0} for writing: {1}", new String[] { tmpFile.getAbsolutePath(), e.getMessage() }), e); //$NON-NLS-1$ - return new ByteArrayOutputStream(); - } - } + private OutputStream getTempOutputStream(IFile file) throws CoreException { + File tmpFile = getTempFile(file); + if (tmpFile.exists()) + tmpFile.delete(); + File parent = tmpFile.getParentFile(); + if (!parent.exists()) + parent.mkdirs(); + try { + return new BufferedOutputStream(new FileOutputStream(tmpFile)); + } catch (FileNotFoundException e) { + TeamPlugin.log(IStatus.ERROR, NLS.bind("Could not open temporary file {0} for writing: {1}", new String[] { tmpFile.getAbsolutePath(), e.getMessage() }), e); //$NON-NLS-1$ + return new ByteArrayOutputStream(); + } + } - private InputStream getTempInputStream(IFile file, OutputStream output) throws CoreException { - if (output instanceof ByteArrayOutputStream) { - ByteArrayOutputStream baos = (ByteArrayOutputStream) output; - return new ByteArrayInputStream(baos.toByteArray()); - } - // We created a temporary file so we need to open an input stream on it - try { - // First make sure the output stream is closed - if (output != null) - output.close(); - } catch (IOException e) { - // Ignore - } - File tmpFile = getTempFile(file); - try { - return new BufferedInputStream(new FileInputStream(tmpFile)); - } catch (FileNotFoundException e) { - throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IMergeStatus.INTERNAL_ERROR, NLS.bind(Messages.MergeContext_4, new String[] { tmpFile.getAbsolutePath(), e.getMessage() }), e)); - } - } + private InputStream getTempInputStream(IFile file, OutputStream output) throws CoreException { + if (output instanceof ByteArrayOutputStream) { + ByteArrayOutputStream baos = (ByteArrayOutputStream) output; + return new ByteArrayInputStream(baos.toByteArray()); + } + // We created a temporary file so we need to open an input stream on it + try { + // First make sure the output stream is closed + if (output != null) + output.close(); + } catch (IOException e) { + // Ignore + } + File tmpFile = getTempFile(file); + try { + return new BufferedInputStream(new FileInputStream(tmpFile)); + } catch (FileNotFoundException e) { + throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IMergeStatus.INTERNAL_ERROR, NLS.bind(Messages.MergeContext_4, new String[] { tmpFile.getAbsolutePath(), e.getMessage() }), e)); + } + } - private File getTempFile(IFile file) { - return TeamPlugin.getPlugin().getStateLocation().append(".tmp").append(file.getName() + ".tmp").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ - } + private File getTempFile(IFile file) { + return TeamPlugin.getPlugin().getStateLocation().append(".tmp").append(file.getName() + ".tmp").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ + } private IFile getLocalFile(IDiff delta) { return ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getPath()); @@ -321,31 +321,31 @@ public abstract class MergeContext extends SynchronizationContext implements IMe * a progress monitor * @throws CoreException */ - protected void performReplace(final IDiff diff, IProgressMonitor monitor) throws CoreException { - IResourceDiff d; - IFile file = getLocalFile(diff); - IFileRevision remote = null; - if (diff instanceof IResourceDiff) { - d = (IResourceDiff) diff; - remote = d.getAfterState(); - } else { - d = (IResourceDiff)((IThreeWayDiff)diff).getRemoteChange(); - if (d != null) - remote = d.getAfterState(); - } - if (d == null) { - d = (IResourceDiff)((IThreeWayDiff)diff).getLocalChange(); - if (d != null) - remote = d.getBeforeState(); - } + protected void performReplace(final IDiff diff, IProgressMonitor monitor) throws CoreException { + IResourceDiff d; + IFile file = getLocalFile(diff); + IFileRevision remote = null; + if (diff instanceof IResourceDiff) { + d = (IResourceDiff) diff; + remote = d.getAfterState(); + } else { + d = (IResourceDiff)((IThreeWayDiff)diff).getRemoteChange(); + if (d != null) + remote = d.getAfterState(); + } + if (d == null) { + d = (IResourceDiff)((IThreeWayDiff)diff).getLocalChange(); + if (d != null) + remote = d.getBeforeState(); + } - // Only perform the replace if a local or remote change was found - if (d != null) { - performReplace(diff, file, remote, monitor); - } + // Only perform the replace if a local or remote change was found + if (d != null) { + performReplace(diff, file, remote, monitor); + } } - /** + /** * Method that is invoked from * {@link #performReplace(IDiff, IProgressMonitor)} after the local has been * changed to match the remote. Subclasses may override @@ -361,7 +361,7 @@ public abstract class MergeContext extends SynchronizationContext implements IMe * a progress monitor * @throws CoreException */ - protected abstract void makeInSync(IDiff diff, IProgressMonitor monitor) throws CoreException; + protected abstract void makeInSync(IDiff diff, IProgressMonitor monitor) throws CoreException; private void performReplace(final IDiff diff, final IFile file, final IFileRevision remote, IProgressMonitor monitor) throws CoreException { run(monitor1 -> { diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeStatus.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeStatus.java index cf272544a..675fbd21c 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeStatus.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/MergeStatus.java @@ -34,40 +34,40 @@ import org.eclipse.team.core.mapping.IMergeStatus; */ public class MergeStatus extends Status implements IMergeStatus { - private ResourceMapping[] conflictingMappings; + private ResourceMapping[] conflictingMappings; private IFile[] conflictingFiles; - /** - * Create a merge status for reporting that some of the resource mappings - * for which a merge was attempted were not auto-mergable. - * @param pluginId the plugin id - * @param message the message for the status - * @param conflictingMappings the mappings which were not auto-mergable - */ - public MergeStatus(String pluginId, String message, ResourceMapping[] conflictingMappings) { - super(IStatus.ERROR, pluginId, CONFLICTS, message, null); - this.conflictingMappings = conflictingMappings; - } + /** + * Create a merge status for reporting that some of the resource mappings + * for which a merge was attempted were not auto-mergable. + * @param pluginId the plugin id + * @param message the message for the status + * @param conflictingMappings the mappings which were not auto-mergable + */ + public MergeStatus(String pluginId, String message, ResourceMapping[] conflictingMappings) { + super(IStatus.ERROR, pluginId, CONFLICTS, message, null); + this.conflictingMappings = conflictingMappings; + } - /** - * Create a merge status for reporting that some of the files - * for which a merge was attempted were not auto-mergable. - * @param pluginId the plugin id - * @param message the message for the status - * @param files the files which were not auto-mergable - */ - public MergeStatus(String pluginId, String message, IFile[] files) { - super(IStatus.ERROR, pluginId, CONFLICTS, message, null); - this.conflictingFiles = files; + /** + * Create a merge status for reporting that some of the files + * for which a merge was attempted were not auto-mergable. + * @param pluginId the plugin id + * @param message the message for the status + * @param files the files which were not auto-mergable + */ + public MergeStatus(String pluginId, String message, IFile[] files) { + super(IStatus.ERROR, pluginId, CONFLICTS, message, null); + this.conflictingFiles = files; } - @Override + @Override public ResourceMapping[] getConflictingMappings() { - return conflictingMappings; - } + return conflictingMappings; + } - @Override + @Override public IFile[] getConflictingFiles() { - return conflictingFiles; - } + return conflictingFiles; + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/SynchronizationContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/SynchronizationContext.java index 75708813d..89349c548 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/SynchronizationContext.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/SynchronizationContext.java @@ -36,22 +36,22 @@ import org.eclipse.team.internal.core.Policy; */ public abstract class SynchronizationContext extends PlatformObject implements ISynchronizationContext { - private final int type; - private final IResourceDiffTree diffTree; - private Cache cache; + private final int type; + private final IResourceDiffTree diffTree; + private Cache cache; private final ISynchronizationScopeManager manager; - /** - * Create a synchronization context. - * @param manager the manager that defines the scope of the synchronization - * @param type the type of synchronization (ONE_WAY or TWO_WAY) - * @param diffTree the sync info tree that contains all out-of-sync resources - */ - protected SynchronizationContext(ISynchronizationScopeManager manager, int type, IResourceDiffTree diffTree) { - this.manager = manager; + /** + * Create a synchronization context. + * @param manager the manager that defines the scope of the synchronization + * @param type the type of synchronization (ONE_WAY or TWO_WAY) + * @param diffTree the sync info tree that contains all out-of-sync resources + */ + protected SynchronizationContext(ISynchronizationScopeManager manager, int type, IResourceDiffTree diffTree) { + this.manager = manager; this.type = type; this.diffTree = diffTree; - } + } @Override public ISynchronizationScope getScope() { diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberResourceMappingContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberResourceMappingContext.java index 3df0805ad..b1f3d8817 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberResourceMappingContext.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberResourceMappingContext.java @@ -45,126 +45,126 @@ import org.eclipse.team.internal.core.TeamPlugin; */ public class SubscriberResourceMappingContext extends RemoteResourceMappingContext { - private final Subscriber subscriber; + private final Subscriber subscriber; - // Lists used to keep track of resources that have been refreshed - private Set<IResource> shallowRefresh = new HashSet<>(); - private Set<IResource> deepRefresh = new HashSet<>(); - private boolean autoRefresh; + // Lists used to keep track of resources that have been refreshed + private Set<IResource> shallowRefresh = new HashSet<>(); + private Set<IResource> deepRefresh = new HashSet<>(); + private boolean autoRefresh; - /** - * Return a resource mapping context suitable for comparison operations. - * Comparisons require that any out-of-sync resources have contents - * that differ. - * @param subscriber the subscriber - * @return a resource mapping context suitable for compare operations - */ - public static RemoteResourceMappingContext createContext(Subscriber subscriber) { - return new SubscriberResourceMappingContext(subscriber, true); - } + /** + * Return a resource mapping context suitable for comparison operations. + * Comparisons require that any out-of-sync resources have contents + * that differ. + * @param subscriber the subscriber + * @return a resource mapping context suitable for compare operations + */ + public static RemoteResourceMappingContext createContext(Subscriber subscriber) { + return new SubscriberResourceMappingContext(subscriber, true); + } - /** - * Create a resource mapping context for the given subscriber - * @param subscriber the subscriber - * from the local contents - * @param autoRefresh whether the context should auto-refresh when queried - */ - public SubscriberResourceMappingContext(Subscriber subscriber, boolean autoRefresh) { - this.subscriber = subscriber; - this.autoRefresh = autoRefresh; - } + /** + * Create a resource mapping context for the given subscriber + * @param subscriber the subscriber + * from the local contents + * @param autoRefresh whether the context should auto-refresh when queried + */ + public SubscriberResourceMappingContext(Subscriber subscriber, boolean autoRefresh) { + this.subscriber = subscriber; + this.autoRefresh = autoRefresh; + } - @Override + @Override public final boolean hasRemoteChange(IResource resource, IProgressMonitor monitor) throws CoreException { - try { + try { monitor.beginTask(null, 100); ensureRefreshed(resource, IResource.DEPTH_ONE, NONE, monitor); SyncInfo syncInfo = subscriber.getSyncInfo(resource); validateRemote(resource, syncInfo); - if (syncInfo == null) return false; - int direction = SyncInfo.getDirection(syncInfo.getKind()); + if (syncInfo == null) return false; + int direction = SyncInfo.getDirection(syncInfo.getKind()); return direction == SyncInfo.INCOMING || direction == SyncInfo.CONFLICTING; } finally { monitor.done(); } - } + } - @Override + @Override public boolean hasLocalChange(IResource resource, IProgressMonitor monitor) throws CoreException { - SyncInfo syncInfo = subscriber.getSyncInfo(resource); - if (syncInfo == null) return false; - int direction = SyncInfo.getDirection(syncInfo.getKind()); + SyncInfo syncInfo = subscriber.getSyncInfo(resource); + if (syncInfo == null) return false; + int direction = SyncInfo.getDirection(syncInfo.getKind()); return direction == SyncInfo.OUTGOING || direction == SyncInfo.CONFLICTING; - } + } - @Override + @Override public final IStorage fetchRemoteContents(IFile file, IProgressMonitor monitor) throws CoreException { - try { + try { monitor.beginTask(null, 100); - ensureRefreshed(file, IResource.DEPTH_ZERO, FILE_CONTENTS_REQUIRED, Policy.subMonitorFor(monitor, 10)); - SyncInfo syncInfo = subscriber.getSyncInfo(file); - IResourceVariant remote = validateRemote(file, syncInfo); - if (remote == null) { - return null; - } - return remote.getStorage(Policy.subMonitorFor(monitor, 90)); + ensureRefreshed(file, IResource.DEPTH_ZERO, FILE_CONTENTS_REQUIRED, Policy.subMonitorFor(monitor, 10)); + SyncInfo syncInfo = subscriber.getSyncInfo(file); + IResourceVariant remote = validateRemote(file, syncInfo); + if (remote == null) { + return null; + } + return remote.getStorage(Policy.subMonitorFor(monitor, 90)); } finally { monitor.done(); } - } + } - @Override + @Override public final IStorage fetchBaseContents(IFile file, IProgressMonitor monitor) throws CoreException { - try { + try { monitor.beginTask(null, 100); - ensureRefreshed(file, IResource.DEPTH_ZERO, FILE_CONTENTS_REQUIRED, Policy.subMonitorFor(monitor, 10)); - SyncInfo syncInfo = subscriber.getSyncInfo(file); - IResourceVariant base = validateBase(file, syncInfo); - if (base == null) { - return null; - } - return base.getStorage(Policy.subMonitorFor(monitor, 90)); + ensureRefreshed(file, IResource.DEPTH_ZERO, FILE_CONTENTS_REQUIRED, Policy.subMonitorFor(monitor, 10)); + SyncInfo syncInfo = subscriber.getSyncInfo(file); + IResourceVariant base = validateBase(file, syncInfo); + if (base == null) { + return null; + } + return base.getStorage(Policy.subMonitorFor(monitor, 90)); } finally { monitor.done(); } - } + } - @Override + @Override public final IResource[] fetchMembers(IContainer container, IProgressMonitor monitor) throws CoreException { - try { + try { monitor.beginTask(null, 100); - ensureRefreshed(container, IResource.DEPTH_ONE, NONE, Policy.subMonitorFor(monitor, 100)); - SyncInfo syncInfo = subscriber.getSyncInfo(container); - if (validateRemote(container, syncInfo) == null) { - // There is no remote so return an empty array - return new IResource[0]; - } - return subscriber.members(container); + ensureRefreshed(container, IResource.DEPTH_ONE, NONE, Policy.subMonitorFor(monitor, 100)); + SyncInfo syncInfo = subscriber.getSyncInfo(container); + if (validateRemote(container, syncInfo) == null) { + // There is no remote so return an empty array + return new IResource[0]; + } + return subscriber.members(container); } finally { monitor.done(); } - } + } - @Override + @Override public final void refresh(ResourceTraversal[] traversals, int flags, IProgressMonitor monitor) throws CoreException { - subscriber.refresh(traversals, monitor); - for (int i = 0; i < traversals.length; i++) { + subscriber.refresh(traversals, monitor); + for (int i = 0; i < traversals.length; i++) { ResourceTraversal traversal = traversals[i]; refreshed(traversal.getResources(), traversal.getDepth()); } - } + } - /** - * Refresh the subscriber and cache the fact that the resources were refreshed by - * calling the <code>refreshed</code> method. The default implementation only refreshes - * the state and does not fetch contents in the <code>FILE_CONTENTS_REQUIRED</code> - * flag is passed. It is up to subclass to handle this. - * @param resources the resources to be refreshed - * @param depth the depth of the refresh - * @param flags the flags that indicate extra state that should be fetched - * @param monitor a progress monitor - * @throws TeamException - */ + /** + * Refresh the subscriber and cache the fact that the resources were refreshed by + * calling the <code>refreshed</code> method. The default implementation only refreshes + * the state and does not fetch contents in the <code>FILE_CONTENTS_REQUIRED</code> + * flag is passed. It is up to subclass to handle this. + * @param resources the resources to be refreshed + * @param depth the depth of the refresh + * @param flags the flags that indicate extra state that should be fetched + * @param monitor a progress monitor + * @throws TeamException + */ protected void refresh(IResource[] resources, int depth, int flags, IProgressMonitor monitor) throws TeamException { subscriber.refresh(resources, depth, monitor); refreshed(resources, depth); @@ -189,32 +189,32 @@ public class SubscriberResourceMappingContext extends RemoteResourceMappingConte } } - /* - * Ensure that the given resource has been refreshed to the specified depth - * since the context has been created. - */ - private void ensureRefreshed(IResource resource, int depth, int flags, IProgressMonitor monitor) throws TeamException { - if (autoRefresh) { - if (depth == IResource.DEPTH_INFINITE) { - // If the resource or a parent was refreshed deeply, no need to do it again - if (wasRefreshedDeeply(resource)) - return; - // if the resource is a file, a shallow refresh is enough - if (resource.getType() == IResource.FILE && wasRefreshedShallow(resource)) - return; - } else { - if (wasRefreshedShallow(resource)) - return; - } - refresh(new IResource[] { resource }, depth, flags, monitor); - } + /* + * Ensure that the given resource has been refreshed to the specified depth + * since the context has been created. + */ + private void ensureRefreshed(IResource resource, int depth, int flags, IProgressMonitor monitor) throws TeamException { + if (autoRefresh) { + if (depth == IResource.DEPTH_INFINITE) { + // If the resource or a parent was refreshed deeply, no need to do it again + if (wasRefreshedDeeply(resource)) + return; + // if the resource is a file, a shallow refresh is enough + if (resource.getType() == IResource.FILE && wasRefreshedShallow(resource)) + return; + } else { + if (wasRefreshedShallow(resource)) + return; + } + refresh(new IResource[] { resource }, depth, flags, monitor); + } } - /* - * Look for a shallow refresh of the resource. If not there, - * look fir a deep refresh of a parent or a shallow refresh of the - * direct parent if the resource is a file. - */ + /* + * Look for a shallow refresh of the resource. If not there, + * look fir a deep refresh of a parent or a shallow refresh of the + * direct parent if the resource is a file. + */ private boolean wasRefreshedShallow(IResource resource) { if (shallowRefresh.contains(resource)) return true; @@ -240,45 +240,45 @@ public class SubscriberResourceMappingContext extends RemoteResourceMappingConte * Validate that the remote resource is of the proper type and return the * remote resource if it is OK. A return of null indicates that there is no remote. */ - private IResourceVariant validateRemote(IResource resource, SyncInfo syncInfo) throws CoreException { - if (syncInfo == null) return null; - IResourceVariant remote = syncInfo.getRemote(); - if (remote == null) return null; - return validateRemote(resource, remote); - } + private IResourceVariant validateRemote(IResource resource, SyncInfo syncInfo) throws CoreException { + if (syncInfo == null) return null; + IResourceVariant remote = syncInfo.getRemote(); + if (remote == null) return null; + return validateRemote(resource, remote); + } private IResourceVariant validateRemote(IResource resource, IResourceVariant remote) throws CoreException { boolean containerExpected = resource.getType() != IResource.FILE; - if (remote.isContainer() && !containerExpected) { - throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_0 + resource.getFullPath().toString(), null)); - } else if (!remote.isContainer() && containerExpected) { - throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_1 + resource.getFullPath().toString(), null)); - } - return remote; + if (remote.isContainer() && !containerExpected) { + throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_0 + resource.getFullPath().toString(), null)); + } else if (!remote.isContainer() && containerExpected) { + throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.RESOURCE_WRONG_TYPE, Messages.SubscriberResourceMappingContext_1 + resource.getFullPath().toString(), null)); + } + return remote; } /* * Validate that the base resource is of the proper type and return the * base resource if it is OK. A return of null indicates that there is no base. */ - private IResourceVariant validateBase(IResource resource, SyncInfo syncInfo) throws CoreException { - if (syncInfo == null) return null; - IResourceVariant base = syncInfo.getBase(); - if (base == null) return null; - return validateRemote(resource, base); - } + private IResourceVariant validateBase(IResource resource, SyncInfo syncInfo) throws CoreException { + if (syncInfo == null) return null; + IResourceVariant base = syncInfo.getBase(); + if (base == null) return null; + return validateRemote(resource, base); + } - /** - * Set whether the context should refresh the state of resources - * when their state is requested. The context keeps track of what - * resources were refreshed and only auto-refreshes a resource - * once. - * @param autoRefresh whether the context should refresh the state of resources - * when their state is requested - */ - public void setAutoRefresh(boolean autoRefresh) { - this.autoRefresh = autoRefresh; - } + /** + * Set whether the context should refresh the state of resources + * when their state is requested. The context keeps track of what + * resources were refreshed and only auto-refreshes a resource + * once. + * @param autoRefresh whether the context should refresh the state of resources + * when their state is requested + */ + public void setAutoRefresh(boolean autoRefresh) { + this.autoRefresh = autoRefresh; + } @Override public boolean isThreeWay() { diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfo.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfo.java index 91103b8c6..5e5ae3c40 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfo.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfo.java @@ -148,20 +148,20 @@ public class SyncInfo implements IAdaptable { /*==================================================================== * Members: *====================================================================*/ - private IResource local; - private IResourceVariant base; - private IResourceVariant remote; - private IResourceVariantComparator comparator; - - private int syncKind; - - /** - * Construct a sync info object. - * @param local the local resource. Must be non-null but may not exist. - * @param base the base resource variant or <code>null</code> - * @param remote the remote resource variant or <code>null</code> - * @param comparator the comparator used to determine if resources differ - */ + private IResource local; + private IResourceVariant base; + private IResourceVariant remote; + private IResourceVariantComparator comparator; + + private int syncKind; + + /** + * Construct a sync info object. + * @param local the local resource. Must be non-null but may not exist. + * @param base the base resource variant or <code>null</code> + * @param remote the remote resource variant or <code>null</code> + * @param comparator the comparator used to determine if resources differ + */ public SyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator) { Assert.isNotNull(local); Assert.isNotNull(comparator); diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfoSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfoSet.java index cd6b35f63..beb723704 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfoSet.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/synchronize/SyncInfoSet.java @@ -667,14 +667,14 @@ public class SyncInfoSet { return errors.values().toArray(new ITeamStatus[errors.size()]); } - /** - * Return an iterator over all <code>SyncInfo</code> - * contained in this set. - * @return an iterator over all <code>SyncInfo</code> - * contained in this set. - * @since 3.1 - */ - public Iterator iterator() { - return resources.values().iterator(); - } + /** + * Return an iterator over all <code>SyncInfo</code> + * contained in this set. + * @return an iterator over all <code>SyncInfo</code> + * contained in this set. + * @since 3.1 + */ + public Iterator iterator() { + return resources.values().iterator(); + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/BackgroundEventHandler.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/BackgroundEventHandler.java index f1f2fbc29..0b6b9a1c8 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/BackgroundEventHandler.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/BackgroundEventHandler.java @@ -101,7 +101,7 @@ public abstract class BackgroundEventHandler { * General event class. The type is specific to subclasses. */ public static class Event { - private int type; + private int type; public Event(int type) { this.type = type; } @@ -116,7 +116,7 @@ public abstract class BackgroundEventHandler { return buffer.toString(); } public IResource getResource() { - return null; + return null; } protected String getTypeString() { return String.valueOf(type); @@ -130,7 +130,7 @@ public abstract class BackgroundEventHandler { private IResource resource; private int depth; public ResourceEvent(IResource resource, int type, int depth) { - super(type); + super(type); this.resource = resource; this.depth = depth; } @@ -249,14 +249,14 @@ public abstract class BackgroundEventHandler { /** * Return the family that the background job for this * event handler belongs to. - * @return the family that the background job for this + * @return the family that the background job for this * event handler belongs to - */ - protected Object getJobFamiliy() { - return null; - } + */ + protected Object getJobFamiliy() { + return null; + } - /** + /** * This method is invoked when the processing job completes. The * default behavior of the handler is to restart the job if the queue * is no longer empty and to clear the queue if the handler was shut down. @@ -467,28 +467,28 @@ public abstract class BackgroundEventHandler { return WAIT_DELAY; } - /** + /** * Return the value that is used to determine how often * the events are dispatched (i.e. how often the UI is * updated) for the first 3 cycles. The default value is 1.5 seconds. * After the first 3 cycles, a longer delay is used - * @return the dispatch delay used for the first 3 cycles. - */ - protected long getShortDispatchDelay() { - return DISPATCH_DELAY; - } + * @return the dispatch delay used for the first 3 cycles. + */ + protected long getShortDispatchDelay() { + return DISPATCH_DELAY; + } /** * Return the value that is used to determine how often * the events are dispatched (i.e. how often the UI is * updated) after the first 3 cycles. The default value is 10 seconds. - * @return the dispatch delay used after the first 3 cycles. - */ - protected long getLongDispatchDelay() { - return LONG_DISPATCH_DELAY; - } + * @return the dispatch delay used after the first 3 cycles. + */ + protected long getLongDispatchDelay() { + return LONG_DISPATCH_DELAY; + } - /** + /** * Handle the exception by recording it in the errors list. * @param e */ diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java index 37f0f525b..a01b75680 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java @@ -49,22 +49,22 @@ public class DefaultFileModificationValidator extends FileModificationValidator @Override public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { - IFile[] readOnlyFiles = getReadOnly(files); - if (readOnlyFiles.length == 0) - return Status.OK_STATUS; - synchronized (this) { - if (uiValidator == null) - uiValidator = loadUIValidator(); - } - if (uiValidator != null) { - return uiValidator.validateEdit(files, context); - } - // There was no plugged in validator so fail gracefully + IFile[] readOnlyFiles = getReadOnly(files); + if (readOnlyFiles.length == 0) + return Status.OK_STATUS; + synchronized (this) { + if (uiValidator == null) + uiValidator = loadUIValidator(); + } + if (uiValidator != null) { + return uiValidator.validateEdit(files, context); + } + // There was no plugged in validator so fail gracefully return getStatus(files); } - protected IStatus getStatus(IFile[] files) { - if (files.length == 1) { + protected IStatus getStatus(IFile[] files) { + if (files.length == 1) { return getDefaultStatus(files[0]); } @@ -83,51 +83,51 @@ public class DefaultFileModificationValidator extends FileModificationValidator ? Messages.ok : Messages.FileModificationValidator_someReadOnly, null); - } + } - private IFile[] getReadOnly(IFile[] files) { - List<IFile> result = new ArrayList<>(files.length); - for (int i = 0; i < files.length; i++) { - IFile file = files[i]; - if (file.isReadOnly()) { - result.add(file); - } - } - return result.toArray(new IFile[result.size()]); - } + private IFile[] getReadOnly(IFile[] files) { + List<IFile> result = new ArrayList<>(files.length); + for (int i = 0; i < files.length; i++) { + IFile file = files[i]; + if (file.isReadOnly()) { + result.add(file); + } + } + return result.toArray(new IFile[result.size()]); + } @Override public IStatus validateSave(IFile file) { - if (!file.isReadOnly()) - return Status.OK_STATUS; - synchronized (this) { - if (uiValidator == null) - uiValidator = loadUIValidator(); - } - if (uiValidator != null) { - return uiValidator.validateSave(file); - } + if (!file.isReadOnly()) + return Status.OK_STATUS; + synchronized (this) { + if (uiValidator == null) + uiValidator = loadUIValidator(); + } + if (uiValidator != null) { + return uiValidator.validateSave(file); + } return getDefaultStatus(file); } - private FileModificationValidator loadUIValidator() { - IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION); + private FileModificationValidator loadUIValidator() { + IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION); if (extension != null) { IExtension[] extensions = extension.getExtensions(); if (extensions.length > 0) { IConfigurationElement[] configElements = extensions[0].getConfigurationElements(); if (configElements.length > 0) { try { - Object o = configElements[0].createExecutableExtension("class"); //$NON-NLS-1$ - if (o instanceof FileModificationValidator) { - return (FileModificationValidator)o; - } - } catch (CoreException e) { - TeamPlugin.log(e); - } + Object o = configElements[0].createExecutableExtension("class"); //$NON-NLS-1$ + if (o instanceof FileModificationValidator) { + return (FileModificationValidator)o; + } + } catch (CoreException e) { + TeamPlugin.log(e); + } } } } return null; - } + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java index d2e177404..8c956d1a9 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java @@ -94,19 +94,19 @@ public class ExceptionCollector { * @param exception the exception to collect */ public void handleException(CoreException exception) { - // log the exception if we have a log - if(log != null) { - log.log(new Status(severity, pluginId, 0, message, exception)); - } - // Record each status individually to flatten the resulting multi-status - IStatus exceptionStatus = exception.getStatus(); - // Wrap the exception so the stack trace is not lost. - IStatus status = new Status(exceptionStatus.getSeverity(), exceptionStatus.getPlugin(), exceptionStatus.getCode(), exceptionStatus.getMessage(), exception); - recordStatus(status); + // log the exception if we have a log + if(log != null) { + log.log(new Status(severity, pluginId, 0, message, exception)); + } + // Record each status individually to flatten the resulting multi-status + IStatus exceptionStatus = exception.getStatus(); + // Wrap the exception so the stack trace is not lost. + IStatus status = new Status(exceptionStatus.getSeverity(), exceptionStatus.getPlugin(), exceptionStatus.getCode(), exceptionStatus.getMessage(), exception); + recordStatus(status); IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; i++) { IStatus status2 = children[i]; - recordStatus(status2); + recordStatus(status2); } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileContentManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileContentManager.java index 2ef473292..4c7dd374f 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileContentManager.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileContentManager.java @@ -40,236 +40,236 @@ import org.eclipse.team.core.Team; */ public class FileContentManager implements IFileContentManager { - private static final String PREF_TEAM_EXTENSION_TYPES= "file_types"; //$NON-NLS-1$ - private static final String PREF_TEAM_FILENAME_TYPES= "cvs_mode_for_file_without_extensions"; //$NON-NLS-1$ + private static final String PREF_TEAM_EXTENSION_TYPES= "file_types"; //$NON-NLS-1$ + private static final String PREF_TEAM_FILENAME_TYPES= "cvs_mode_for_file_without_extensions"; //$NON-NLS-1$ - private static class StringMapping implements IStringMapping { + private static class StringMapping implements IStringMapping { - private final String fString; - private final int fType; + private final String fString; + private final int fType; - public StringMapping(String string, int type) { - fString= string; - fType= type; - } + public StringMapping(String string, int type) { + fString= string; + fType= type; + } - @Override + @Override public String getString() { - return fString; - } + return fString; + } - @Override + @Override public int getType() { - return fType; - } - } + return fType; + } + } - private static class UserExtensionMappings extends UserStringMappings { + private static class UserExtensionMappings extends UserStringMappings { - public UserExtensionMappings(String key) { - super(key); - } + public UserExtensionMappings(String key) { + super(key); + } - @Override + @Override protected Map<String, Integer> loadMappingsFromPreferences() { - final Map<String, Integer> result= super.loadMappingsFromPreferences(); - if (loadMappingsFromOldWorkspace(result)) { - TeamPlugin.getPlugin().savePluginPreferences(); - } - return result; - } - - /** - * If the workspace is an old 2.0 one, read the old file and delete it. - * - * @param A map where the new mappings should be added. - * - * @return true if the workspace was a 2.0 one and the old mappings have - * been added to the map, false otherwise. - * - */ - private boolean loadMappingsFromOldWorkspace(Map<String, Integer> map) { - // File name of the persisted file type information - String STATE_FILE = ".fileTypes"; //$NON-NLS-1$ - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(STATE_FILE); - File f = pluginStateLocation.toFile(); - - if (!f.exists()) - return false; - - try { - DataInputStream input = new DataInputStream(new FileInputStream(f)); - try { - map.putAll(readOldFormatExtensionMappings(input)); - } finally { - input.close(); - f.delete(); - } - } catch (IOException ex) { - TeamPlugin.log(IStatus.ERROR, ex.getMessage(), ex); - return false; - } - return true; - } - - /** - * Read the saved file type state from the given input stream. - * - * @param input the input stream to read the saved state from - * @throws IOException if an I/O problem occurs - */ - private Map<String, Integer> readOldFormatExtensionMappings(DataInputStream input) throws IOException { - final Map<String, Integer> result= new TreeMap<>(); - int numberOfMappings = 0; - try { - numberOfMappings = input.readInt(); - } catch (EOFException e) { - // Ignore the exception, it will occur if there are no - // patterns stored in the state file. - return Collections.emptyMap(); - } - for (int i = 0; i < numberOfMappings; i++) { - final String extension = input.readUTF(); - final int type = input.readInt(); - result.put(extension, Integer.valueOf(type)); - } - return result; - } - } - - private final UserStringMappings fUserExtensionMappings, fUserNameMappings; - private PluginStringMappings fPluginExtensionMappings;//, fPluginNameMappings; - private IContentType textContentType; - - public FileContentManager() { - fUserExtensionMappings= new UserExtensionMappings(PREF_TEAM_EXTENSION_TYPES); - fUserNameMappings= new UserStringMappings(PREF_TEAM_FILENAME_TYPES); - fPluginExtensionMappings= new PluginStringMappings(TeamPlugin.FILE_TYPES_EXTENSION, "extension"); //$NON-NLS-1$ - } - - @Override + final Map<String, Integer> result= super.loadMappingsFromPreferences(); + if (loadMappingsFromOldWorkspace(result)) { + TeamPlugin.getPlugin().savePluginPreferences(); + } + return result; + } + + /** + * If the workspace is an old 2.0 one, read the old file and delete it. + * + * @param A map where the new mappings should be added. + * + * @return true if the workspace was a 2.0 one and the old mappings have + * been added to the map, false otherwise. + * + */ + private boolean loadMappingsFromOldWorkspace(Map<String, Integer> map) { + // File name of the persisted file type information + String STATE_FILE = ".fileTypes"; //$NON-NLS-1$ + IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(STATE_FILE); + File f = pluginStateLocation.toFile(); + + if (!f.exists()) + return false; + + try { + DataInputStream input = new DataInputStream(new FileInputStream(f)); + try { + map.putAll(readOldFormatExtensionMappings(input)); + } finally { + input.close(); + f.delete(); + } + } catch (IOException ex) { + TeamPlugin.log(IStatus.ERROR, ex.getMessage(), ex); + return false; + } + return true; + } + + /** + * Read the saved file type state from the given input stream. + * + * @param input the input stream to read the saved state from + * @throws IOException if an I/O problem occurs + */ + private Map<String, Integer> readOldFormatExtensionMappings(DataInputStream input) throws IOException { + final Map<String, Integer> result= new TreeMap<>(); + int numberOfMappings = 0; + try { + numberOfMappings = input.readInt(); + } catch (EOFException e) { + // Ignore the exception, it will occur if there are no + // patterns stored in the state file. + return Collections.emptyMap(); + } + for (int i = 0; i < numberOfMappings; i++) { + final String extension = input.readUTF(); + final int type = input.readInt(); + result.put(extension, Integer.valueOf(type)); + } + return result; + } + } + + private final UserStringMappings fUserExtensionMappings, fUserNameMappings; + private PluginStringMappings fPluginExtensionMappings;//, fPluginNameMappings; + private IContentType textContentType; + + public FileContentManager() { + fUserExtensionMappings= new UserExtensionMappings(PREF_TEAM_EXTENSION_TYPES); + fUserNameMappings= new UserStringMappings(PREF_TEAM_FILENAME_TYPES); + fPluginExtensionMappings= new PluginStringMappings(TeamPlugin.FILE_TYPES_EXTENSION, "extension"); //$NON-NLS-1$ + } + + @Override public int getTypeForName(String filename) { - final int userType= fUserNameMappings.getType(filename); + final int userType= fUserNameMappings.getType(filename); // final int pluginType= fPluginNameMappings.getType(filename); // return userType != Team.UNKNOWN ? userType : pluginType; - return userType; - } + return userType; + } - @Override + @Override public int getTypeForExtension(String extension) { - final int userType= fUserExtensionMappings.getType(extension); - final int pluginType= fPluginExtensionMappings.getType(extension); - return userType != Team.UNKNOWN ? userType : pluginType; - } + final int userType= fUserExtensionMappings.getType(extension); + final int pluginType= fPluginExtensionMappings.getType(extension); + return userType != Team.UNKNOWN ? userType : pluginType; + } - @Override + @Override public void addNameMappings(String[] names, int [] types) { - fUserNameMappings.addStringMappings(names, types); - } + fUserNameMappings.addStringMappings(names, types); + } - @Override + @Override public void addExtensionMappings(String[] extensions, int [] types) { - fUserExtensionMappings.addStringMappings(extensions, types); - } + fUserExtensionMappings.addStringMappings(extensions, types); + } - @Override + @Override public void setNameMappings(String[] names, int [] types) { - fUserNameMappings.setStringMappings(names, types); - } + fUserNameMappings.setStringMappings(names, types); + } - @Override + @Override public void setExtensionMappings(String[] extensions, int [] types) { - fUserExtensionMappings.setStringMappings(extensions, types); - } + fUserExtensionMappings.setStringMappings(extensions, types); + } - @Override + @Override public IStringMapping[] getNameMappings() { - return getMappings(fUserNameMappings, null);//fPluginNameMappings); - } + return getMappings(fUserNameMappings, null);//fPluginNameMappings); + } - @Override + @Override public IStringMapping[] getExtensionMappings() { - return getMappings(fUserExtensionMappings, fPluginExtensionMappings); - } + return getMappings(fUserExtensionMappings, fPluginExtensionMappings); + } - @Override + @Override public int getType(IStorage storage) { - int type; - - final String name= storage.getName(); - if (name != null && (type= getTypeForName(name)) != Team.UNKNOWN) - return type; - - final String extension= getFileExtension(name); - if (extension != null && (type= getTypeForExtension(extension)) != Team.UNKNOWN) - return type; - - IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(name); - if (contentType != null) { - IContentType textType = getTextContentType(); - if (contentType.isKindOf(textType)) { - return Team.TEXT; - } - } - - return Team.UNKNOWN; - } - - private IContentType getTextContentType() { - if (textContentType == null) - textContentType = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); - return textContentType; - } - - @Override + int type; + + final String name= storage.getName(); + if (name != null && (type= getTypeForName(name)) != Team.UNKNOWN) + return type; + + final String extension= getFileExtension(name); + if (extension != null && (type= getTypeForExtension(extension)) != Team.UNKNOWN) + return type; + + IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(name); + if (contentType != null) { + IContentType textType = getTextContentType(); + if (contentType.isKindOf(textType)) { + return Team.TEXT; + } + } + + return Team.UNKNOWN; + } + + private IContentType getTextContentType() { + if (textContentType == null) + textContentType = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); + return textContentType; + } + + @Override public IStringMapping[] getDefaultNameMappings() { - // TODO: There is currently no extension point for this - return new IStringMapping[0];//getStringMappings(fPluginNameMappings.referenceMap()); - } + // TODO: There is currently no extension point for this + return new IStringMapping[0];//getStringMappings(fPluginNameMappings.referenceMap()); + } - @Override + @Override public IStringMapping[] getDefaultExtensionMappings() { - return getStringMappings(fPluginExtensionMappings.referenceMap()); - } + return getStringMappings(fPluginExtensionMappings.referenceMap()); + } - @Override + @Override public boolean isKnownExtension(String extension) { - return fUserExtensionMappings.referenceMap().containsKey(extension) - || fPluginExtensionMappings.referenceMap().containsKey(extension); - } + return fUserExtensionMappings.referenceMap().containsKey(extension) + || fPluginExtensionMappings.referenceMap().containsKey(extension); + } - @Override + @Override public boolean isKnownFilename(String filename) { - return fUserNameMappings.referenceMap().containsKey(filename); + return fUserNameMappings.referenceMap().containsKey(filename); // || fPluginNameMappings.referenceMap().containsKey(filename); - } - - private static String getFileExtension(String name) { - if (name == null) - return null; - int index = name.lastIndexOf('.'); - if (index == -1) - return null; - if (index == (name.length() - 1)) - return ""; //$NON-NLS-1$ - return name.substring(index + 1); - } - - private static IStringMapping [] getStringMappings(Map map) { - final IStringMapping [] result= new IStringMapping [map.size()]; - int index= 0; - for (final Iterator iter = map.entrySet().iterator(); iter.hasNext();) { - final Map.Entry entry= (Map.Entry)iter.next(); - result[index++]= new StringMapping((String)entry.getKey(), ((Integer)entry.getValue()).intValue()); - } - return result; - } - - private IStringMapping [] getMappings(UserStringMappings userMappings, PluginStringMappings pluginMappings) { - final Map<String, Integer> mappings= new HashMap<>(); - if (pluginMappings != null) - mappings.putAll(pluginMappings.referenceMap()); - mappings.putAll(userMappings.referenceMap()); - return getStringMappings(mappings); - } + } + + private static String getFileExtension(String name) { + if (name == null) + return null; + int index = name.lastIndexOf('.'); + if (index == -1) + return null; + if (index == (name.length() - 1)) + return ""; //$NON-NLS-1$ + return name.substring(index + 1); + } + + private static IStringMapping [] getStringMappings(Map map) { + final IStringMapping [] result= new IStringMapping [map.size()]; + int index= 0; + for (final Iterator iter = map.entrySet().iterator(); iter.hasNext();) { + final Map.Entry entry= (Map.Entry)iter.next(); + result[index++]= new StringMapping((String)entry.getKey(), ((Integer)entry.getValue()).intValue()); + } + return result; + } + + private IStringMapping [] getMappings(UserStringMappings userMappings, PluginStringMappings pluginMappings) { + final Map<String, Integer> mappings= new HashMap<>(); + if (pluginMappings != null) + mappings.putAll(pluginMappings.referenceMap()); + mappings.putAll(userMappings.referenceMap()); + return getStringMappings(mappings); + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java index e00379ea3..c8dc7055e 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java @@ -102,9 +102,9 @@ public class FileModificationValidatorManager extends FileModificationValidator } private synchronized FileModificationValidator getDefaultValidator() { - if (defaultValidator == null) { - defaultValidator = new DefaultFileModificationValidator(); - } - return defaultValidator; + if (defaultValidator == null) { + defaultValidator = new DefaultFileModificationValidator(); + } + return defaultValidator; } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Messages.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Messages.java index fc01b4197..66017dc2a 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Messages.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Messages.java @@ -27,7 +27,7 @@ public class Messages extends NLS { public static String ok; public static String concatStrings; - public static String AbstractResourceVariantTree_0; + public static String AbstractResourceVariantTree_0; public static String Assert_assertionFailed; @@ -44,7 +44,7 @@ public class Messages extends NLS { public static String RepositoryProvider_linkedURIsNotSupported; public static String RepositoryProvider_couldNotClearAfterError; public static String RepositoryProvider_invalidClass; - public static String RepositoryProvider_toString; + public static String RepositoryProvider_toString; public static String SubscriberDiffTreeEventHandler_0; @@ -99,15 +99,15 @@ public class Messages extends NLS { public static String ProjectSetCapability_0; public static String ProjectSetCapability_1; - public static String SubscriberResourceMappingContext_0; - public static String SubscriberResourceMappingContext_1; + public static String SubscriberResourceMappingContext_0; + public static String SubscriberResourceMappingContext_1; public static String MergeContext_0; public static String MergeContext_1; public static String MergeContext_2; public static String MergeContext_3; public static String MergeContext_4; - public static String LocalFileRevision_currentVersion; + public static String LocalFileRevision_currentVersion; public static String LocalFileRevision_currentVersionTag; public static String LocalFileRevision_localRevisionTag; static { diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/PluginStringMappings.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/PluginStringMappings.java index 3197bdc6e..8193e6ae4 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/PluginStringMappings.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/PluginStringMappings.java @@ -29,63 +29,63 @@ import org.eclipse.team.core.Team; */ public class PluginStringMappings { - private final String fExtensionID; - private final String fAttributeName; - - private SortedMap<String, Integer> fMappings; - - public PluginStringMappings(String extensionID, String stringAttributeName) { - fExtensionID= extensionID; - fAttributeName= stringAttributeName; - } - - /** - * Load all the extension patterns contributed by plugins. - * @return a map with the patterns - */ - private SortedMap<String, Integer> loadPluginPatterns() { - - final SortedMap<String, Integer> result= new TreeMap<>(); - - final TeamPlugin plugin = TeamPlugin.getPlugin(); - if (plugin == null) - return result; - - final IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, fExtensionID);//TeamPlugin.FILE_TYPES_EXTENSION); - if (extension == null) - return result; - - final IExtension[] extensions = extension.getExtensions(); - - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); - - for (int j = 0; j < configElements.length; j++) { - - final String ext = configElements[j].getAttribute(fAttributeName);//"extension"); - final String type = configElements[j].getAttribute("type"); //$NON-NLS-1$ - if (ext == null || type == null) - continue; - - if (type.equals("text")) { //$NON-NLS-1$ - result.put(ext, Integer.valueOf(Team.TEXT)); - } else if (type.equals("binary")) { //$NON-NLS-1$ - result.put(ext, Integer.valueOf(Team.BINARY)); - } - } - } - return result; - } - - public Map<String, Integer> referenceMap() { - if (fMappings == null) { - fMappings= loadPluginPatterns(); - } - return fMappings; - } - - public int getType(String filename) { - final Map<String, Integer> mappings= referenceMap(); - return mappings.containsKey(filename) ? mappings.get(filename).intValue() : Team.UNKNOWN; - } + private final String fExtensionID; + private final String fAttributeName; + + private SortedMap<String, Integer> fMappings; + + public PluginStringMappings(String extensionID, String stringAttributeName) { + fExtensionID= extensionID; + fAttributeName= stringAttributeName; + } + + /** + * Load all the extension patterns contributed by plugins. + * @return a map with the patterns + */ + private SortedMap<String, Integer> loadPluginPatterns() { + + final SortedMap<String, Integer> result= new TreeMap<>(); + + final TeamPlugin plugin = TeamPlugin.getPlugin(); + if (plugin == null) + return result; + + final IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, fExtensionID);//TeamPlugin.FILE_TYPES_EXTENSION); + if (extension == null) + return result; + + final IExtension[] extensions = extension.getExtensions(); + + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); + + for (int j = 0; j < configElements.length; j++) { + + final String ext = configElements[j].getAttribute(fAttributeName);//"extension"); + final String type = configElements[j].getAttribute("type"); //$NON-NLS-1$ + if (ext == null || type == null) + continue; + + if (type.equals("text")) { //$NON-NLS-1$ + result.put(ext, Integer.valueOf(Team.TEXT)); + } else if (type.equals("binary")) { //$NON-NLS-1$ + result.put(ext, Integer.valueOf(Team.BINARY)); + } + } + } + return result; + } + + public Map<String, Integer> referenceMap() { + if (fMappings == null) { + fMappings= loadPluginPatterns(); + } + return fMappings; + } + + public int getType(String filename) { + final Map<String, Integer> mappings= referenceMap(); + return mappings.containsKey(filename) ? mappings.get(filename).intValue() : Team.UNKNOWN; + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ResourceVariantCache.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ResourceVariantCache.java index c1702941c..ba1bf5be1 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ResourceVariantCache.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ResourceVariantCache.java @@ -100,8 +100,8 @@ public class ResourceVariantCache { public static synchronized void shutdown() { String[] keys = caches.keySet().toArray(new String[caches.size()]); - for (int i = 0; i < keys.length; i++) { - String id = keys[i]; + for (int i = 0; i < keys.length; i++) { + String id = keys[i]; disableCache(id); } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StorageMergerRegistry.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StorageMergerRegistry.java index 27f3f40f1..4c6095879 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StorageMergerRegistry.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StorageMergerRegistry.java @@ -97,11 +97,11 @@ public class StorageMergerRegistry { // collect all IStreamMergers IConfigurationElement[] elements= registry.getConfigurationElementsFor(TeamPlugin.ID, STORAGE_MERGER_EXTENSION_POINT); for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (STORAGE_MERGER.equals(element.getName())) - register(element, new StorageMergerDescriptor(element)); - else if (CONTENT_TYPE_BINDING.equals(element.getName())) - createBinding(element, STORAGE_MERGER_ID_ATTRIBUTE); + IConfigurationElement element= elements[i]; + if (STORAGE_MERGER.equals(element.getName())) + register(element, new StorageMergerDescriptor(element)); + else if (CONTENT_TYPE_BINDING.equals(element.getName())) + createBinding(element, STORAGE_MERGER_ID_ATTRIBUTE); } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java index 82f2e7d8c..b2b22a7e7 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java @@ -77,9 +77,9 @@ final public class TeamPlugin extends Plugin { // The id of the default file modification validator extension point public static final String DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION = "defaultFileModificationValidator"; //$NON-NLS-1$ - // The id used to associate a provider with a project - public final static QualifiedName PROVIDER_PROP_KEY = - new QualifiedName("org.eclipse.team.core", "repository"); //$NON-NLS-1$ //$NON-NLS-2$ + // The id used to associate a provider with a project + public final static QualifiedName PROVIDER_PROP_KEY = + new QualifiedName("org.eclipse.team.core", "repository"); //$NON-NLS-1$ //$NON-NLS-2$ // The id for the Bundle Import extension point public static final String EXTENSION_POINT_BUNDLE_IMPORTERS = ID + ".bundleImporters"; //$NON-NLS-1$ @@ -187,13 +187,13 @@ final public class TeamPlugin extends Plugin { for (int i = 0; i < extensions.length; i++) { IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); for (int j = 0; j < configElements.length; j++) { - String aliasId = configElements[j].getAttribute("canImportId"); //$NON-NLS-1$ - if (aliasId != null && aliasId.equals(id)) { + String aliasId = configElements[j].getAttribute("canImportId"); //$NON-NLS-1$ + if (aliasId != null && aliasId.equals(id)) { String extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$ if (extensionId != null) { return RepositoryProviderType.getProviderType(extensionId); } - } + } } } } @@ -208,11 +208,11 @@ final public class TeamPlugin extends Plugin { IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); for (int j = 0; j < configElements.length; j++) { String extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$ - String metaFilePaths = configElements[j].getAttribute("metaFilePaths"); //$NON-NLS-1$ - if (extensionId != null && extensionId.equals(id) && metaFilePaths != null) { + String metaFilePaths = configElements[j].getAttribute("metaFilePaths"); //$NON-NLS-1$ + if (extensionId != null && extensionId.equals(id) && metaFilePaths != null) { return getPaths(metaFilePaths); - } + } } } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/UserStringMappings.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/UserStringMappings.java index acac94a70..cfe1bc0cd 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/UserStringMappings.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/UserStringMappings.java @@ -28,96 +28,96 @@ import org.eclipse.team.core.Team; public class UserStringMappings implements Preferences.IPropertyChangeListener { - public static final Integer BINARY= Integer.valueOf(Team.BINARY); - public static final Integer TEXT= Integer.valueOf(Team.TEXT); - public static final Integer UNKNOWN= Integer.valueOf(Team.UNKNOWN); - - - private static final String PREF_TEAM_SEPARATOR = "\n"; //$NON-NLS-1$ - - private final Preferences fPreferences; - private final String fKey; - - private Map<String, Integer> fMap; - - public UserStringMappings(String key) { - fKey= key; - fPreferences= TeamPlugin.getPlugin().getPluginPreferences(); - fPreferences.addPropertyChangeListener(this); - } - - public Map<String, Integer> referenceMap() { - if (fMap == null) { - fMap= loadMappingsFromPreferences(); - } - return fMap; - } - - public void addStringMappings(String[] names, int[] types) { - Assert.isTrue(names.length == types.length); - final Map<String, Integer> map= referenceMap(); - - for (int i = 0; i < names.length; i++) { - switch (types[i]) { - case Team.BINARY: map.put(names[i], BINARY); break; - case Team.TEXT: map.put(names[i], TEXT); break; - case Team.UNKNOWN: map.put(names[i], UNKNOWN); break; - } - } - save(); - } - - public void setStringMappings(String [] names, int [] types) { - Assert.isTrue(names.length == types.length); - referenceMap().clear(); - addStringMappings(names, types); - } - - public int getType(String string) { - if (string == null) - return Team.UNKNOWN; - final Integer type= referenceMap().get(string); - return type != null ? type.intValue() : Team.UNKNOWN; - } - - @Override + public static final Integer BINARY= Integer.valueOf(Team.BINARY); + public static final Integer TEXT= Integer.valueOf(Team.TEXT); + public static final Integer UNKNOWN= Integer.valueOf(Team.UNKNOWN); + + + private static final String PREF_TEAM_SEPARATOR = "\n"; //$NON-NLS-1$ + + private final Preferences fPreferences; + private final String fKey; + + private Map<String, Integer> fMap; + + public UserStringMappings(String key) { + fKey= key; + fPreferences= TeamPlugin.getPlugin().getPluginPreferences(); + fPreferences.addPropertyChangeListener(this); + } + + public Map<String, Integer> referenceMap() { + if (fMap == null) { + fMap= loadMappingsFromPreferences(); + } + return fMap; + } + + public void addStringMappings(String[] names, int[] types) { + Assert.isTrue(names.length == types.length); + final Map<String, Integer> map= referenceMap(); + + for (int i = 0; i < names.length; i++) { + switch (types[i]) { + case Team.BINARY: map.put(names[i], BINARY); break; + case Team.TEXT: map.put(names[i], TEXT); break; + case Team.UNKNOWN: map.put(names[i], UNKNOWN); break; + } + } + save(); + } + + public void setStringMappings(String [] names, int [] types) { + Assert.isTrue(names.length == types.length); + referenceMap().clear(); + addStringMappings(names, types); + } + + public int getType(String string) { + if (string == null) + return Team.UNKNOWN; + final Integer type= referenceMap().get(string); + return type != null ? type.intValue() : Team.UNKNOWN; + } + + @Override public void propertyChange(PropertyChangeEvent event) { - if(event.getProperty().equals(fKey)) - fMap= null; - } - - public void save() { - // Now set into preferences - final StringBuilder buffer = new StringBuilder(); - final Iterator e = fMap.keySet().iterator(); - - while (e.hasNext()) { - final String filename = (String)e.next(); - buffer.append(filename); - buffer.append(PREF_TEAM_SEPARATOR); - final Integer type = fMap.get(filename); - buffer.append(type); - buffer.append(PREF_TEAM_SEPARATOR); - } - TeamPlugin.getPlugin().getPluginPreferences().setValue(fKey, buffer.toString()); - } - - protected Map<String, Integer> loadMappingsFromPreferences() { - final Map<String, Integer> result= new HashMap<>(); - - if (!fPreferences.contains(fKey)) - return result; - - final String prefTypes = fPreferences.getString(fKey); - final StringTokenizer tok = new StringTokenizer(prefTypes, PREF_TEAM_SEPARATOR); - try { - while (tok.hasMoreElements()) { - final String name = tok.nextToken(); - final String mode= tok.nextToken(); - result.put(name, Integer.valueOf(mode)); - } - } catch (NoSuchElementException e) { - } - return result; - } + if(event.getProperty().equals(fKey)) + fMap= null; + } + + public void save() { + // Now set into preferences + final StringBuilder buffer = new StringBuilder(); + final Iterator e = fMap.keySet().iterator(); + + while (e.hasNext()) { + final String filename = (String)e.next(); + buffer.append(filename); + buffer.append(PREF_TEAM_SEPARATOR); + final Integer type = fMap.get(filename); + buffer.append(type); + buffer.append(PREF_TEAM_SEPARATOR); + } + TeamPlugin.getPlugin().getPluginPreferences().setValue(fKey, buffer.toString()); + } + + protected Map<String, Integer> loadMappingsFromPreferences() { + final Map<String, Integer> result= new HashMap<>(); + + if (!fPreferences.contains(fKey)) + return result; + + final String prefTypes = fPreferences.getString(fKey); + final StringTokenizer tok = new StringTokenizer(prefTypes, PREF_TEAM_SEPARATOR); + try { + while (tok.hasMoreElements()) { + final String name = tok.nextToken(); + final String mode= tok.nextToken(); + result.put(name, Integer.valueOf(mode)); + |