1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.jface.action.*; 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 import org.eclipse.jface.viewers.*; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.team.internal.ui.Policy; 23 import org.eclipse.team.internal.ui.Utils; 24 import org.eclipse.team.internal.ui.synchronize.actions.DirectionFilterActionGroup; 25 import org.eclipse.team.ui.synchronize.*; 26 import org.eclipse.ui.IActionBars; 27 import org.eclipse.ui.IPageLayout; 28 import org.eclipse.ui.part.*; 29 30 35 public abstract class AbstractSynchronizePage extends Page implements ISynchronizePage, IAdaptable { 36 37 private ISynchronizePageConfiguration configuration; 38 private ISynchronizePageSite site; 39 40 private Composite composite; 43 private ChangesSection changesSection; 44 private Viewer changesViewer; 45 46 private AbstractViewerAdvisor viewerAdvisor; 47 48 51 class ModeFilterActions extends SynchronizePageActionGroup { 52 private DirectionFilterActionGroup modes; 53 public void initialize(ISynchronizePageConfiguration configuration) { 54 super.initialize(configuration); 55 if (isThreeWay()) { 56 modes = new DirectionFilterActionGroup(configuration); 57 } 58 } 59 public void fillActionBars(IActionBars actionBars) { 60 super.fillActionBars(actionBars); 61 if (modes == null) return; 62 IToolBarManager manager = actionBars.getToolBarManager(); 63 IContributionItem group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP); 64 if (manager != null && group != null) { 65 modes.fillToolBar(group.getId(), manager); 66 } 67 IMenuManager viewMenu = actionBars.getMenuManager(); 68 group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP); 69 if (viewMenu != null && group != null) { 70 IContributionItem layoutGroup = findGroup(manager, ISynchronizePageConfiguration.LAYOUT_GROUP); 71 if (layoutGroup != null) { 72 group = layoutGroup; 74 } 75 MenuManager modesItem = new MenuManager(Utils.getString("action.modes.label", Policy.getActionBundle())); viewMenu.appendToGroup(group.getId(), modesItem); 77 modes.fillMenu(modesItem); 78 } 79 } 80 private boolean isThreeWay() { 81 return ISynchronizePageConfiguration.THREE_WAY.equals(configuration.getComparisonType()); 82 } 83 } 84 85 89 protected AbstractSynchronizePage(ISynchronizePageConfiguration configuration) { 90 this.configuration = configuration; 91 configuration.setPage(this); 92 configuration.addActionContribution(new ModeFilterActions()); 93 } 94 95 98 public void createControl(Composite parent) { 99 composite = new Composite(parent, SWT.NONE); 100 GridLayout gridLayout= new GridLayout(); 102 gridLayout.makeColumnsEqualWidth= false; 103 gridLayout.marginWidth= 0; 104 gridLayout.marginHeight = 0; 105 gridLayout.verticalSpacing = 0; 106 composite.setLayout(gridLayout); 107 GridData data = new GridData(GridData.FILL_BOTH); 108 data.grabExcessVerticalSpace = true; 109 composite.setLayoutData(data); 110 111 this.changesSection = createChangesSection(composite); 113 this.changesViewer = createChangesViewer(changesSection.getContainer()); 114 changesSection.setViewer(changesViewer); 115 } 116 117 121 protected abstract ChangesSection createChangesSection(Composite parent); 122 123 130 protected Viewer createChangesViewer(Composite parent) { 131 viewerAdvisor = createViewerAdvisor(parent); 132 return viewerAdvisor.getViewer(); 133 } 134 135 protected abstract AbstractViewerAdvisor createViewerAdvisor(Composite parent); 136 137 public AbstractViewerAdvisor getViewerAdvisor() { 138 return viewerAdvisor; 139 } 140 141 144 public void setActionBars(IActionBars actionBars) { 145 viewerAdvisor.setActionBars(actionBars); 147 } 148 149 152 public Control getControl() { 153 return composite; 154 } 155 156 159 public void setFocus() { 160 changesSection.setFocus(); 161 } 162 163 166 public void init(ISynchronizePageSite site) { 167 this.site = site; 168 IDialogSettings settings = getSettings(); 169 if (settings != null) { 170 try { 171 int mode = settings.getInt(ISynchronizePageConfiguration.P_MODE); 172 if (mode != 0) { 173 configuration.setMode(mode); 174 } 175 } catch (NumberFormatException e) { 176 } 181 } 182 } 183 184 187 public void dispose() { 188 changesSection.dispose(); 189 composite.dispose(); 190 super.dispose(); 191 } 192 193 196 public Viewer getViewer() { 197 return changesViewer; 198 } 199 200 203 public boolean aboutToChangeProperty( 204 ISynchronizePageConfiguration configuration, String key, 205 Object newValue) { 206 if (key.equals(ISynchronizePageConfiguration.P_MODE)) { 207 return (internalSetMode(configuration.getMode(), ((Integer )newValue).intValue())); 208 } 209 return true; 210 } 211 212 private boolean internalSetMode(int oldMode, int mode) { 213 if(oldMode == mode) return false; 214 updateMode(mode); 215 IDialogSettings settings = getSettings(); 216 if (settings != null) { 217 settings.put(ISynchronizePageConfiguration.P_MODE, mode); 218 } 219 return true; 220 } 221 222 227 public Object getAdapter(Class key) { 228 if (key.equals(ISelectionProvider.class)) 229 return changesViewer; 230 if (key == IShowInSource.class) { 231 return new IShowInSource() { 232 public ShowInContext getShowInContext() { 233 StructuredViewer v = (StructuredViewer)changesViewer; 234 if (v == null) return null; 235 ISelection s = v.getSelection(); 236 if (s instanceof IStructuredSelection) { 237 Object [] resources = Utils.getResources(((IStructuredSelection)s).toArray()); 238 return new ShowInContext(null, new StructuredSelection(resources)); 239 } 240 return null; 241 } 242 }; 243 } 244 if (key == IShowInTargetList.class) { 245 return new IShowInTargetList() { 246 public String [] getShowInTargetIds() { 247 return new String [] { IPageLayout.ID_RES_NAV }; 248 } 249 250 }; 251 } 252 return null; 253 } 254 255 259 public ISynchronizePageSite getSynchronizePageSite() { 260 return site; 261 } 262 263 268 public ISynchronizePageConfiguration getConfiguration() { 269 return configuration; 270 } 271 272 278 protected IDialogSettings getSettings() { 279 return configuration.getSite().getPageSettings(); 280 } 281 282 287 public abstract void reset(); 288 289 294 protected abstract void updateMode(int mode); 295 296 public ChangesSection getChangesSection() { 297 return changesSection; 298 } 299 } 300 | Popular Tags |