1 11 package org.eclipse.team.internal.ccvs.ui.merge; 12 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.viewers.ColumnWeightData; 18 import org.eclipse.jface.viewers.DoubleClickEvent; 19 import org.eclipse.jface.viewers.IDoubleClickListener; 20 import org.eclipse.jface.viewers.ISelectionChangedListener; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.jface.viewers.SelectionChangedEvent; 23 import org.eclipse.jface.viewers.TableLayout; 24 import org.eclipse.jface.viewers.TableViewer; 25 import org.eclipse.jface.viewers.Viewer; 26 import org.eclipse.jface.viewers.ViewerSorter; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Table; 31 import org.eclipse.swt.widgets.TableColumn; 32 import org.eclipse.team.internal.ccvs.core.CVSTag; 33 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 34 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 35 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds; 36 import org.eclipse.team.internal.ccvs.ui.Policy; 37 import org.eclipse.team.internal.ccvs.ui.TagConfigurationDialog; 38 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage; 39 import org.eclipse.ui.help.WorkbenchHelp; 40 import org.eclipse.ui.model.WorkbenchContentProvider; 41 import org.eclipse.ui.model.WorkbenchLabelProvider; 42 43 public class MergeWizardStartPage extends CVSWizardPage { 44 TableViewer table; 45 CVSTag result; 46 IProject project; 47 48 private static final int TABLE_HEIGHT_HINT = 350; 49 private static final int TABLE_WIDTH_HINT = 100; 50 51 58 public MergeWizardStartPage(String pageName, String title, ImageDescriptor titleImage) { 59 super(pageName, title, titleImage); 60 setDescription(Policy.bind("MergeWizardStartPage.description")); } 62 protected TableViewer createTable(Composite parent) { 63 Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); 64 GridData data = new GridData(GridData.FILL_BOTH); 65 data.heightHint = TABLE_HEIGHT_HINT; 66 data.widthHint = TABLE_WIDTH_HINT; 67 table.setLayoutData(data); 68 TableLayout layout = new TableLayout(); 69 layout.addColumnData(new ColumnWeightData(100, true)); 70 table.setLayout(layout); 71 TableColumn col = new TableColumn(table, SWT.NONE); 72 col.setResizable(true); 73 74 return new TableViewer(table); 75 } 76 79 public void createControl(Composite parent) { 80 Composite composite = createComposite(parent, 1); 81 WorkbenchHelp.setHelp(composite, IHelpContextIds.MERGE_START_PAGE); 83 84 table = createTable(composite); 85 table.setContentProvider(new WorkbenchContentProvider()); 86 table.setLabelProvider(new WorkbenchLabelProvider()); 87 table.setSorter(new ViewerSorter() { 88 public int compare(Viewer v, Object o1, Object o2) { 89 int result = super.compare(v, o1, o2); 90 if (o1 instanceof TagElement && o2 instanceof TagElement) { 91 return -result; 92 } 93 return result; 94 } 95 }); 96 table.addSelectionChangedListener(new ISelectionChangedListener() { 97 public void selectionChanged(SelectionChangedEvent event) { 98 IStructuredSelection selection = (IStructuredSelection)table.getSelection(); 99 if(!selection.isEmpty()) { 100 TagElement element = (TagElement)((IStructuredSelection)table.getSelection()).getFirstElement(); 101 if(element!=null) { 102 result = element.getTag(); 103 setPageComplete(true); 104 } 105 } 106 } 107 }); 108 table.addDoubleClickListener(new IDoubleClickListener() { 109 public void doubleClick(DoubleClickEvent event) { 110 getContainer().showPage(getNextPage()); 111 } 112 }); 113 114 Runnable afterRefresh = new Runnable () { 115 public void run() { 116 getShell().getDisplay().syncExec(new Runnable () { 117 public void run() { 118 table.refresh(); 119 setPageComplete(! table.getSelection().isEmpty()); 120 } 121 }); 122 } 123 }; 124 125 Runnable afterConfigure = new Runnable () { 126 public void run() { 127 getShell().getDisplay().syncExec(new Runnable () { 128 public void run() { 129 initialize(); 130 } 131 }); 132 } 133 }; 134 135 setControl(composite); 136 TagConfigurationDialog.createTagDefinitionButtons(getShell(), composite, new ICVSFolder[] {CVSWorkspaceRoot.getCVSFolderFor(project)}, 137 convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT), 138 convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH), 139 afterRefresh, afterConfigure); 140 initialize(); 141 setPageComplete(false); 142 } 143 private void initialize() { 144 ICVSFolder cvsProject = CVSWorkspaceRoot.getCVSFolderFor(project); 145 table.setInput(new TagRootElement(cvsProject, CVSTag.VERSION)); 146 } 147 public void setProject(IProject project) { 148 this.project = project; 149 } 150 public CVSTag getTag() { 151 return result; 152 } 153 public void setVisible(boolean visible) { 154 super.setVisible(visible); 155 if (visible) { 156 table.getControl().setFocus(); 157 } 158 } 159 } 160 | Popular Tags |