KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > wizards > RepositorySelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.ccvs.ui.wizards;
12
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.jface.viewers.*;
17 import org.eclipse.osgi.util.TextProcessor;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
22 import org.eclipse.team.internal.ccvs.ui.*;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.model.*;
25
26 /**
27  * First wizard page for importing a project into a CVS repository.
28  * This page prompts the user to select an existing repo or create a new one.
29  * If the user selected an existing repo, then getLocation() will return it.
30  */

31 public class RepositorySelectionPage extends CVSWizardPage {
32     
33     private class DecoratingRepoLabelProvider extends WorkbenchLabelProvider {
34         protected String JavaDoc decorateText(String JavaDoc input, Object JavaDoc element) {
35             //Used to process RTL locales only
36
return TextProcessor.process(input, ":@/"); //$NON-NLS-1$
37
}
38     }
39     
40     
41     private TableViewer table;
42     private Button useExistingRepo;
43     private Button useNewRepo;
44     
45     private ICVSRepositoryLocation result;
46     
47     String JavaDoc extendedDescription;
48     
49     /**
50      * RepositorySelectionPage constructor.
51      *
52      * @param pageName the name of the page
53      * @param title the title of the page
54      * @param titleImage the image for the page
55      */

56     public RepositorySelectionPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage) {
57         super(pageName, title, titleImage);
58     }
59     protected TableViewer createTable(Composite parent, int span) {
60         Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
61         GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
62         data.horizontalSpan = span;
63         data.widthHint = 200;
64         table.setLayoutData(data);
65         TableLayout layout = new TableLayout();
66         layout.addColumnData(new ColumnWeightData(100, true));
67         table.setLayout(layout);
68         TableColumn col = new TableColumn(table, SWT.NONE);
69         col.setResizable(true);
70     
71         return new TableViewer(table);
72     }
73     /**
74      * Creates the UI part of the page.
75      *
76      * @param parent the parent of the created widgets
77      */

78     public void createControl(Composite parent) {
79         Composite composite = createComposite(parent, 1, false);
80         // set F1 help
81
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_SELECT_REPOSITORY_PAGE);
82         if (extendedDescription == null) {
83             extendedDescription = CVSUIMessages.RepositorySelectionPage_description;
84         }
85         createWrappingLabel(composite, extendedDescription, 0 /* indent */, 1 /* columns */);
86         
87         useNewRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useNew, 1);
88         
89         useExistingRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useExisting, 1);
90         table = createTable(composite, 1);
91         table.setContentProvider(new WorkbenchContentProvider());
92         table.setLabelProvider(new DecoratingRepoLabelProvider()/*WorkbenchLabelProvider()*/);
93         table.addDoubleClickListener(new IDoubleClickListener() {
94             public void doubleClick(DoubleClickEvent event) {
95                 getContainer().showPage(getNextPage());
96             }
97         });
98
99         setControl(composite);
100
101         initializeValues();
102         Dialog.applyDialogFont(parent);
103         
104         table.addSelectionChangedListener(new ISelectionChangedListener() {
105             public void selectionChanged(SelectionChangedEvent event) {
106                 result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement();
107                 setPageComplete(true);
108             }
109         });
110         
111         useExistingRepo.addListener(SWT.Selection, new Listener() {
112             public void handleEvent(Event event) {
113                 if (useNewRepo.getSelection()) {
114                     table.getTable().setEnabled(false);
115                     result = null;
116                 } else {
117                     table.getTable().setEnabled(true);
118                     result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement();
119                 }
120                 setPageComplete(true);
121             }
122         });
123     }
124     /**
125      * Initializes states of the controls.
126      */

127     private void initializeValues() {
128         ICVSRepositoryLocation[] locations = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations();
129         AdaptableList input = new AdaptableList(locations);
130         table.setInput(input);
131         if (locations.length == 0) {
132             useNewRepo.setSelection(true);
133             useExistingRepo.setSelection(false);
134             table.getTable().setEnabled(false);
135         } else {
136             useNewRepo.setSelection(false);
137             useExistingRepo.setSelection(true);
138             table.getTable().setEnabled(true);
139             result = locations[0];
140             table.setSelection(new StructuredSelection(result));
141         }
142         setPageComplete(true);
143     }
144     
145     public ICVSRepositoryLocation getLocation() {
146         return result;
147     }
148     public void setVisible(boolean visible) {
149         super.setVisible(visible);
150         if (visible) {
151             useExistingRepo.setFocus();
152         }
153     }
154     
155     public void setExtendedDescription(String JavaDoc extendedDescription) {
156         this.extendedDescription = extendedDescription;
157     }
158 }
159
Popular Tags