KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > compare > CompareDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.compare;
12
13 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.*;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21
22 import org.eclipse.jface.dialogs.*;
23 import org.eclipse.jface.viewers.Viewer;
24
25 import org.eclipse.ui.PlatformUI;
26
27 import org.eclipse.compare.*;
28 import org.eclipse.compare.structuremergeviewer.ICompareInput;
29
30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31
32
33 class CompareDialog extends ResizableDialog {
34     
35     class ViewerSwitchingPane extends CompareViewerSwitchingPane {
36         
37         ViewerSwitchingPane(Composite parent, int style) {
38             super(parent, style, false);
39         }
40     
41         protected Viewer getViewer(Viewer oldViewer, Object JavaDoc input) {
42             if (input instanceof ICompareInput)
43                 return CompareUI.findContentViewer(oldViewer, (ICompareInput)input, this, fCompareConfiguration);
44             return null;
45         }
46                 
47         public void setImage(Image image) {
48             // don't show icon
49
}
50     }
51     
52     private CompareViewerSwitchingPane fContentPane;
53     private CompareConfiguration fCompareConfiguration;
54     private ICompareInput fInput;
55     
56     
57     CompareDialog(Shell parent, ResourceBundle JavaDoc bundle) {
58         super(parent, bundle);
59         
60         fCompareConfiguration= new CompareConfiguration();
61         fCompareConfiguration.setLeftEditable(false);
62         fCompareConfiguration.setRightEditable(false);
63     }
64     
65     void compare(ICompareInput input) {
66         
67         fInput= input;
68         
69         fCompareConfiguration.setLeftLabel(fInput.getLeft().getName());
70         fCompareConfiguration.setLeftImage(fInput.getLeft().getImage());
71         
72         fCompareConfiguration.setRightLabel(fInput.getRight().getName());
73         fCompareConfiguration.setRightImage(fInput.getRight().getImage());
74         
75         if (fContentPane != null)
76             fContentPane.setInput(fInput);
77             
78         open();
79     }
80     
81      /* (non Javadoc)
82      * Creates SWT control tree.
83      */

84     protected synchronized Control createDialogArea(Composite parent2) {
85         
86         Composite parent= (Composite) super.createDialogArea(parent2);
87
88         getShell().setText(JavaCompareUtilities.getString(fBundle, "title")); //$NON-NLS-1$
89

90         fContentPane= new ViewerSwitchingPane(parent, SWT.BORDER | SWT.FLAT);
91         fContentPane.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL
92                     | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL));
93         
94         if (fInput != null)
95             fContentPane.setInput(fInput);
96             
97         applyDialogFont(parent);
98         return parent;
99     }
100     
101     /* (non-Javadoc)
102      * Method declared on Dialog.
103      */

104     protected void createButtonsForButtonBar(Composite parent) {
105         String JavaDoc buttonLabel= JavaCompareUtilities.getString(fBundle, "buttonLabel", IDialogConstants.OK_LABEL); //$NON-NLS-1$
106
createButton(parent, IDialogConstants.CANCEL_ID, buttonLabel, false);
107     }
108
109     /*
110      * @see org.eclipse.jface.window.Window#configureShell(Shell)
111      */

112     protected void configureShell(Shell newShell) {
113         super.configureShell(newShell);
114         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.COMPARE_DIALOG);
115     }
116 }
117
Popular Tags