View | Details | Raw Unified | Return to bug 223857 | Differences between
and this patch

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/CompareMessages.java (+3 lines)
Lines 130-135 Link Here
130
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
130
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
131
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
131
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
132
132
133
	public static String ChangeEncodingAction_message_noEncodingSupport;
134
	public static String ChangeEncodingAction_button_apply_label;
135
133
	static {
136
	static {
134
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
137
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
135
	}
138
	}
(-)compare/org/eclipse/compare/internal/CompareMessages.properties (+4 lines)
Lines 141-143 Link Here
141
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
141
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
142
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
142
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
143
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace
143
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace
144
145
# change encoding action
146
ChangeEncodingAction_message_noEncodingSupport=No encoding support installed
147
ChangeEncodingAction_button_apply_label=Apply
(-)compare/org/eclipse/compare/internal/MergeSourceViewer.java (+2 lines)
Lines 105-110 Link Here
105
	public static final String SAVE_ID= "save"; //$NON-NLS-1$
105
	public static final String SAVE_ID= "save"; //$NON-NLS-1$
106
	public static final String FIND_ID= "find"; //$NON-NLS-1$
106
	public static final String FIND_ID= "find"; //$NON-NLS-1$
107
	public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$
107
	public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$
108
	public static final String CHANGE_ENCODING_ID= "changeEncoding"; //$NON-NLS-1$
108
109
109
	class TextOperationAction extends MergeViewerAction {
110
	class TextOperationAction extends MergeViewerAction {
110
		
111
		
Lines 799-804 Link Here
799
		addMenu(menu, SELECT_ALL_ID);
800
		addMenu(menu, SELECT_ALL_ID);
800
801
801
		menu.add(new Separator("edit")); //$NON-NLS-1$
802
		menu.add(new Separator("edit")); //$NON-NLS-1$
803
		addMenu(menu, CHANGE_ENCODING_ID);
802
		menu.add(new Separator("find")); //$NON-NLS-1$
804
		menu.add(new Separator("find")); //$NON-NLS-1$
803
		addMenu(menu, FIND_ID);
805
		addMenu(menu, FIND_ID);
804
		
806
		
(-)compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java (-8 / +90 lines)
Lines 37-42 Link Here
37
import org.eclipse.compare.ITypedElement;
37
import org.eclipse.compare.ITypedElement;
38
import org.eclipse.compare.SharedDocumentAdapter;
38
import org.eclipse.compare.SharedDocumentAdapter;
39
import org.eclipse.compare.internal.BufferedCanvas;
39
import org.eclipse.compare.internal.BufferedCanvas;
40
import org.eclipse.compare.internal.ChangeEncodingAction;
40
import org.eclipse.compare.internal.ChangePropertyAction;
41
import org.eclipse.compare.internal.ChangePropertyAction;
41
import org.eclipse.compare.internal.CompareEditorSelectionProvider;
42
import org.eclipse.compare.internal.CompareEditorSelectionProvider;
42
import org.eclipse.compare.internal.CompareHandlerService;
43
import org.eclipse.compare.internal.CompareHandlerService;
Lines 157-162 Link Here
157
import org.eclipse.ui.actions.ActionFactory;
158
import org.eclipse.ui.actions.ActionFactory;
158
import org.eclipse.ui.contexts.IContextService;
159
import org.eclipse.ui.contexts.IContextService;
159
import org.eclipse.ui.editors.text.EditorsUI;
160
import org.eclipse.ui.editors.text.EditorsUI;
161
import org.eclipse.ui.editors.text.IEncodingSupport;
162
import org.eclipse.ui.editors.text.IStorageDocumentProvider;
160
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
163
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
161
import org.eclipse.ui.texteditor.AbstractTextEditor;
164
import org.eclipse.ui.texteditor.AbstractTextEditor;
162
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
165
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
Lines 497-503 Link Here
497
		}
500
		}
498
	}
501
	}
499
502
500
	class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener {
503
	class ContributorInfo implements IElementStateListener, VerifyListener, IDocumentListener, IEncodingSupport {
501
		private final TextMergeViewer fViewer;
504
		private final TextMergeViewer fViewer;
502
		private final Object fElement;
505
		private final Object fElement;
503
		private char fLeg;
506
		private char fLeg;
Lines 521-531 Link Here
521
				}
524
				}
