Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 25364 Details for
Bug 102461
(PatchAttached) Allow for keeping commit comments permanent
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
new version of the patch
comment-templates-3.patch (text/plain), 40.14 KB, created by
Maik Schreiber
on 2005-07-27 14:18:14 EDT
(
hide
)
Description:
new version of the patch
Filename:
MIME Type:
Creator:
Maik Schreiber
Created:
2005-07-27 14:18:14 EDT
Size:
40.14 KB
patch
obsolete
>Index: plugin.properties >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/plugin.properties,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 plugin.properties >--- plugin.properties 18 Jul 2005 23:09:11 -0000 1.1.1.1 >+++ plugin.properties 27 Jul 2005 18:15:47 -0000 >@@ -7,6 +7,7 @@ > # > # Contributors: > # IBM Corporation - initial API and implementation >+# Maik Schreiber - bug 102461 > ############################################################################### > providerName=Eclipse.org > pluginName=CVS Team Provider UI >@@ -239,3 +240,5 @@ > > RepoPreference.Name=CVS Repositories > RepoPreference.Description=Preferences that contain the CVS repository connection information >+ >+CommentTemplatesPreferencePage.name=Comment Templates >Index: plugin.xml >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/plugin.xml,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 plugin.xml >--- plugin.xml 18 Jul 2005 23:09:11 -0000 1.1.1.1 >+++ plugin.xml 27 Jul 2005 18:15:48 -0000 >@@ -681,6 +681,16 @@ > <extension > point="org.eclipse.ui.preferencePages"> > <page >+ name="%CommentTemplatesPreferencePage.name" >+ category="org.eclipse.team.cvs.ui.CVSPreferences" >+ class="org.eclipse.team.internal.ccvs.ui.CommentTemplatesPreferencePage" >+ id="org.eclipse.team.cvs.ui.CommentTemplatesPreferences"> >+ <keywordReference id="org.eclipse.team.cvs.ui.cvs"/> >+ </page> >+ </extension> >+ <extension >+ point="org.eclipse.ui.preferencePages"> >+ <page > name="%ConsolePreferencePage.name" > category="org.eclipse.team.cvs.ui.CVSPreferences" > class="org.eclipse.team.internal.ccvs.ui.console.ConsolePreferencesPage" >Index: src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 CVSUIMessages.java >--- src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 18 Jul 2005 23:09:13 -0000 1.1.1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 27 Jul 2005 18:15:51 -0000 >@@ -5,7 +5,8 @@ > * available at http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * IBM - Initial API and implementation >+ * IBM - Initial API and implementation >+ * Maik Schreiber - bug 102461 > **********************************************************************/ > package org.eclipse.team.internal.ccvs.ui; > >@@ -815,6 +816,8 @@ > public static String CommitCommentArea_2; > public static String CommitCommentArea_3; > public static String CommitCommentArea_4; >+ public static String CommitCommentArea_5; >+ public static String CommitCommentArea_6; > > public static String CheckoutProjectOperation_8; > public static String CheckoutProjectOperation_9; >@@ -985,4 +988,12 @@ > > public static String OpenChangeSetAction_0; > public static String OpenChangeSetAction_1; >-} >\ No newline at end of file >+ >+ public static String CommentTemplatesPreferencePage_Description; >+ public static String CommentTemplatesPreferencePage_New; >+ public static String CommentTemplatesPreferencePage_Edit; >+ public static String CommentTemplatesPreferencePage_Remove; >+ public static String CommentTemplatesPreferencePage_Preview; >+ public static String CommentTemplatesPreferencePage_EditCommentTemplateTitle; >+ public static String CommentTemplatesPreferencePage_EditCommentTemplateMessage; >+} >Index: src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 CommitCommentArea.java >--- src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 18 Jul 2005 23:09:13 -0000 1.1.1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 27 Jul 2005 18:15:51 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Sebastian Davids - bug 57208 >+ * Maik Schreiber - bug 102461 > *******************************************************************************/ > package org.eclipse.team.internal.ccvs.ui; > >@@ -26,6 +27,7 @@ > import org.eclipse.team.internal.ccvs.core.*; > import org.eclipse.team.internal.ui.SWTUtils; > import org.eclipse.team.internal.ui.dialogs.DialogArea; >+import org.eclipse.ui.dialogs.PreferencesUtil; > > /** > * This area provides the widgets for providing the CVS commit comment >@@ -125,35 +127,57 @@ > > private final String fMessage; > private final String [] fComments; >+ private String[] fCommentTemplates; > private final Combo fCombo; > > >- public ComboBox(Composite composite, String message, String [] options) { >+ public ComboBox(Composite composite, String message, String [] options, >+ String[] commentTemplates) { > > fMessage= message; > fComments= options; >+ fCommentTemplates = commentTemplates; > > fCombo = new Combo(composite, SWT.READ_ONLY); > fCombo.setLayoutData(SWTUtils.createHFillGridData()); > > // populate the previous comment list >- fCombo.add(fMessage); >- for (int i = 0; i < fComments.length; i++) { >- fCombo.add(HistoryView.flattenText(fComments[i])); >- } >- fCombo.setText(fMessage); >+ populateList(); > > // We don't want to have an initial selection > // (see bug 32078: http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078) > fCombo.addFocusListener(this); > fCombo.addSelectionListener(this); > } >+ >+ private void populateList() { >+ fCombo.removeAll(); >+ >+ fCombo.add(fMessage); >+ for (int i = 0; i < fCommentTemplates.length; i++) { >+ fCombo.add(CVSUIMessages.CommitCommentArea_6 + ": " + //$NON-NLS-1$ >+ HistoryView.flattenText(fCommentTemplates[i])); >+ } >+ for (int i = 0; i < fComments.length; i++) { >+ fCombo.add(HistoryView.flattenText(fComments[i])); >+ } >+ fCombo.setText(fMessage); >+ } > > public void widgetSelected(SelectionEvent e) { >- final int index = fCombo.getSelectionIndex(); >+ int index = fCombo.getSelectionIndex(); > if (index > 0) { >+ index--; > setChanged(); >- notifyObservers(fComments[index - 1]); >+ >+ // map from combo box index to array index >+ String message; >+ if (index < fCommentTemplates.length) { >+ message = fCommentTemplates[index]; >+ } else { >+ message = fComments[index - fCommentTemplates.length]; >+ } >+ notifyObservers(message); > } > } > >@@ -178,10 +202,16 @@ > public void setEnabled(boolean enabled) { > fCombo.setEnabled(enabled); > } >+ >+ void setCommentTemplates(String[] templates) { >+ fCommentTemplates = templates; >+ populateList(); >+ } > } > > private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$ > private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$ >+ private static final String CONFIGURE_TEMPLATES_MESSAGE= CVSUIMessages.CommitCommentArea_5; //$NON-NLS-1$ > > public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$ > public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$ >@@ -206,12 +236,36 @@ > fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment()); > > final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments(); >- fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments); >+ final String[] commentTemplates = CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates(); >+ fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, commentTemplates); >+ >+ Link templatesPrefsLink = new Link(fComposite, 0); >+ templatesPrefsLink.setText("<a href=\"configureTemplates\">" + //$NON-NLS-1$ >+ CONFIGURE_TEMPLATES_MESSAGE + "</a>"); //$NON-NLS-1$ >+ templatesPrefsLink.addSelectionListener(new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ openCommentTemplatesPreferencePage(); >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ openCommentTemplatesPreferencePage(); >+ } >+ }); > > fComboBox.addObserver(fTextBox); > } > >- public String getComment(boolean save) { >+ void openCommentTemplatesPreferencePage() { >+ PreferencesUtil.createPreferenceDialogOn( >+ null, >+ "org.eclipse.team.cvs.ui.CommentTemplatesPreferences", //$NON-NLS-1$ >+ new String[] { "org.eclipse.team.cvs.ui.CommentTemplatesPreferences" }, //$NON-NLS-1$ >+ null).open(); >+ fComboBox.setCommentTemplates( >+ CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates()); >+ } >+ >+ public String getComment(boolean save) { > final String comment= fTextBox.getText(); > if (comment == null) > return ""; //$NON-NLS-1$ >Index: src/org/eclipse/team/internal/ccvs/ui/messages.properties >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 messages.properties >--- src/org/eclipse/team/internal/ccvs/ui/messages.properties 18 Jul 2005 23:09:15 -0000 1.1.1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/messages.properties 27 Jul 2005 18:15:52 -0000 >@@ -7,6 +7,7 @@ > # > # Contributors: > # IBM Corporation - initial API and implementation >+# Maik Schreiber - bug 102461 > ############################################################################### > PasswordManagementPreferencePage_2=When you create a CVS repository location you have the option of saving the password to disk. This page allows you to manage the stored passwords. The following CVS repository locations have saved passwords: > PasswordManagementPreferencePage_3=Location >@@ -853,6 +854,8 @@ > CommitCommentArea_2=Empty commit comment > CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment? > CommitCommentArea_4=Re&member decision? >+CommitCommentArea_5=Configure Comment Templates... >+CommitCommentArea_6=Template > > > >@@ -1039,3 +1042,11 @@ > UncommittedChangesDialog_3=&The dirty resources contained in ''{0}'' > UncommittedChangesDialog_4=&The full path of ''{0}'' > AddWizard_0=Add to Version Control >+ >+CommentTemplatesPreferencePage_Description=&Create, edit or remove comment templates: >+CommentTemplatesPreferencePage_New=&New... >+CommentTemplatesPreferencePage_Edit=&Edit... >+CommentTemplatesPreferencePage_Remove=&Remove >+CommentTemplatesPreferencePage_Preview=Previe&w: >+CommentTemplatesPreferencePage_EditCommentTemplateTitle=Enter Comment Template >+CommentTemplatesPreferencePage_EditCommentTemplateMessage=Please enter a comment template: >Index: src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 RepositoryManager.java >--- src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 18 Jul 2005 23:09:18 -0000 1.1.1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 27 Jul 2005 18:15:53 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Maik Schreiber - bug 102461 > *******************************************************************************/ > package org.eclipse.team.internal.ccvs.ui.repo; > >@@ -47,8 +48,10 @@ > // new state file > private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$ > private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$ >+ private static final String COMMENT_TEMPLATES_FILE = "commentTemplates.xml"; //$NON-NLS-1$ > static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$ > static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$ >+ static final String ELEMENT_COMMENT_TEMPLATES = "CommitCommentTemplates"; //$NON-NLS-1$ > > private Map repositoryRoots = new HashMap(); > >@@ -56,6 +59,7 @@ > > // The previously remembered comment > static String[] previousComments = new String[0]; >+ static String[] commentTemplates = new String[0]; > > public static boolean notifyRepoView = true; > >@@ -303,6 +307,7 @@ > public void startup() { > loadState(); > loadCommentHistory(); >+ loadCommentTemplates(); > CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() { > public void repositoryAdded(ICVSRepositoryLocation root) { > rootAdded(root); >@@ -316,6 +321,7 @@ > public void shutdown() throws TeamException { > saveState(); > saveCommentHistory(); >+ saveCommentTemplates(); > } > > private void loadState() { >@@ -372,6 +378,23 @@ > CVSUIPlugin.log(e); > } > } >+ private void loadCommentTemplates() { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_TEMPLATES_FILE); >+ File file = pluginStateLocation.toFile(); >+ if (!file.exists()) return; >+ try { >+ BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); >+ try { >+ readCommentTemplates(is); >+ } finally { >+ is.close(); >+ } >+ } catch (IOException e) { >+ CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$ >+ } catch (TeamException e) { >+ CVSUIPlugin.log(e); >+ } >+ } > > protected void saveState() throws TeamException { > IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); >@@ -430,6 +453,17 @@ > throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$ > } > } >+ private void readCommentTemplates(InputStream stream) throws IOException, TeamException { >+ try { >+ SAXParserFactory factory = SAXParserFactory.newInstance(); >+ SAXParser parser = factory.newSAXParser(); >+ parser.parse(new InputSource(stream), new CommentTemplatesContentHandler()); >+ } catch (SAXException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_FILE }), ex); //$NON-NLS-1$ >+ } catch (ParserConfigurationException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_FILE }), ex); //$NON-NLS-1$ >+ } >+ } > > private void readOldState(DataInputStream dis) throws IOException, TeamException { > int repoSize = dis.readInt(); >@@ -512,12 +546,40 @@ > throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$ > } > } >+ protected void saveCommentTemplates() throws TeamException { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); >+ File tempFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE + ".tmp").toFile(); //$NON-NLS-1$ >+ File histFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE).toFile(); >+ try { >+ XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); >+ try { >+ writeCommentTemplates(writer); >+ } finally { >+ writer.close(); >+ } >+ if (histFile.exists()) { >+ histFile.delete(); >+ } >+ boolean renamed = tempFile.renameTo(histFile); >+ if (!renamed) { >+ throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$ >+ } >+ } catch (IOException e) { >+ throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$ >+ } >+ } > private void writeCommentHistory(XMLWriter writer) { > writer.startTag(ELEMENT_COMMIT_HISTORY, null, false); > for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++) > writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]); > writer.endTag(ELEMENT_COMMIT_HISTORY); > } >+ private void writeCommentTemplates(XMLWriter writer) { >+ writer.startTag(ELEMENT_COMMENT_TEMPLATES, null, false); >+ for (int i=0; i<commentTemplates.length; i++) >+ writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, commentTemplates[i]); >+ writer.endTag(ELEMENT_COMMENT_TEMPLATES); >+ } > > public void addRepositoryListener(IRepositoryListener listener) { > listeners.add(listener); >@@ -778,21 +840,31 @@ > return previousComments; > } > >+ /** >+ * Get list of comment templates. >+ */ >+ public String[] getCommentTemplates() { >+ return commentTemplates; >+ } >+ > /** > * Method addComment. > * @param string > */ >- public void addComment(String comment) { >- // Only add the comment if its not there already >- if (containsComment(comment)) return; >- // Insert the comment as the first element >- String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)]; >- newComments[0] = comment; >- for (int i = 1; i < newComments.length; i++) { >- newComments[i] = previousComments[i-1]; >- } >- previousComments = newComments; >- } >+ public void addComment(String comment) { >+ // Only add the comment if its not there already >+ if (containsComment(comment) || containsCommentTemplate(comment)) >+ return; >+ >+ // Insert the comment as the first element >+ String[] newComments = new String[Math.min( >+ previousComments.length + 1, MAX_COMMENTS)]; >+ newComments[0] = comment; >+ for (int i = 1; i < newComments.length; i++) { >+ newComments[i] = previousComments[i - 1]; >+ } >+ previousComments = newComments; >+ } > > private boolean containsComment(String comment) { > for (int i = 0; i < previousComments.length; i++) { >@@ -802,4 +874,18 @@ > } > return false; > } >+ >+ private boolean containsCommentTemplate(String comment) { >+ for (int i = 0; i < commentTemplates.length; i++) { >+ if (commentTemplates[i].equals(comment)) { >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ public void replaceAndSaveCommentTemplates(String[] templates) throws TeamException { >+ commentTemplates = templates; >+ saveCommentTemplates(); >+ } > } >Index: src/org/eclipse/team/internal/ccvs/ui/CommentTemplateEditDialog.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/ui/CommentTemplateEditDialog.java >diff -N src/org/eclipse/team/internal/ccvs/ui/CommentTemplateEditDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/ui/CommentTemplateEditDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,260 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ccvs.ui; >+ >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.IInputValidator; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ModifyEvent; >+import org.eclipse.swt.events.ModifyListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * A simple input dialog for soliciting an input string from the user. >+ * <p> >+ * This concrete dialog class can be instantiated as is, or further subclassed as >+ * required. >+ * </p> >+ */ >+public class CommentTemplateEditDialog extends Dialog { >+ /** >+ * The title of the dialog. >+ */ >+ private String title; >+ >+ /** >+ * The message to display, or <code>null</code> if none. >+ */ >+ private String message; >+ >+ /** >+ * The input value; the empty string by default. >+ */ >+ private String value = "";//$NON-NLS-1$ >+ >+ /** >+ * The input validator, or <code>null</code> if none. >+ */ >+ private IInputValidator validator; >+ >+ /** >+ * Ok button widget. >+ */ >+ private Button okButton; >+ >+ /** >+ * Input text widget. >+ */ >+ private Text text; >+ >+ /** >+ * Error message label widget. >+ */ >+ private Text errorMessageText; >+ >+ /** >+ * Creates an input dialog with OK and Cancel buttons. Note that the dialog >+ * will have no visual representation (no widgets) until it is told to open. >+ * <p> >+ * Note that the <code>open</code> method blocks for input dialogs. >+ * </p> >+ * >+ * @param parentShell >+ * the parent shell, or <code>null</code> to create a top-level >+ * shell >+ * @param dialogTitle >+ * the dialog title, or <code>null</code> if none >+ * @param dialogMessage >+ * the dialog message, or <code>null</code> if none >+ * @param initialValue >+ * the initial input value, or <code>null</code> if none >+ * (equivalent to the empty string) >+ * @param validator >+ * an input validator, or <code>null</code> if none >+ */ >+ public CommentTemplateEditDialog(Shell parentShell, String dialogTitle, >+ String dialogMessage, String initialValue, IInputValidator validator) { >+ super(parentShell); >+ this.title = dialogTitle; >+ message = dialogMessage; >+ if (initialValue == null) >+ value = "";//$NON-NLS-1$ >+ else >+ value = initialValue; >+ this.validator = validator; >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected void buttonPressed(int buttonId) { >+ if (buttonId == IDialogConstants.OK_ID) { >+ value = text.getText(); >+ } else { >+ value = null; >+ } >+ super.buttonPressed(buttonId); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) >+ */ >+ protected void configureShell(Shell shell) { >+ super.configureShell(shell); >+ if (title != null) >+ shell.setText(title); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ // create OK and Cancel buttons by default >+ okButton = createButton(parent, IDialogConstants.OK_ID, >+ IDialogConstants.OK_LABEL, true); >+ createButton(parent, IDialogConstants.CANCEL_ID, >+ IDialogConstants.CANCEL_LABEL, false); >+ //do this here because setting the text will set enablement on the ok >+ // button >+ text.setFocus(); >+ if (value != null) { >+ text.setText(value); >+ text.selectAll(); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) Method declared on Dialog. >+ */ >+ protected Control createDialogArea(Composite parent) { >+ // create composite >+ Composite composite = (Composite) super.createDialogArea(parent); >+ // create message >+ if (message != null) { >+ Label label = new Label(composite, SWT.WRAP); >+ label.setText(message); >+ GridData data = new GridData(GridData.GRAB_HORIZONTAL >+ | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL >+ | GridData.VERTICAL_ALIGN_CENTER); >+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); >+ label.setLayoutData(data); >+ label.setFont(parent.getFont()); >+ } >+ text = new Text(composite, SWT.MULTI | SWT.BORDER); >+ GridData gd = new GridData(GridData.GRAB_HORIZONTAL >+ | GridData.HORIZONTAL_ALIGN_FILL); >+ gd.heightHint = convertHeightInCharsToPixels(5); >+ text.setLayoutData(gd); >+ text.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ validateInput(); >+ } >+ }); >+ errorMessageText = new Text(composite, SWT.READ_ONLY); >+ errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL >+ | GridData.HORIZONTAL_ALIGN_FILL)); >+ errorMessageText.setBackground(errorMessageText.getDisplay() >+ .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); >+ >+ applyDialogFont(composite); >+ return composite; >+ } >+ >+ /** >+ * Returns the error message label. >+ * >+ * @return the error message label >+ * @deprecated use setErrorMessage(String) instead >+ */ >+ protected Label getErrorMessageLabel() { >+ return null; >+ } >+ >+ /** >+ * Returns the ok button. >+ * >+ * @return the ok button >+ */ >+ protected Button getOkButton() { >+ return okButton; >+ } >+ >+ /** >+ * Returns the text area. >+ * >+ * @return the text area >+ */ >+ protected Text getText() { >+ return text; >+ } >+ >+ /** >+ * Returns the validator. >+ * >+ * @return the validator >+ */ >+ protected IInputValidator getValidator() { >+ return validator; >+ } >+ >+ /** >+ * Returns the string typed into this input dialog. >+ * >+ * @return the input string >+ */ >+ public String getValue() { >+ return value; >+ } >+ >+ /** >+ * Validates the input. >+ * <p> >+ * The default implementation of this framework method delegates the request >+ * to the supplied input validator object; if it finds the input invalid, >+ * the error message is displayed in the dialog's message line. This hook >+ * method is called whenever the text changes in the input field. >+ * </p> >+ */ >+ protected void validateInput() { >+ String errorMessage = null; >+ if (validator != null) { >+ errorMessage = validator.isValid(text.getText()); >+ } >+ // Bug 16256: important not to treat "" (blank error) the same as null >+ // (no error) >+ setErrorMessage(errorMessage); >+ } >+ >+ /** >+ * Sets or clears the error message. >+ * If not <code>null</code>, the OK button is disabled. >+ * >+ * @param errorMessage >+ * the error message, or <code>null</code> to clear >+ * @since 3.0 >+ */ >+ public void setErrorMessage(String errorMessage) { >+ errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$ >+ okButton.setEnabled(errorMessage == null); >+ errorMessageText.getParent().update(); >+ } >+} >Index: src/org/eclipse/team/internal/ccvs/ui/CommentTemplatesPreferencePage.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/ui/CommentTemplatesPreferencePage.java >diff -N src/org/eclipse/team/internal/ccvs/ui/CommentTemplatesPreferencePage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/ui/CommentTemplatesPreferencePage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,245 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 Maik Schreiber. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Maik Schreiber - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.team.internal.ccvs.ui; >+ >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.preference.PreferencePage; >+import org.eclipse.jface.viewers.DoubleClickEvent; >+import org.eclipse.jface.viewers.IDoubleClickListener; >+import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.ListViewer; >+import org.eclipse.jface.viewers.SelectionChangedEvent; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerSorter; >+import org.eclipse.jface.window.Window; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.List; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.team.core.TeamException; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPreferencePage; >+ >+public class CommentTemplatesPreferencePage extends PreferencePage implements >+ IWorkbenchPreferencePage, ISelectionChangedListener { >+ >+ private ListViewer viewer; >+ private Button editButton; >+ private Button removeButton; >+ private Text preview; >+ >+ protected Control createContents(Composite ancestor) { >+ Composite parent = new Composite(ancestor, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ layout.numColumns = 1; >+ parent.setLayout(layout); >+ parent.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ createListAndButtons(parent); >+ >+ Label previewLabel = new Label(parent, SWT.NONE); >+ previewLabel.setText(CVSUIMessages.CommentTemplatesPreferencePage_Preview); >+ >+ preview = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER); >+ GridData gd = new GridData(GridData.FILL_HORIZONTAL); >+ gd.heightHint = convertHeightInCharsToPixels(5); >+ preview.setLayoutData(gd); >+ >+ Dialog.applyDialogFont(ancestor); >+ >+ return parent; >+ } >+ >+ private Composite createListAndButtons(Composite parent) { >+ Composite listAndButtons = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ layout.numColumns = 2; >+ listAndButtons.setLayout(layout); >+ listAndButtons.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ viewer = new ListViewer(listAndButtons); >+ viewer.setLabelProvider(new LabelProvider() { >+ public String getText(Object element) { >+ String template = (String) element; >+ return HistoryView.flattenText(template); >+ } >+ }); >+ viewer.addSelectionChangedListener(this); >+ viewer.setSorter(new ViewerSorter() { >+ public int compare(Viewer viewer, Object e1, Object e2) { >+ String template1 = HistoryView.flattenText((String) e1); >+ String template2 = HistoryView.flattenText((String) e2); >+ return template1.compareToIgnoreCase(template2); >+ } >+ }); >+ viewer.addDoubleClickListener(new IDoubleClickListener() { >+ public void doubleClick(DoubleClickEvent event) { >+ editTemplate(); >+ } >+ }); >+ List list = viewer.getList(); >+ list.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ // populate list >+ String[] templates = >+ CVSUIPlugin.getPlugin().getRepositoryManager().getCommentTemplates(); >+ for (int i = 0; i < templates.length; i++) { >+ viewer.add(templates[i]); >+ } >+ >+ createButtons(listAndButtons); >+ return listAndButtons; >+ } >+ >+ private void createButtons(Composite parent) { >+ Composite buttons = new Composite(parent, SWT.NONE); >+ buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); >+ GridLayout layout = new GridLayout(); >+ layout.marginHeight = 0; >+ layout.marginWidth = 0; >+ buttons.setLayout(layout); >+ >+ Button newButton = new Button(buttons, SWT.PUSH); >+ newButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_New); >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); >+ data.widthHint = Math.max(widthHint, >+ newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); >+ newButton.setLayoutData(data); >+ newButton.setEnabled(true); >+ newButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event event) { >+ newTemplate(); >+ } >+ }); >+ >+ editButton = new Button(buttons, SWT.PUSH); >+ editButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_Edit); >+ data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); >+ data.widthHint = Math.max(widthHint, >+ editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); >+ editButton.setLayoutData(data); >+ editButton.setEnabled(false); >+ editButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event e) { >+ editTemplate(); >+ } >+ }); >+ >+ removeButton = new Button(buttons, SWT.PUSH); >+ removeButton.setText(CVSUIMessages.CommentTemplatesPreferencePage_Remove); >+ data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); >+ data.widthHint = Math.max(widthHint, >+ removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); >+ removeButton.setLayoutData(data); >+ removeButton.setEnabled(false); >+ removeButton.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(Event e) { >+ remove(); >+ } >+ }); >+ } >+ >+ public void init(IWorkbench workbench) { >+ setDescription(CVSUIMessages.CommentTemplatesPreferencePage_Description); >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ IStructuredSelection selection = (IStructuredSelection) event.getSelection(); >+ switch (selection.size()) { >+ case 0: >+ editButton.setEnabled(false); >+ removeButton.setEnabled(false); >+ preview.setText(""); //$NON-NLS-1$ >+ break; >+ >+ case 1: >+ editButton.setEnabled(true); >+ removeButton.setEnabled(true); >+ preview.setText((String) selection.getFirstElement()); >+ break; >+ >+ default: >+ editButton.setEnabled(false); >+ removeButton.setEnabled(true); >+ preview.setText(""); //$NON-NLS-1$ >+ break; >+ } >+ } >+ >+ void newTemplate() { >+ CommentTemplateEditDialog dialog = new CommentTemplateEditDialog( >+ getShell(), >+ CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateTitle, >+ CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateMessage, >+ "", null); //$NON-NLS-1$ >+ if (dialog.open() == Window.OK) { >+ viewer.add(dialog.getValue()); >+ } >+ } >+ >+ void editTemplate() { >+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); >+ if (selection.size() == 1) { >+ String oldTemplate = (String) selection.getFirstElement(); >+ CommentTemplateEditDialog dialog = new CommentTemplateEditDialog( >+ getShell(), >+ CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateTitle, >+ CVSUIMessages.CommentTemplatesPreferencePage_EditCommentTemplateMessage, >+ oldTemplate, null); >+ if (dialog.open() == Window.OK) { >+ viewer.remove(oldTemplate); >+ viewer.add(dialog.getValue()); >+ } >+ } >+ } >+ >+ void remove() { >+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); >+ viewer.remove(selection.toArray()); >+ } >+ >+ public boolean performOk() { >+ int numTemplates = viewer.getList().getItemCount(); >+ String[] templates = new String[numTemplates]; >+ for (int i = 0; i < numTemplates; i++) { >+ templates[i] = (String) viewer.getElementAt(i); >+ } >+ try { >+ CVSUIPlugin.getPlugin().getRepositoryManager() >+ .replaceAndSaveCommentTemplates(templates); >+ } catch (TeamException e) { >+ // TODO: handle save error >+ } >+ >+ return super.performOk(); >+ } >+} >Index: src/org/eclipse/team/internal/ccvs/ui/repo/CommentTemplatesContentHandler.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/ui/repo/CommentTemplatesContentHandler.java >diff -N src/org/eclipse/team/internal/ccvs/ui/repo/CommentTemplatesContentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/ui/repo/CommentTemplatesContentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.team.internal.ccvs.ui.repo; >+ >+import java.util.Vector; >+ >+import org.xml.sax.Attributes; >+import org.xml.sax.helpers.DefaultHandler; >+ >+class CommentTemplatesContentHandler extends DefaultHandler { >+ >+ private StringBuffer buffer; >+ private Vector comments; >+ public CommentTemplatesContentHandler() { >+ } >+ >+ /** >+ * @see ContentHandler#characters(char[], int, int) >+ */ >+ public void characters(char[] chars, int startIndex, int length) { >+ if (buffer == null) return; >+ buffer.append(chars, startIndex, length); >+ } >+ >+ /** >+ * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) >+ */ >+ public void startElement( >+ String namespaceURI, >+ String localName, >+ String qName, >+ Attributes atts) { >+ >+ String elementName = getElementName(localName, qName); >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) { >+ buffer = new StringBuffer(); >+ return; >+ } >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMENT_TEMPLATES)) { >+ comments = new Vector(); >+ return; >+ } >+ } >+ >+ /** >+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) >+ */ >+ public void endElement(String namespaceURI, String localName, String qName) { >+ String elementName = getElementName(localName, qName); >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) { >+ comments.add(buffer.toString()); >+ buffer = null; >+ return; >+ } >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMENT_TEMPLATES)) { >+ RepositoryManager.commentTemplates = new String[comments.size()]; >+ comments.copyInto(RepositoryManager.commentTemplates); >+ return; >+ } >+ } >+ >+ /* >+ * Couldn't figure out from the SAX API exactly when localName vs. qName is used. >+ * However, the XML for project sets doesn't use namespaces so either of the two names >+ * is fine. Therefore, use whichever one is provided. >+ */ >+ private String getElementName(String localName, String qName) { >+ if (localName != null && localName.length() > 0) { >+ return localName; >+ } >+ return qName; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 102461
:
24301
|
24310
|
24894
|
24963
| 25364