KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > merge > MergeWizardEndPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.merge;
12
13
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.jface.viewers.ISelectionChangedListener;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.SelectionChangedEvent;
19 import org.eclipse.jface.viewers.TreeViewer;
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.jface.viewers.ViewerSorter;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Tree;
26 import org.eclipse.team.core.TeamException;
27 import org.eclipse.team.internal.ccvs.core.CVSTag;
28 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
29 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
30 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
31 import org.eclipse.team.internal.ccvs.ui.Policy;
32 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage;
33 import org.eclipse.ui.help.WorkbenchHelp;
34 import org.eclipse.ui.model.WorkbenchContentProvider;
35 import org.eclipse.ui.model.WorkbenchLabelProvider;
36
37 public class MergeWizardEndPage extends CVSWizardPage {
38     IProject project;
39     TreeViewer tree;
40     CVSTag result;
41     ICVSRemoteFolder remote;
42     // for accessing the start tag
43
MergeWizardStartPage startPage;
44     
45     /**
46      * MergeWizardEndPage constructor.
47      *
48      * @param pageName the name of the page
49      * @param title the title of the page
50      * @param titleImage the image for the page
51      */

52     public MergeWizardEndPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage, MergeWizardStartPage startPage) {
53         super(pageName, title, titleImage);
54         setDescription(Policy.bind("MergeWizardEndPage.description")); //$NON-NLS-1$
55
this.startPage = startPage;
56     }
57     /*
58      * @see IDialogPage#createControl(Composite)
59      */

60     public void createControl(Composite parent) {
61         Composite composite = createComposite(parent, 2);
62         // set F1 help
63
WorkbenchHelp.setHelp(composite, IHelpContextIds.MERGE_END_PAGE);
64         
65         tree = createTree(composite);
66         tree.setContentProvider(new WorkbenchContentProvider());
67         tree.setLabelProvider(new WorkbenchLabelProvider());
68         tree.setSorter(new ViewerSorter() {
69             public int compare(Viewer v, Object JavaDoc o1, Object JavaDoc o2) {
70                 int result = super.compare(v, o1, o2);
71                 if (o1 instanceof TagElement && o2 instanceof TagElement) {
72                     return -result;
73                 }
74                 return result;
75             }
76         });
77         tree.addSelectionChangedListener(new ISelectionChangedListener() {
78             public void selectionChanged(SelectionChangedEvent event) {
79                 Object JavaDoc selected = ((IStructuredSelection)tree.getSelection()).getFirstElement();
80                 if (selected instanceof TagElement) {
81                     result = ((TagElement)selected).getTag();
82                     if(!result.equals(startPage.getTag())) {
83                         setPageComplete(true);
84                         setMessage(null);
85                     } else {
86                         setMessage(Policy.bind("MergeWizardEndPage.duplicateTagSelected", result.getName()), WARNING); //$NON-NLS-1$
87
setPageComplete(false);
88                     }
89                 } else {
90                     setMessage(null);
91                     result = null;
92                     setPageComplete(false);
93                 }
94             }
95         });
96         setControl(composite);
97         tree.setInput(new ProjectElement(CVSWorkspaceRoot.getCVSFolderFor(project), ProjectElement.INCLUDE_ALL_TAGS));
98         setPageComplete(false);
99     }
100     protected TreeViewer createTree(Composite parent) {
101         Tree tree = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
102         tree.setLayoutData(new GridData(GridData.FILL_BOTH));
103         return new TreeViewer(tree);
104     }
105     public void setProject(IProject project) {
106         this.project = project;
107         try {
108             this.remote = (ICVSRemoteFolder) CVSWorkspaceRoot.getRemoteResourceFor(project);
109         } catch (TeamException e) {
110             // To do
111
}
112     }
113     public CVSTag getTag() {
114         return result;
115     }
116     /**
117      * @see IDialogPage#setVisible(boolean)
118      */

119     public void setVisible(boolean visible) {
120         super.setVisible(visible);
121         // refresh the tree because tags may have been added in the previous page
122
tree.refresh();
123         if (visible) {
124             tree.getControl().setFocus();
125         }
126     }
127 }
128
Popular Tags