522
			}
525
			}
523
		}
526
		}
524
		
527
528
		public void setEncoding(String encoding) {
529
			if (fDocumentKey == null || fDocumentProvider == null) {
530
				return;
531
			}
532
			if (fDocumentProvider instanceof IStorageDocumentProvider) {
533
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
534
				String current = provider.getEncoding(fDocumentKey);
535
				boolean dirty = fDocumentProvider.canSaveDocument(fDocumentKey);
536
				if (!dirty) {
537
					String internal = encoding == null ? "" : encoding; //$NON-NLS-1$
538
					if (!internal.equals(current)) {
539
						provider.setEncoding(fDocumentKey, encoding);
540
						try {
541
							fDocumentProvider.resetDocument(fDocumentKey);
542
						} catch (CoreException e) {
543
							// TODO:
544
							e.printStackTrace();
545
						}
546
					}
547
				}
548
			}
549
		}
550
525
		public String getEncoding() {
551
		public String getEncoding() {
526
			if (fEncoding == null)
552
			if (fDocumentProvider != null && fDocumentKey != null
527
				return ResourcesPlugin.getEncoding();
553
					&& fDocumentProvider instanceof IStorageDocumentProvider) {
528
			return fEncoding;
554
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
555
				return provider.getEncoding(fDocumentKey);
556
			}
557
			return null;
558
		}
559
560
		public String getDefaultEncoding() {
561
			if (fDocumentProvider != null && fDocumentKey != null
562
					&& fDocumentProvider instanceof IStorageDocumentProvider) {
563
				IStorageDocumentProvider provider = (IStorageDocumentProvider) fDocumentProvider;
564
				return provider.getDefaultEncoding();
565
			}
566
			return null;
567
		}
568
569
		public String getInternalEncoding() {
570
			if (fEncoding != null) {
571
				return fEncoding;
572
			}
573
			return ResourcesPlugin.getEncoding();
529
		}
574
		}
530
575
531
		public void setEncodingIfAbsent(ContributorInfo otherContributor) {
576
		public void setEncodingIfAbsent(ContributorInfo otherContributor) {
Lines 716-722 Link Here
716
				String s= null;
761
				String s= null;
717
762
718
				try {
763
				try {
719
					String encoding = getEncoding();
764
					String encoding = getInternalEncoding();
720
					s = Utilities.readString(sca, encoding);
765
					s = Utilities.readString(sca, encoding);
721
				} catch (CoreException ex) {
766
				} catch (CoreException ex) {
722
					this.fViewer.setError(fLeg, ex.getMessage());
767
					this.fViewer.setError(fLeg, ex.getMessage());
Lines 836-842 Link Here
836
		 * </ol>
881
		 * </ol>
837
		 * @return the document key used to obtain a shared document or <code>null</code>
882
		 * @return the document key used to obtain a shared document or <code>null</code>
838
		 */
883
		 */
839
		private IEditorInput getDocumentKey() {
884
		public IEditorInput getDocumentKey() {
840
			if (fDocumentKey != null)
885
			if (fDocumentKey != null)
841
				return fDocumentKey;
886
				return fDocumentKey;
842
			if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) {
887
			if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) {
Lines 979-984 Link Here
979
			if (oldContributor != null) {
1024
			if (oldContributor != null) {
980
				fSelection = oldContributor.fSelection;
1025
				fSelection = oldContributor.fSelection;
981
				fTopIndex = oldContributor.fTopIndex;
1026
				fTopIndex = oldContributor.fTopIndex;
1027
				fEncoding = oldContributor.fEncoding;
982
			}
1028
			}
983
				
1029
				
984
		}
1030
		}
Lines 1937-1942 Link Here
1937
				service.activateContext("org.eclipse.ui.textEditorScope"); //$NON-NLS-1$
1983
				service.activateContext("org.eclipse.ui.textEditorScope"); //$NON-NLS-1$
1938
			}
1984
			}
1939
		}
1985
		}
1986
		
1987
		contributeChangeEncodingAction(fAncestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR);
1988
		contributeChangeEncodingAction(fLeft, MergeViewerContentProvider.LEFT_CONTRIBUTOR);
1989
		contributeChangeEncodingAction(fRight, MergeViewerContentProvider.RIGHT_CONTRIBUTOR);
