1 11 12 package org.eclipse.team.internal.ui.synchronize; 13 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.jface.action.*; 16 import org.eclipse.jface.dialogs.IDialogSettings; 17 import org.eclipse.jface.viewers.*; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.team.internal.ui.Policy; 24 import org.eclipse.team.internal.ui.Utils; 25 import org.eclipse.team.internal.ui.synchronize.actions.DirectionFilterActionGroup; 26 import org.eclipse.team.ui.synchronize.*; 27 import org.eclipse.ui.IActionBars; 28 import org.eclipse.ui.IPageLayout; 29 import org.eclipse.ui.part.*; 30 31 42 public abstract class SyncInfoSetSynchronizePage extends Page implements ISynchronizePage, IAdaptable { 43 44 private ISynchronizePageConfiguration configuration; 45 private ISynchronizePageSite site; 46 47 private Composite composite; 50 private ChangesSection changesSection; 51 private Viewer changesViewer; 52 private StructuredViewerAdvisor viewerAdvisor; 53 54 57 class SyncInfoSetActions extends SynchronizePageActionGroup { 58 private DirectionFilterActionGroup modes; 59 public void initialize(ISynchronizePageConfiguration configuration) { 60 super.initialize(configuration); 61 if (isThreeWay()) { 62 modes = new DirectionFilterActionGroup(configuration); 63 } 64 } 65 public void fillActionBars(IActionBars actionBars) { 66 super.fillActionBars(actionBars); 67 if (modes == null) return; 68 IToolBarManager manager = actionBars.getToolBarManager(); 69 IContributionItem group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP); 70 if (manager != null && group != null) { 71 modes.fillToolBar(group.getId(), manager); 72 } 73 IMenuManager viewMenu = actionBars.getMenuManager(); 74 group = findGroup(manager, ISynchronizePageConfiguration.MODE_GROUP); 75 if (viewMenu != null && group != null) { 76 IContributionItem layoutGroup = findGroup(manager, ISynchronizePageConfiguration.LAYOUT_GROUP); 77 if (layoutGroup != null) { 78 group = layoutGroup; 80 } 81 MenuManager modesItem = new MenuManager(Utils.getString("action.modes.label", Policy.getActionBundle())); viewMenu.appendToGroup(group.getId(), modesItem); 83 modes.fillMenu(modesItem); 84 } 85 } 86 private boolean isThreeWay() { 87 return ISynchronizePageConfiguration.THREE_WAY.equals(configuration.getComparisonType()); 88 } 89 } 90 91 95 protected SyncInfoSetSynchronizePage(ISynchronizePageConfiguration configuration) { 96 this.configuration = configuration; 97 configuration.setPage(this); 98 configuration.addActionContribution(new SyncInfoSetActions()); 99 } 100 101 104 public void createControl(Composite parent) { 105 composite = new Composite(parent, SWT.NONE); 106 GridLayout gridLayout= new GridLayout(); 108 gridLayout.makeColumnsEqualWidth= false; 109 gridLayout.marginWidth= 0; 110 gridLayout.marginHeight = 0; 111 gridLayout.verticalSpacing = 0; 112 composite.setLayout(gridLayout); 113 GridData data = new GridData(GridData.FILL_BOTH); 114 data.grabExcessVerticalSpace = true; 115 composite.setLayoutData(data); 116 117 this.changesSection = new ChangesSection(composite, this, configuration); 119 this.changesViewer = createChangesViewer(changesSection.getComposite()); 120 changesSection.setViewer(changesViewer); 121 } 122 123 protected Viewer createChangesViewer(Composite parent) { 124 viewerAdvisor = new TreeViewerAdvisor(parent, configuration); 125 return viewerAdvisor.getViewer(); 126 } 127 128 public StructuredViewerAdvisor getViewerAdvisor() { 129 return viewerAdvisor; 130 } 131 132 135 public Control getControl() { 136 return composite; 137 } 138 139 142 public void setFocus() { 143 changesSection.setFocus(); 144 } 145 146 149 public void init(ISynchronizePageSite site) { 150 this.site = site; 151 IDialogSettings settings = getSettings(); 152 if (settings != null) { 153 try { 154 int mode = settings.getInt(ISynchronizePageConfiguration.P_MODE); 155 if (mode != 0) { 156 configuration.setMode(mode); 157 } 158 } catch (NumberFormatException e) { 159 } 164 } 165 } 166 167 170 public void setActionBars(IActionBars actionBars) { 171 viewerAdvisor.setActionBars(actionBars); 173 } 174 175 178 public void dispose() { 179 changesSection.dispose(); 180 composite.dispose(); 181 super.dispose(); 182 } 183 184 187 public Viewer getViewer() { 188 return changesViewer; 189 } 190 191 194 public boolean aboutToChangeProperty( 195 ISynchronizePageConfiguration configuration, String key, 196 Object newValue) { 197 if (key.equals(ISynchronizePageConfiguration.P_MODE)) { 198 return (internalSetMode(configuration.getMode(), ((Integer )newValue).intValue())); 199 } 200 return true; 201 } 202 203 private boolean internalSetMode(int oldMode, int mode) { 204 if(oldMode == mode) return false; 205 updateMode(mode); 206 IDialogSettings settings = getSettings(); 207 if (settings != null) { 208 settings.put(ISynchronizePageConfiguration.P_MODE, mode); 209 } 210 return true; 211 } 212 213 218 public Object getAdapter(Class key) { 219 if (key.equals(ISelectionProvider.class)) 220 return changesViewer; 221 if (key == IShowInSource.class) { 222 return new IShowInSource() { 223 public ShowInContext getShowInContext() { 224 StructuredViewer v = (StructuredViewer)changesViewer; 225 if (v == null) return null; 226 ISelection s = v.getSelection(); 227 if (s instanceof IStructuredSelection) { 228 Object [] resources = Utils.getResources(((IStructuredSelection)s).toArray()); 229 return new ShowInContext(null, new StructuredSelection(resources)); 230 } 231 return null; 232 } 233 }; 234 } 235 if (key == IShowInTargetList.class) { 236 return new IShowInTargetList() { 237 public String [] getShowInTargetIds() { 238 return new String [] { IPageLayout.ID_RES_NAV }; 239 } 240 241 }; 242 } 243 return null; 244 } 245 246 250 public ISynchronizePageSite getSynchronizePageSite() { 251 return site; 252 } 253 254 259 public ISynchronizePageConfiguration getConfiguration() { 260 return configuration; 261 } 262 263 269 protected IDialogSettings getSettings() { 270 return configuration.getSite().getPageSettings(); 271 } 272 273 278 public abstract void reset(); 279 280 285 protected abstract void updateMode(int mode); 286 } 287 | Popular Tags |