1940
	}
1990
	}
1941
	
1991
	
1942
	private void hsynchViewport(final TextViewer tv1, final TextViewer tv2, final TextViewer tv3) {
1992
	private void hsynchViewport(final TextViewer tv1, final TextViewer tv2, final TextViewer tv3) {
Lines 2430-2435 Link Here
2430
		viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action);
2480
		viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action);
2431
	}
2481
	}
2432
2482
2483
	private void contributeChangeEncodingAction(MergeSourceViewer viewer, char type) {
2484
		IAction action = new ChangeEncodingAction(this, type, fComposite.getShell());
2485
		viewer.addAction(MergeSourceViewer.CHANGE_ENCODING_ID, action);
2486
	}
2487
2433
	private void connectGlobalActions(final MergeSourceViewer part) {
2488
	private void connectGlobalActions(final MergeSourceViewer part) {
2434
		if (fHandlerService != null) {
2489
		if (fHandlerService != null) {
2435
			if (part != null)
2490
			if (part != null)
Lines 2938-2944 Link Here
2938
				if (contents != null) {
2993
				if (contents != null) {
2939
					byte[] bytes;
2994
					byte[] bytes;
2940
					try {
2995
					try {
2941
						bytes= contents.getBytes(left ? fLeftContributor.getEncoding() : fRightContributor.getEncoding());
2996
						bytes= contents.getBytes(left ? fLeftContributor.getInternalEncoding() : fRightContributor.getInternalEncoding());
2942
					} catch(UnsupportedEncodingException ex) {
2997
					} catch(UnsupportedEncodingException ex) {
2943
						// use default encoding
2998
						// use default encoding
2944
						bytes= contents.getBytes();
2999
						bytes= contents.getBytes();
Lines 4898-4901 Link Here
4898
			return true;
4953
			return true;
4899
		return false;
4954
		return false;
4900
	}
4955
	}
4956
4957
	public IEncodingSupport getEncodingSupport(char type) {
4958
		switch (type) {
4959
		case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR:
4960
			return fAncestorContributor;
4961
		case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
4962
			return fLeftContributor;
4963
		case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
4964
			return fRightContributor;
4965
		default:
4966
			return null;
4967
		}
4968
	}
4969
4970
	public IEditorInput getEditorInput(char type) {
4971
		switch (type) {
4972
		case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR:
4973
			return fAncestorContributor.getDocumentKey();
4974
		case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
4975
			return fLeftContributor.getDocumentKey();
4976
		case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
4977
			return fRightContributor.getDocumentKey();
4978
		default:
4979
			return null;
4980
		}
4981
	}
4982
4901
}
4983
}
(-)compare/org/eclipse/compare/internal/ChangeEncodingAction.java (+214 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
12
13
import java.util.ResourceBundle;
14
15
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.jface.dialogs.Dialog;
18
import org.eclipse.jface.dialogs.DialogPage;
19
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.jface.preference.PreferenceStore;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.ui.editors.text.IEncodingSupport;
31
import org.eclipse.ui.ide.dialogs.AbstractEncodingFieldEditor;
32
import org.eclipse.ui.ide.dialogs.EncodingFieldEditor;
33
import org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor;
34
import org.eclipse.ui.texteditor.ResourceAction;
35
36
public class ChangeEncodingAction extends ResourceAction {
37
	
38
	private static final int APPLY_ID= IDialogConstants.OK_ID + IDialogConstants.CANCEL_ID + 1;
39
40
	private static final String BUNDLE_FOR_CONSTRUCTED_KEYS = "org.eclipse.ui.texteditor.ConstructedTextEditorMessages"; //$NON-NLS-1$
41
	private static final String ENCODING_PREF_KEY= "encoding"; //$NON-NLS-1$
42
	private static final String PREFIX = "Editor.ChangeEncodingAction.";
43
44
	private static ResourceBundle fgBundleForConstructedKeys = ResourceBundle
45
			.getBundle(BUNDLE_FOR_CONSTRUCTED_KEYS);
46
47
	private String fDialogTitle;
48
	private TextMergeViewer viewer;
49
	private char type;
50
	private Shell shell;
51
52
	public ChangeEncodingAction(TextMergeViewer viewer, char type, Shell shell) {
53
		super(fgBundleForConstructedKeys, PREFIX); //$NON-NLS-1$
54
		this.viewer = viewer;
55
		this.type = type;
56
		this.shell = shell;
57
58
		String key = PREFIX + "dialog.title"; //$NON-NLS-1$;
59
		fDialogTitle = getString(fgBundleForConstructedKeys, key, null);
60
	}
61
62
	/*
63
	 * @see org.eclipse.jface.action.Action#run()
64
	 */
65
	public void run() {
66
		final IResource resource= getResource();
67
		final IEncodingSupport encodingSupport= getEncodingSupport();
68
		if (resource == null && encodingSupport == null) {
69
			MessageDialog.openInformation(shell, fDialogTitle, CompareMessages.ChangeEncodingAction_message_noEncodingSupport);
70
			return;
71
		}
72
73
		Dialog dialog= new Dialog(shell) {
74
			private AbstractEncodingFieldEditor fEncodingEditor;
75
			private IPreferenceStore store= null;
76
77
			/*
78
			 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
79
			 */
80
			protected void configureShell(Shell newShell) {
81
				super.configureShell(newShell);
82
				newShell.setText(fDialogTitle);
83
			}
84
85
			/*
86
			 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
87
			 */
88
			protected Control createDialogArea(Composite parent) {
89
				Control composite= super.createDialogArea(parent);
90
				if (!(composite instanceof Composite)) {
91
					composite.dispose();
92
					composite= new Composite(parent, SWT.NONE);
93
				}
94
95
				GridLayout layout= new GridLayout();
96
				layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
97
				layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
98
				layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
99
				layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
100
				parent.setLayout(layout);
101
102
				GridData data = new GridData(GridData.FILL_BOTH);
103
				composite.setLayoutData(data);
104
				composite.setFont(parent.getFont());
105
106
				DialogPage page= new MessageDialogPage((Composite)composite) {
107
					public void setErrorMessage(String newMessage) {
108
						super.setErrorMessage(newMessage);
109
						setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
110
						setButtonEnabledState(APPLY_ID, newMessage == null);
111
					}
112
113
					private void setButtonEnabledState(int id, boolean state) {
114
						Button button= getButton(id);
115
						if (button != null)
116
							button.setEnabled(state);
117
					}
118
				};
119
120
				if (resource != null) {
121
					fEncodingEditor= new ResourceEncodingFieldEditor("", (Composite)composite, resource); //$NON-NLS-1$
122
					fEncodingEditor.setPage(page);
123
					fEncodingEditor.load();
124
				} else {
125
					fEncodingEditor= new EncodingFieldEditor(ENCODING_PREF_KEY, "", (Composite)composite); //$NON-NLS-1$
126
					store= new PreferenceStore();
127
					String defaultEncoding= encodingSupport.getDefaultEncoding();
128
					if (defaultEncoding != null) {
129
						store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
130
					}
131
					String encoding= encodingSupport.getEncoding();
132
					if (encoding != null)
133
						store.setValue(ENCODING_PREF_KEY, encoding);
134
					fEncodingEditor.setPreferenceStore(store);
135
136
					fEncodingEditor.setPage(page);
137
					fEncodingEditor.load();
138
139
					if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
140
						fEncodingEditor.loadDefault();
141
				}
142
143
				return composite;
144
			}
145
146
			/*
147
			 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
148
			 */
149
			protected void createButtonsForButtonBar(Composite parent) {
150
				createButton(parent, APPLY_ID, CompareMessages.ChangeEncodingAction_button_apply_label, false);
151
				super.createButtonsForButtonBar(parent);
152
			}
153
154
			/*
155
			 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
156
			 */
157
			protected void buttonPressed(int buttonId) {
158
				if (buttonId == APPLY_ID)
159
					apply();
160
				else
161
					super.buttonPressed(buttonId);
162
			}
163
164
			/*
165
			 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
166
			 */
167
			protected void okPressed() {
168
				apply();
169
				super.okPressed();
170
			}
171
172
			private void apply() {
173
				fEncodingEditor.store();
174
175
				if (resource == null) {
176
					String encoding= fEncodingEditor.getPreferenceStore().getString(fEncodingEditor.getPreferenceName());
177
					encodingSupport.setEncoding(encoding);
178
				}
179
			}
180
		};
181
		dialog.open();
182
	}
183
184
	/*
185
	 * @see org.eclipse.ui.texteditor.IUpdate#update()
186
	 */
187
	public void update() {
188
		setEnabled((getResource() != null || getEncodingSupport() != null));
189
	}
190
191
	/**
192
	 * Gets the resource which is being edited in the editor.
193
	 *
194
	 * @return the resource being edited or <code>null</code>s
195
	 */
196
	private IResource getResource() {
197
		if (viewer != null && viewer.getEditorInput(type) != null)
198
			return (IResource)viewer.getEditorInput(type).getAdapter(IResource.class);
199
200
		return null;
201
	}
202
203
	/**
204
	 * Gets the editor's encoding support.
205
	 *
206
	 * @return the resource being edited or <code>null</code>s
207
	 */
208
	private IEncodingSupport getEncodingSupport() {
209
		if (viewer != null)
210
			return viewer.getEncodingSupport(type);
211
212
		return null;
213
	}
214
}
(-)compare/org/eclipse/compare/internal/MessageRegion.java (+190 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Rectangle;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Label;
21
import org.eclipse.swt.widgets.Text;
22
23
import org.eclipse.jface.dialogs.Dialog;
24
import org.eclipse.jface.dialogs.IDialogConstants;
25
import org.eclipse.jface.dialogs.IMessageProvider;
26
import org.eclipse.jface.resource.JFaceColors;
27
import org.eclipse.jface.resource.JFaceResources;
28
29
30
/**
31
 * The MessageRegion is the optional area to
32
 * show messages in the page.
33
 * <p>
34
 * XXX: Copied from org.eclipse.jface.preference.PreferencePage.MessageRegion
35
 * 		see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=84061
36
 * </p>
37
 *
38
 * @since 3.1
39
 */
40
class MessageRegion {
41
42
	private Text messageText;
43
44
	private Label messageImageLabel;
45
46
	private Composite messageComposite;
47
48
	private String lastMessageText = "";//$NON-NLS-1$
49
50
	private int lastMessageType;
51
52
	/**
53
	 * Create a new instance of the receiver.
54
	 */
55
	public MessageRegion() {
56
		//No initial behavior
57
	}
58
59
	/**
60
	 * Create the contents for the receiver.
61
	 *
62
	 * @param parent the Composite that the children will be created in
63
	 */
64
	public void createContents(Composite parent) {
65
		messageComposite = new Composite(parent, SWT.NONE);
66
		GridLayout messageLayout = new GridLayout();
67
		messageLayout.numColumns = 2;
68
		messageLayout.marginWidth = 0;
69
		messageLayout.marginHeight = 0;
70
		messageLayout.makeColumnsEqualWidth = false;
71
		messageComposite.setLayout(messageLayout);
72
		messageImageLabel = new Label(messageComposite, SWT.NONE);
73
74
		GridData imageData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
75
		Image sizingImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
76
		Rectangle imageBounds;
77
		if(sizingImage == null)
78
			imageBounds = new Rectangle(0,0,IDialogConstants.VERTICAL_MARGIN * 2,IDialogConstants.VERTICAL_MARGIN * 2);
79
		else
80
			imageBounds = sizingImage.getBounds();
81
		imageData.heightHint = imageBounds.height + IDialogConstants.VERTICAL_SPACING;
82
		imageData.widthHint = imageBounds.width + IDialogConstants.HORIZONTAL_SPACING;
83
		messageImageLabel.setLayoutData(imageData);
84
85
		messageText = new Text(messageComposite, SWT.NONE);
86
		messageText.setEditable(false);
87
		messageText.setBackground(parent.getDisplay().getSystemColor(
88
				SWT.COLOR_WIDGET_BACKGROUND));
89
90
		GridData textData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL
91
				| GridData.VERTICAL_ALIGN_CENTER);
92
		messageText.setLayoutData(textData);
93
		hideRegion();
94
95
	}
96
97
	/**
98
	 * Set the layoutData for the messageArea. In most cases this will be a copy of the layoutData
99
	 * used in setTitleLayoutData.
100
	 *
101
	 * @param layoutData the layoutData for the message area composite.
102
	 */
103
	public void setMessageLayoutData(Object layoutData) {
104
		messageComposite.setLayoutData(layoutData);
105
	}
106
107
	/**
108
	 * Show the new message in the message text and update the image. Base the background color on
109
	 * whether or not there are errors.
110
	 *
111
	 * @param newMessage The new value for the message
112
	 * @param newType One of the IMessageProvider constants. If newType is IMessageProvider.NONE
113
	 *            show the title.
114
	 * @see IMessageProvider
115
	 */
116
	public void updateText(String newMessage, int newType) {
117
		Image newImage = null;
118
		boolean showingError = false;
119
		switch (newType) {
120
		case IMessageProvider.NONE:
121
			hideRegion();
122
			return;
123
		case IMessageProvider.INFORMATION:
124
			newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
125
			break;
126
		case IMessageProvider.WARNING:
127
			newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
128
			break;
129
		case IMessageProvider.ERROR:
130
			newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
131
			showingError = true;
132
			break;
133
		}
134
135
		if(newMessage == null){//No message so clear the area
136
			hideRegion();
137
			return;
138
		}
139
		showRegion();
140
		// Any more updates required
141
		if (newMessage.equals(messageText.getText())
142
				&& newImage == messageImageLabel.getImage())
143
			return;
144
		messageImageLabel.setImage(newImage);
145
		messageText.setText(newMessage);
146
		if (showingError)
147
			setMessageColors(JFaceColors.getErrorBackground(messageComposite.getDisplay()));
148
		else {
149
			lastMessageText = newMessage;
150
			setMessageColors(JFaceColors.getBannerBackground(messageComposite.getDisplay()));
151
		}
152
153
	}
154
155
	/**
156
	 * Show and enable the widgets in the message region
157
	 */
158
	private void showRegion() {
159
		messageComposite.setVisible(true);
160
	}
161
162
	/**
163
	 * Hide the message region and clear out the caches.
164
	 */
165
	private void hideRegion() {
166
		messageComposite.setVisible(false);
167
		lastMessageText = null;
168
		lastMessageType = IMessageProvider.NONE;
169
	}
170
171
	/**
172
	 * Set the colors of the message area.
173
	 *
174
	 * @param color the color to be use in the message area.
175
	 */
176
	private void setMessageColors(Color color) {
177
		messageText.setBackground(color);
178
		messageComposite.setBackground(color);
179
		messageImageLabel.setBackground(color);
180
	}
181
182
	/**
183
	 * Clear the error message. Restore the previously displayed message if
184
	 * there is one, if not restore the title label.
185
	 *
186
	 */
187
	public void clearErrorMessage() {
188
		updateText(lastMessageText, lastMessageType);
189
	}
190
}
(-)compare/org/eclipse/compare/internal/MessageDialogPage.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Hiroyuki Inaba <hiroyuki.inaba@jp.fujitsu.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140121
11
 *******************************************************************************/
12
13
package org.eclipse.compare.internal;
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Composite;
19
20
import org.eclipse.jface.dialogs.Dialog;
21
import org.eclipse.jface.dialogs.DialogPage;
22
import org.eclipse.jface.dialogs.IMessageProvider;
23
24
/**
25
 * Dialog page used to show text or error message.
26
 *
27
 * @since 3.1
28
 */
29
class MessageDialogPage extends DialogPage {
30
31
	MessageRegion fMessageRegion;
32
33
34
	public MessageDialogPage(Composite parent) {
35
		createControl(parent);
36
	}
37
38
	public void createControl(Composite parent) {
39
		Composite composite1= new Composite(parent, SWT.NONE);
40
		composite1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
41
		GridLayout layout = new GridLayout();
42
		layout.marginWidth = 0;
43
		layout.marginHeight = 0;
44
		composite1.setLayout(layout);
45
		fMessageRegion= new MessageRegion();
46
		fMessageRegion.createContents(composite1);
47
		GridData messageData= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
48
		fMessageRegion.setMessageLayoutData(messageData);
49
		setControl(composite1);
50
		Dialog.applyDialogFont(composite1);
51
	}
52
53
	public void setMessage(String newMessage,int newType) {
54
		super.setMessage(newMessage, newType);
55
		fMessageRegion.updateText(newMessage, newType);
56
	}
57
58
	public void setErrorMessage(String newMessage) {
59
		super.setErrorMessage(newMessage);
60
		fMessageRegion.updateText(newMessage, IMessageProvider.ERROR);
61
	}
62
}

Return to bug 223857