Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 140337 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +4 lines)
Lines 66-70 Link Here
66
 org.eclipse.ui.console,
66
 org.eclipse.ui.console,
67
 org.eclipse.core.filebuffers,
67
 org.eclipse.core.filebuffers,
68
 org.eclipse.core.runtime,
68
 org.eclipse.core.runtime,
69
 org.eclipse.help
69
 org.eclipse.help,
70
 org.eclipse.ui.navigator,
71
 org.eclipse.core.expressions,
72
 org.eclipse.ui.navigator.resources
70
Eclipse-LazyStart: true
73
Eclipse-LazyStart: true
(-)plugin.properties (+3 lines)
Lines 328-330 Link Here
328
328
329
IndexView.name=C/C++ Index
329
IndexView.name=C/C++ Index
330
RebuildIndex.name=Rebuild Index
330
RebuildIndex.name=Rebuild Index
331
332
# Common Navigator
333
navigatorContent.name = CDT Elements
(-)plugin.xml (+213 lines)
Lines 1358-1361 Link Here
1358
    </objectContribution>
1358
    </objectContribution>
1359
 </extension>
1359
 </extension>
1360
1360
1361
<!--- Common Navigator extensions -->
1362
 <extension
1363
       point="org.eclipse.ui.navigator.navigatorContent">
1364
    <navigatorContent
1365
          activeByDefault="true"
1366
          contentProvider="org.eclipse.cdt.internal.ui.navigator.CNavigatorContentProvider"
1367
          icon="icons/view16/cview.gif"
1368
          id="org.eclipse.cdt.ui.navigator.content"
1369
          labelProvider="org.eclipse.cdt.internal.ui.navigator.CNavigatorLabelProvider"
1370
          name="%navigatorContent.name"
1371
          priority="normal">
1372
       <triggerPoints>
1373
          <or>
1374
             <adapt type="org.eclipse.core.resources.IProject">
1375
                <or>
1376
                   <test
1377
                         property="org.eclipse.core.resources.projectNature"
1378
                         value="org.eclipse.cdt.core.cnature"/>
1379
                   <test
1380
                         property="org.eclipse.core.resources.projectNature"
1381
                         value="org.eclipse.cdt.core.ccnature"/>
1382
                </or>
1383
             </adapt>
1384
             <instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/>
1385
             <instanceof value="org.eclipse.core.resources.IFolder" />
1386
             <instanceof value="org.eclipse.core.resources.IFile" />
1387
             <instanceof value="org.eclipse.core.resources.IStorage" />
1388
             <instanceof value="org.eclipse.cdt.core.model.ICProject"/>
1389
             <instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
1390
             <instanceof value="org.eclipse.cdt.core.model.ICElement"/>
1391
             <instanceof value="org.eclipse.cdt.ui.CElementGrouping"/>
1392
          </or>
1393
       </triggerPoints>
1394
       <possibleChildren>
1395
          <or>
1396
             <instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/>
1397
	         <instanceof value="org.eclipse.core.resources.IFolder" />
1398
	         <instanceof value="org.eclipse.core.resources.IFile" />
1399
	         <instanceof value="org.eclipse.core.resources.IStorage" />
1400
             <instanceof value="org.eclipse.cdt.core.model.ICProject"/>
1401
             <instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
1402
             <instanceof value="org.eclipse.cdt.core.model.ICElement"/>
1403
             <instanceof value="org.eclipse.cdt.ui.CElementGrouping"/>
1404
          </or>
1405
       </possibleChildren>
1406
       <override
1407
             policy="InvokeAlwaysRegardlessOfSuppressedExt"
1408
             suppressedExtensionId="org.eclipse.ui.navigator.resourceContent"/>
1409
       <commonSorter
1410
             class="org.eclipse.cdt.ui.CElementSorter"
1411
             id="org.eclipse.cdt.ui.commonSorter"/>
1412
       <actionProvider
1413
             class="org.eclipse.cdt.internal.ui.navigator.CNavigatorOpenActionProvider"
1414
             id="org.eclipse.cdt.ui.navigator.actions.open"
1415
             overrides="org.eclipse.ui.navigator.resources.OpenActions">
1416
          <enablement>
1417
             <instanceof value="org.eclipse.cdt.core.model.ICElement"/>
1418
          </enablement>
1419
       </actionProvider>
1420
       <actionProvider
1421
             class="org.eclipse.cdt.internal.ui.navigator.CNavigatorBuildActionProvider"
1422
             id="org.eclipse.cdt.ui.navigator.actions.build">
1423
          <enablement>
1424
             <instanceof value="org.eclipse.cdt.core.model.ICElement"/>
1425
          </enablement>
1426
       </actionProvider>
1427
       <actionProvider
1428
             class="org.eclipse.cdt.internal.ui.navigator.CNavigatorWorkingSetActionProvider"
1429
             id="org.eclipse.cdt.ui.navigator.actions.workingSet">
1430
       </actionProvider>
1431
       <actionProvider
1432
             class="org.eclipse.cdt.internal.ui.navigator.CNavigatorSearchActionProvider"
1433
             id="org.eclipse.cdt.ui.navigator.actions.search">
1434
          <enablement>
1435
             <instanceof value="org.eclipse.cdt.core.model.ICElement"/>
1436
          </enablement>
1437
       </actionProvider>
1438
	   <commonWizard
1439
	         associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
1440
	         menuGroupId="org.eclipse.cdt.ui"
1441
	         type="new"
1442
	         wizardId="org.eclipse.cdt.ui.wizards.NewSourceFileCreationWizard">
1443
				<enablement>
1444
					<or>
1445
						<instanceof value="org.eclipse.cdt.core.model.ICElement" />	
1446
			            <adapt type="org.eclipse.core.resources.IProject">
1447
			               <or>
1448
			                  <test
1449
			                        property="org.eclipse.core.resources.projectNature"
1450
			                        value="org.eclipse.cdt.core.cnature"/>
1451
			                  <test
1452
			                        property="org.eclipse.core.resources.projectNature"
1453
			                        value="org.eclipse.cdt.core.ccnature"/>
1454
			               </or>
1455
			            </adapt>
1456
					</or>
1457
		         </enablement>
1458
	   </commonWizard>
1459
       <commonWizard
1460
            associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
1461
            menuGroupId="org.eclipse.cdt.ui"
1462
            type="new"
1463
            wizardId="org.eclipse.cdt.ui.wizards.NewHeaderFileCreationWizard">
1464
				<enablement>
1465
					<or>
1466
						<instanceof value="org.eclipse.cdt.core.model.ICElement" />	
1467
			            <adapt type="org.eclipse.core.resources.IProject">
1468
			               <or>
1469
			                  <test
1470
			                        property="org.eclipse.core.resources.projectNature"
1471
			                        value="org.eclipse.cdt.core.cnature"/>
1472
			                  <test
1473
			                        property="org.eclipse.core.resources.projectNature"
1474
			                        value="org.eclipse.cdt.core.ccnature"/>
1475
			               </or>
1476
			            </adapt>
1477
					</or>
1478
		         </enablement>
1479
	   </commonWizard>
1480
       <commonWizard
1481
            associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
1482
            menuGroupId="org.eclipse.cdt.ui"
1483
            type="new"
1484
            wizardId="org.eclipse.cdt.ui.wizards.NewSourceFolderCreationWizard">
1485
				<enablement>
1486
					<or>
1487
						<instanceof value="org.eclipse.cdt.core.model.ICElement" />	
1488
			            <adapt type="org.eclipse.core.resources.IProject">
1489
			               <or>
1490
			                  <test
1491
			                        property="org.eclipse.core.resources.projectNature"
1492
			                        value="org.eclipse.cdt.core.cnature"/>
1493
			                  <test
1494
			                        property="org.eclipse.core.resources.projectNature"
1495
			                        value="org.eclipse.cdt.core.ccnature"/>
1496
			               </or>
1497
			            </adapt>
1498
					</or>
1499
		         </enablement>
1500
	   </commonWizard>
1501
       <commonWizard
1502
            associatedExtensionId="org.eclipse.cdt.ui.navigator.content"
1503
            menuGroupId="org.eclipse.cdt.ui"
1504
            type="new"
1505
            wizardId="org.eclipse.cdt.ui.wizards.NewClassCreationWizard">
1506
				<enablement>
1507
					<or>
1508
						<instanceof value="org.eclipse.cdt.core.model.ICElement" />	
1509
			            <adapt type="org.eclipse.core.resources.IProject">
1510
			               <or>
1511
			                  <test
1512
			                        property="org.eclipse.core.resources.projectNature"
1513
			                        value="org.eclipse.cdt.core.ccnature"/>
1514
			               </or>
1515
			            </adapt>
1516
					</or>
1517
		         </enablement>
1518
	   </commonWizard>
1519
     <dropAssistant
1520
           class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDropAdapterAssistant"
1521
           id="org.eclipse.cdt.ui.navigator.dropAssistant">
1522
        <possibleDropTargets>
1523
           <or>
1524
              <instanceof value="org.eclipse.cdt.core.model.ISourceReference"/>
1525
           </or>
1526
        </possibleDropTargets>
1527
     </dropAssistant>
1528
    </navigatorContent>
1529
    <commonFilter
1530
          class="org.eclipse.cdt.internal.ui.filters.ExecutableFilter"
1531
          description="%HideExecutableFiles.description"
1532
          id="org.eclipse.cdt.ui.navigator.filters.ExecutableFilter"
1533
          name="%HideExecutableFiles.label"/>
1534
    <commonFilter
1535
          class="org.eclipse.cdt.internal.ui.filters.SharedFilter"
1536
          description="%HideSharedFiles.description"
1537
          id="org.eclipse.cdt.ui.navigator.filters.SharedFilter"
1538
          name="%HideSharedFiles.label"/>
1539
    <commonFilter
1540
          class="org.eclipse.cdt.internal.ui.filters.ObjectFilter"
1541
          description="%HideObjectFiles.description"
1542
          id="org.eclipse.cdt.ui.navigator.filters.ObjectFilter"
1543
          name="%HideObjectFiles.label"/>
1544
    <commonFilter
1545
          class="org.eclipse.cdt.internal.ui.filters.ArchiveFilter"
1546
          description="%HideArchiveFiles.description"
1547
          id="org.eclipse.cdt.ui.navigator.filters.ArchiveFilter"
1548
          name="%HideArchiveFiles.label"/>
1549
    <commonFilter
1550
          class="org.eclipse.cdt.internal.ui.filters.NonCProjectsFilter"
1551
          description="%HideNonCProjects.description"
1552
          id="org.eclipse.cdt.ui.navigator.filters.NonCProjectsFilter"
1553
          name="%HideNonCProjects.label"/>
1554
    <commonFilter
1555
          class="org.eclipse.cdt.internal.ui.filters.NonCElementFilter"
1556
          description="%HideNonCElements.description"
1557
          id="org.eclipse.cdt.ui.navigator.filters.NonCElementFilter"
1558
          name="%HideNonCElements.label"/>
1559
 </extension>
1560
 <extension
1561
       point="org.eclipse.ui.navigator.viewer">
1562
    <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
1563
       <includes>
1564
          <contentExtension pattern="org.eclipse.cdt.ui.navigator.content"/>
1565
          <contentExtension pattern="org.eclipse.cdt.ui.navigator.filters.*"/>
1566
          <contentExtension pattern="org.eclipse.cdt.ui.wizards.*"/>
1567
       </includes>
1568
    </viewerContentBinding>
1569
    <dragAssistant
1570
          class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDragAdapterAssistant"
1571
          viewerId="org.eclipse.ui.navigator.ProjectExplorer"/>
1572
 </extension>
1573
1361
</plugin>
1574
</plugin>
(-)src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java (-4 / +2 lines)
Lines 42-49 Link Here
42
	private FindDeclarationsProjectAction fFindDeclarationsProjectAction;
42
	private FindDeclarationsProjectAction fFindDeclarationsProjectAction;
43
	private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction;
43
	private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction;
44
	
44
	
45
	private ArrayList actions;
46
	
47
	public DeclarationsSearchGroup(IWorkbenchSite site) {
45
	public DeclarationsSearchGroup(IWorkbenchSite site) {
48
		fFindDeclarationsAction= new FindDeclarationsAction(site);
46
		fFindDeclarationsAction= new FindDeclarationsAction(site);
49
		fFindDeclarationsProjectAction = new FindDeclarationsProjectAction(site);
47
		fFindDeclarationsProjectAction = new FindDeclarationsProjectAction(site);
Lines 81-89 Link Here
81
		
79
		
82
		if (fEditor != null){
80
		if (fEditor != null){
83
			menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, declarationsMenu);	
81
			menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, declarationsMenu);	
82
		} else {
83
			incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, declarationsMenu);
84
		}
84
		}
85
		
86
		incomingMenu.add(declarationsMenu);
87
		incomingMenu = declarationsMenu;
85
		incomingMenu = declarationsMenu;
88
		
86
		
89
		FindAction[] actions = getWorkingSetActions();
87
		FindAction[] actions = getWorkingSetActions();
(-)src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java (-5 / +2 lines)
Lines 73-85 Link Here
73
		
73
		
74
		if (fEditor != null){
74
		if (fEditor != null){
75
			menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, refsMenu);	
75
			menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, refsMenu);	
76
		} else {
77
			incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, refsMenu);
76
		}
78
		}
77
		
79
		
78
	
79
//		/setReferenceMenuEnabled();
80
			
81
	
82
		incomingMenu.add(refsMenu);
83
		incomingMenu = refsMenu;
80
		incomingMenu = refsMenu;
84
		
81
		
85
		FindAction[] actions = getWorkingSetActions();
82
		FindAction[] actions = getWorkingSetActions();
(-)src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java (-1 / +1 lines)
Lines 180-186 Link Here
180
			//Can be added once support for manually adding external files to index is established
180
			//Can be added once support for manually adding external files to index is established
181
			/*menu.add(new Separator());
181
			/*menu.add(new Separator());
182
			menu.add(addToIndexAction);*/
182
			menu.add(addToIndexAction);*/
183
			menu.add(new Separator());
183
			menu.add(new Separator(org.eclipse.search.ui.IContextMenuConstants.GROUP_SEARCH));
184
			addSearchMenu(menu, celements);
184
			addSearchMenu(menu, celements);
185
			menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
185
			menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
186
			menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
186
			menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionGroup.java (+147 lines)
Added Link Here
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
 *     Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator
11
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.navigator;
13
14
import java.util.Iterator;
15
16
import org.eclipse.cdt.internal.ui.cview.CViewMessages;
17
import org.eclipse.core.resources.ICommand;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IncrementalProjectBuilder;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.jface.action.GroupMarker;
24
import org.eclipse.jface.action.IMenuManager;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IViewPart;
29
import org.eclipse.ui.actions.BuildAction;
30
import org.eclipse.ui.navigator.ICommonMenuConstants;
31
32
/**
33
 * Common Navigator compatible clone of {@link org.eclipse.cdt.internal.ui.cview.BuildGroup}.
34
 * <p>
35
 * Adds action "Clean Project" and group marker "buildGroup" to the context menu.
36
 * </p>
37
 * @see org.eclipse.cdt.internal.ui.cview.BuildGroup
38
 * @see org.eclipse.ui.actions.BuildAction
39
 */
40
public class CNavigatorBuildActionGroup extends AbstractCNavigatorActionGroup {
41
42
	private BuildAction fCleanAction;
43
44
	// Menu tags for the build
45
	final String BUILD_GROUP_MARKER= "buildGroup"; //$NON-NLS-1$
46
	final String BUILD_GROUP_MARKER_END= "end-buildGroup"; //$NON-NLS-1$
47
48
	/**
49
	 * Create action group associated with given view part.
50
	 * @param viewPart
51
	 */
52
	public CNavigatorBuildActionGroup(IViewPart viewPart) {
53
		super(viewPart);
54
	}
55
56
	public void fillActionBars(IActionBars actionBars) {
57
	}
58
59
	/**
60
	 * Adds the build actions to the context menu.
61
	 * <p>
62
	 * The following conditions apply: build-only projects selected, auto build
63
	 * disabled, at least one * builder present
64
	 * </p>
65
	 * <p>
66
	 * No disabled action should be on the context menu.
67
	 * </p>
68
	 * 
69
	 * @param menu
70
	 *            context menu to add actions to
71
	 */
72
	public void fillContextMenu(IMenuManager menu) {
73
		IStructuredSelection selection= (IStructuredSelection) getContext().getSelection();
74
		boolean isProjectSelection= true;
75
		boolean hasOpenProjects= false;
76
		boolean hasClosedProjects= false;
77
		boolean hasBuilder= true; // false if any project is closed or does
78
		// not have builder
79
80
		Iterator resources= selection.iterator();
81
		while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
82
			Object next= resources.next();
83
			IProject project= null;
84
85
			if (next instanceof IProject) {
86
				project= (IProject) next;
87
			} else if (next instanceof IAdaptable) {
88
				IResource res= (IResource)((IAdaptable)next).getAdapter(IResource.class);
89
				if (res instanceof IProject) {
90
					project= (IProject) res;
91
				}
92
			}
93
94
			if (project == null) {
95
				isProjectSelection= false;
96
				continue;
97
			}
98
			if (project.isOpen()) {
99
				hasOpenProjects= true;
100
				if (hasBuilder && !hasBuilder(project)) {
101
					hasBuilder= false;
102
				}
103
			} else {
104
				hasClosedProjects= true;
105
				hasBuilder= false;
106
			}
107
		}
108
109
		menu.insertAfter(ICommonMenuConstants.GROUP_BUILD, new GroupMarker(BUILD_GROUP_MARKER));
110
111
		if (!selection.isEmpty() && isProjectSelection && hasBuilder) {
112
			fCleanAction.selectionChanged(selection);
113
			if (fCleanAction.isEnabled()) {
114
				menu.appendToGroup(BUILD_GROUP_MARKER, fCleanAction);
115
			}
116
		}
117
		menu.appendToGroup(BUILD_GROUP_MARKER, new GroupMarker(BUILD_GROUP_MARKER_END));
118
	}
119
120
	/**
121
	 * Returns whether there are builders configured on the given project.
122
	 * 
123
	 * @return <code>true</code> if it has builders, <code>false</code> if
124
	 *         not, or if this could not be determined
125
	 */
126
	boolean hasBuilder(IProject project) {
127
		try {
128
			ICommand[] commands= project.getDescription().getBuildSpec();
129
			if (commands.length > 0) return true;
130
		} catch (CoreException e) {
131
			// Cannot determine if project has builders. Project is closed
132
			// or does not exist. Fall through to return false.
133
		}
134
		return false;
135
	}
136
137
	protected void makeActions() {
138
		Shell shell= getViewPart().getSite().getShell();
139
140
		fCleanAction= new BuildAction(shell, IncrementalProjectBuilder.CLEAN_BUILD);
141
		fCleanAction.setText(CViewMessages.getString("CleanAction.label")); //$NON-NLS-1$
142
		
143
	}
144
145
	public void updateActionBars() {
146
	}
147
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionProvider.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.jface.action.IMenuManager;
14
import org.eclipse.ui.IActionBars;
15
import org.eclipse.ui.IViewPart;
16
import org.eclipse.ui.actions.ActionContext;
17
import org.eclipse.ui.navigator.CommonActionProvider;
18
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
19
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
20
21
/**
22
 * A Common Navigator action provider providing the contributions
23
 * from the build action group.
24
 * 
25
 * @see CNavigatorBuildActionGroup
26
 */
27
public class CNavigatorBuildActionProvider extends CommonActionProvider {
28
29
	private CNavigatorBuildActionGroup fBuildGroup;
30
31
	/*
32
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
33
	 */
34
	public void init(ICommonActionExtensionSite site) {
35
		ICommonViewerWorkbenchSite workbenchSite= null;
36
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
37
			workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
38
		}
39
		if (workbenchSite != null) {
40
			if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
41
				IViewPart viewPart= (IViewPart) workbenchSite.getPart();
42
43
				fBuildGroup= new CNavigatorBuildActionGroup(viewPart);
44
			}
45
		}
46
	}
47
48
	/*
49
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
50
	 */
51
	public void dispose() {
52
		if (fBuildGroup != null) {
53
			fBuildGroup.dispose();
54
			fBuildGroup = null;
55
		}
56
		super.dispose();
57
	}
58
59
	/*
60
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
61
	 */
62
	public void fillActionBars(IActionBars actionBars) {
63
		if (fBuildGroup != null) {
64
			fBuildGroup.fillActionBars(actionBars);
65
		}
66
	}
67
68
	/*
69
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
70
	 */
71
	public void fillContextMenu(IMenuManager menu) {
72
		if (fBuildGroup != null) {
73
			fBuildGroup.fillContextMenu(menu);
74
		}
75
	}
76
77
	/*
78
	 * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
79
	 */
80
	public void setContext(ActionContext context) {
81
		super.setContext(context);
82
		if (fBuildGroup != null) {
83
			fBuildGroup.setContext(context);
84
		}
85
	}
86
87
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorSearchActionProvider.java (+98 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
14
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.ui.IActionBars;
17
import org.eclipse.ui.IViewPart;
18
import org.eclipse.ui.actions.ActionContext;
19
import org.eclipse.ui.navigator.CommonActionProvider;
20
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
21
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
22
23
/**
24
 * Common Navigator action provider for the C-search sub menus.
25
 * 
26
 * @see org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup
27
 */
28
public class CNavigatorSearchActionProvider extends CommonActionProvider {
29
30
	private SelectionSearchGroup fSearchGroup;
31
	
32
	/*
33
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
34
	 */
35
	public void init(ICommonActionExtensionSite site) {
36
		ICommonViewerWorkbenchSite workbenchSite= null;
37
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
38
			workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
39
		}
40
		if (workbenchSite != null) {
41
			if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
42
				fSearchGroup= new SelectionSearchGroup(workbenchSite.getSite());
43
			}
44
		}
45
	}
46
47
	/*
48
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
49
	 */
50
	public void dispose() {
51
		if (fSearchGroup != null) {
52
			fSearchGroup.dispose();
53
			fSearchGroup = null;
54
		}
55
		super.dispose();
56
	}
57
58
	/*
59
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
60
	 */
61
	public void fillActionBars(IActionBars actionBars) {
62
		if (fSearchGroup != null) {
63
			fSearchGroup.fillActionBars(actionBars);
64
		}
65
	}
66
67
	/*
68
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
69
	 */
70
	public void fillContextMenu(IMenuManager menu) {
71
		if (fSearchGroup != null) {
72
			ISelection selection = getContext().getSelection();
73
			if (SelectionSearchGroup.canActionBeAdded(selection)){
74
				fSearchGroup.fillContextMenu(menu);
75
			}
76
		}
77
	}
78
79
	/*
80
	 * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
81
	 */
82
	public void setContext(ActionContext context) {
83
		super.setContext(context);
84
		if (fSearchGroup != null) {
85
			fSearchGroup.setContext(context);
86
		}
87
	}
88
89
	/*
90
	 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
91
	 */
92
	public void updateActionBars() {
93
		if (fSearchGroup != null) {
94
			fSearchGroup.updateActionBars();
95
		}
96
	}
97
	
98
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenActionProvider.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.internal.ui.navigator;
13
14
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.ui.IActionBars;
16
import org.eclipse.ui.IViewPart;
17
import org.eclipse.ui.actions.ActionContext;
18
import org.eclipse.ui.navigator.CommonActionProvider;
19
import org.eclipse.ui.navigator.ICommonActionConstants;
20
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
21
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
22
23
/**
24
 * A Common Navigator action provider providing the contributions
25
 * from the open editor action group.
26
 * 
27
 * @see CNavigatorOpenEditorActionGroup
28
 */
29
public class CNavigatorOpenActionProvider extends CommonActionProvider {
30
31
	private CNavigatorOpenEditorActionGroup fOpenGroup;
32
33
	/*
34
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
35
	 */
36
	public void init(ICommonActionExtensionSite site) {
37
		ICommonViewerWorkbenchSite workbenchSite = null;
38
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
39
			workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
40
		}
41
		if (workbenchSite != null) {
42
			if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
43
				IViewPart viewPart = (IViewPart) workbenchSite.getPart();
44
45
				fOpenGroup = new CNavigatorOpenEditorActionGroup(viewPart);
46
			}
47
		}
48
	}
49
50
	/*
51
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
52
	 */
53
	public void dispose() {
54
		if (fOpenGroup != null) {
55
			fOpenGroup.dispose();
56
			fOpenGroup = null;
57
		}
58
		super.dispose();
59
	}
60
61
	/*
62
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
63
	 */
64
	public void fillActionBars(IActionBars actionBars) {
65
		if (fOpenGroup != null) {
66
			fOpenGroup.updateActionBars();
67
			if (fOpenGroup.getOpenAction().isEnabled()) {
68
				actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction());
69
			}
70
		}
71
72
	}
73
74
	/*
75
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
76
	 */
77
	public void fillContextMenu(IMenuManager menu) {
78
		if (fOpenGroup != null) {
79
			if (fOpenGroup.getOpenAction().isEnabled()) {
80
				fOpenGroup.fillContextMenu(menu);
81
			}
82
		}
83
	}
84
85
	/*
86
	 * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
87
	 */
88
	public void setContext(ActionContext context) {
89
		super.setContext(context);
90
		if (fOpenGroup != null) {
91
			fOpenGroup.setContext(context);
92
		}
93
	}
94
95
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionProvider.java (+138 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilter;
14
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.action.Separator;
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
import org.eclipse.jface.util.PropertyChangeEvent;
18
import org.eclipse.jface.viewers.StructuredViewer;
19
import org.eclipse.ui.IActionBars;
20
import org.eclipse.ui.IMemento;
21
import org.eclipse.ui.IViewPart;
22
import org.eclipse.ui.IWorkingSet;
23
import org.eclipse.ui.actions.ActionContext;
24
import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
25
import org.eclipse.ui.navigator.CommonActionProvider;
26
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
27
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
28
29
/**
30
 * A Common Navigator action provider adding standard working set filter support.
31
 * 
32
 * @see CNavigatorWorkingSetActionGroup
33
 * @see org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilter
34
 */
35
public class CNavigatorWorkingSetActionProvider extends CommonActionProvider {
36
37
	private CNavigatorWorkingSetActionGroup fWorkingSetGroup;
38
	private WorkingSetFilter fWorkingSetFilter;
39
	private boolean fContributed;
40
41
	/*
42
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
43
	 */
44
	public void fillActionBars(IActionBars actionBars) {
45
		if(fWorkingSetGroup != null && !fContributed) {
46
			// contribute only once to action bars
47
			fContributed= true;
48
			// add an extra separator before the working set filter actions
49
			// TLETODO [CN] add working set filter actions on top of the menu
50
			actionBars.getMenuManager().add(new Separator());
51
			fWorkingSetGroup.fillActionBars(actionBars);
52
		}
53
	}
54
55
	/*
56
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
57
	 */
58
	public void fillContextMenu(IMenuManager menu) {
59
		if (fWorkingSetGroup != null) {
60
			fWorkingSetGroup.fillContextMenu(menu);
61
		}
62
	}
63
64
	/*
65
	 * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
66
	 */
67
	public void init(ICommonActionExtensionSite site) {
68
		super.init(site);
69
		ICommonViewerWorkbenchSite workbenchSite= null;
70
		if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) {
71
			workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
72
		}
73
		if (workbenchSite != null) {
74
			if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
75
				final StructuredViewer viewer= site.getStructuredViewer();
76
				fWorkingSetFilter= new WorkingSetFilter();
77
				viewer.addFilter(fWorkingSetFilter);
78
				IPropertyChangeListener workingSetUpdater= new IPropertyChangeListener() {
79
					public void propertyChange(PropertyChangeEvent event) {
80
		                String property= event.getProperty();
81
		                if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(property)) {
82
		                    Object newValue= event.getNewValue();
83
		                    if (newValue instanceof IWorkingSet) {
84
		                    	fWorkingSetFilter.setWorkingSet((IWorkingSet) newValue);
85
								viewer.refresh();
86
		                    } else if (newValue == null) {
87
		                    	fWorkingSetFilter.setWorkingSet(null);
88
								viewer.refresh();
89
		                    }
90
		                }
91
					}};
92
				fWorkingSetGroup= new CNavigatorWorkingSetActionGroup(workbenchSite.getShell(), workingSetUpdater);
93
			}
94
		}
95
	}
96
97
	/*
98
	 * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
99
	 */
100
	public void setContext(ActionContext context) {
101
		super.setContext(context);
102
		if (fWorkingSetGroup != null) {
103
			fWorkingSetGroup.setContext(context);
104
		}
105
	}
106
107
	/*
108
	 * @see org.eclipse.ui.navigator.CommonActionProvider#restoreState(org.eclipse.ui.IMemento)
109
	 */
110
	public void restoreState(IMemento memento) {
111
		super.restoreState(memento);
112
		if (fWorkingSetGroup != null && memento != null) {
113
			fWorkingSetGroup.restoreState(memento);
114
		}
115
	}
116
117
	/*
118
	 * @see org.eclipse.ui.navigator.CommonActionProvider#saveState(org.eclipse.ui.IMemento)
119
	 */
120
	public void saveState(IMemento memento) {
121
		super.saveState(memento);
122
		if (fWorkingSetGroup != null && memento != null) {
123
			fWorkingSetGroup.saveState(memento);
124
		}
125
	}
126
127
	/*
128
	 * @see org.eclipse.ui.actions.ActionGroup#dispose()
129
	 */
130
	public void dispose() {
131
		if (fWorkingSetGroup != null) {
132
			fWorkingSetGroup.dispose();
133
			fWorkingSetGroup= null;
134
		}
135
		super.dispose();
136
	}
137
138
}
(-)src/org/eclipse/cdt/internal/ui/navigator/AbstractCNavigatorActionGroup.java (+93 lines)
Added Link Here
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
 *     Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator
11
 *******************************************************************************/
12
package org.eclipse.cdt.internal.ui.navigator;
13
14
import java.net.URL;
15
16
import org.eclipse.cdt.ui.CUIPlugin;
17
import org.eclipse.core.runtime.FileLocator;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.util.Assert;
22
import org.eclipse.ui.IActionBars;
23
import org.eclipse.ui.IViewPart;
24
import org.eclipse.ui.actions.ActionGroup;
25
26
/**
27
 * A basic abstract action group implementation similar to 
28
 * {@link org.eclipse.cdt.internal.ui.cview.CViewActionGroup}, avoiding
29
 * the explicit dependency on {@link org.eclipse.cdt.internal.ui.cview.CView} to
30
 * allow reuse in the Common Navigator.
31
 * 
32
 * @see org.eclipse.cdt.internal.ui.cview.CViewActionGroup
33
 */
34
public abstract class AbstractCNavigatorActionGroup extends ActionGroup {
35
36
	/**
37
	 * The view part this action group is associated with.
38
	 */
39
	private final IViewPart fViewPart;
40
41
	/**
42
	 * Create a new action group associated  with given view part.
43
	 * 
44
	 * @param viewPart
45
	 *            the view part this action group is associated with, may not be
46
	 *            <code>null</code>.
47
	 */
48
	public AbstractCNavigatorActionGroup(IViewPart viewPart) {
49
		Assert.isNotNull(viewPart);
50
		fViewPart = viewPart;
51
		makeActions();
52
	}
53
54
	/**
55
	 * Provide access to the view part this action group has been registered with.
56
	 * 
57
	 * @return the view part
58
	 */
59
	protected IViewPart getViewPart() {
60
		return fViewPart;
61
	}
62
63
	/**
64
	 * Returns the image descriptor with the given relative path.
65
	 */
66
	protected ImageDescriptor getImageDescriptor(String relativePath) {
67
		String iconPath = "/icons/" + relativePath; //$NON-NLS-1$
68
		URL iconURL = FileLocator.find(CUIPlugin.getDefault().getBundle(), new Path(iconPath), null);
69
		// it's safe to pass null
70
		return ImageDescriptor.createFromURL(iconURL);
71
	}
72
73
	/**
74
	 * Makes the actions contained in this action group.
75
	 */
76
	protected abstract void makeActions();
77
	
78
	/*
79
	 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
80
	 */
81
	public abstract void fillContextMenu(IMenuManager menu);
82
83
	/*
84
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
85
	 */
86
	public abstract void fillActionBars(IActionBars actionBars);
87
88
	/*
89
	 * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
90
	 */
91
	public abstract void updateActionBars();
92
93
}
(-)src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java (+72 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.cdt.core.model.ICElement;
14
import org.eclipse.cdt.core.model.ISourceReference;
15
import org.eclipse.cdt.internal.ui.util.EditorUtility;
16
import org.eclipse.cdt.ui.CUIPlugin;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.actions.OpenFileAction;
22
23
/**
24
 * Open an editor and navigate to the source location of
25
 * the currently selected <code>ICElement</code>.
26
 * In case of multiple selections, opening is delegated to
27
 * the base class {@link OpenFileAction}.
28
 */
29
public class OpenCElementAction extends OpenFileAction {
30
31
	private ICElement fOpenElement;
32
	/**
33
	 * @param page
34
	 */
35
	public OpenCElementAction(IWorkbenchPage page) {
36
		super(page);
37
	}
38
39
	/*
40
	 * @see org.eclipse.ui.actions.OpenSystemEditorAction#run()
41
	 */
42
	public void run() {
43
		if (fOpenElement != null) {
44
			IEditorPart part;
45
			try {
46
				part= EditorUtility.openInEditor(fOpenElement);
47
				if (fOpenElement instanceof ISourceReference) {
48
					EditorUtility.revealInEditor(part, (ICElement)fOpenElement);
49
				}
50
			} catch (CoreException exc) {
51
				CUIPlugin.getDefault().log(exc.getStatus());
52
			}
53
		} else {
54
			super.run();
55
		}
56
	}
57
58
	/*
59
	 * @see org.eclipse.ui.actions.OpenSystemEditorAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
60
	 */
61
	protected boolean updateSelection(IStructuredSelection selection) {
62
		fOpenElement = null;
63
		if (selection.size() == 1) {
64
			Object element = selection.getFirstElement();
65
			if (element instanceof ICElement && element instanceof ISourceReference) {
66
				fOpenElement = (ICElement)element;
67
			}
68
		}
69
		return fOpenElement != null || super.updateSelection(selection);
70
	}
71
72
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import java.util.Iterator;
14
15
import org.eclipse.cdt.core.model.ICElement;
16
import org.eclipse.cdt.core.model.ISourceReference;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.swt.dnd.DragSourceEvent;
19
import org.eclipse.swt.dnd.Transfer;
20
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
21
import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
22
23
24
/**
25
 * A Common Navigator drag assistant for <code>ICElement</code>s being also
26
 * <code>ISourceReference</code>s.
27
 * 
28
 * @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter
29
 * @see org.eclipse.cdt.internal.ui.cview.CView#initDrag()
30
 */
31
public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant {
32
33
	/*
34
	 * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
35
	 */
36
	public Transfer[] getSupportedTransferTypes() {
37
		Transfer[] transfers= new Transfer[] {
38
				LocalSelectionTransfer.getInstance()
39
		};
40
		return transfers;
41
	}
42
43
	/*
44
	 * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent, org.eclipse.jface.viewers.IStructuredSelection)
45
	 */
46
	public boolean setDragData(DragSourceEvent event,
47
			IStructuredSelection selection) {
48
		if (selection instanceof IStructuredSelection) {
49
			for (Iterator iter= ((IStructuredSelection)selection).iterator(); iter.hasNext();) {
50
				Object element= iter.next();
51
				if (element instanceof ICElement) {
52
					if (!(element instanceof ISourceReference)) {
53
						return false;
54
					}
55
				}
56
			}
57
			event.data = selection;
58
			return true;
59
		}
60
		return false;
61
	}
62
63
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionGroup.java (+66 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.swt.widgets.Shell;
15
import org.eclipse.ui.IMemento;
16
import org.eclipse.ui.IWorkingSet;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
19
20
/**
21
 * A Common Navigator adapted <code>WorkingSetFilterActionGroup</code> adding persistency.
22
 * 
23
 * @see org.eclipse.ui.actions.WorkingSetFilterActionGroup
24
 * @see org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilterActionGroup
25
 */
26
public class CNavigatorWorkingSetActionGroup extends WorkingSetFilterActionGroup {
27
28
	private static final String TAG_WORKING_SET_NAME= "workingSetName"; //$NON-NLS-1$
29
30
	/**
31
	 * Create a new working set filter action group.
32
	 * @param shell
33
	 * @param workingSetUpdater
34
	 */
35
	public CNavigatorWorkingSetActionGroup(Shell shell, IPropertyChangeListener workingSetUpdater) {
36
		super(shell, workingSetUpdater);
37
	}
38
39
	/**
40
	 * Saves the state of the filter actions in a memento.
41
	 * 
42
	 * @param memento the memento
43
	 */
44
	public void saveState(IMemento memento) {
45
		String workingSetName= ""; //$NON-NLS-1$
46
		IWorkingSet workingSet= getWorkingSet();
47
		if (workingSet != null) {
48
			workingSetName= workingSet.getName();
49
		}
50
		memento.putString(TAG_WORKING_SET_NAME, workingSetName);
51
	}
52
53
	/**
54
	 * Restores the state of the filter actions from a memento.
55
	 * <p>
56
	 * Note: This method does not refresh the viewer.
57
	 * </p>
58
	 * @param memento
59
	 */	
60
	public void restoreState(IMemento memento) {
61
		String workingSetName= memento.getString(TAG_WORKING_SET_NAME);
62
		IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
63
		setWorkingSet(workingSet);
64
	}
65
	
66
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorLabelProvider.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import org.eclipse.cdt.core.model.IArchiveContainer;
14
import org.eclipse.cdt.core.model.IBinary;
15
import org.eclipse.cdt.core.model.IBinaryContainer;
16
import org.eclipse.cdt.core.model.IBinaryModule;
17
import org.eclipse.cdt.core.model.ICElement;
18
import org.eclipse.cdt.core.model.ICProject;
19
import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider;
20
import org.eclipse.cdt.internal.ui.cview.CViewMessages;
21
import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
22
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.ui.IMemento;
25
import org.eclipse.ui.model.IWorkbenchAdapter;
26
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
27
import org.eclipse.ui.navigator.ICommonLabelProvider;
28
29
/**
30
 * A label provider suitable for the Common Navigator providing also
31
 * status message text for the current selected item.
32
 * 
33
 * @see org.eclipse.cdt.internal.ui.cview.CView#getStatusLineMessage()
34
 */
35
public class CNavigatorLabelProvider extends CViewLabelProvider implements ICommonLabelProvider {
36
37
	/**
38
	 * Create a default label provider.
39
	 * 
40
	 * @see org.eclipse.cdt.internal.ui.cview.CView#createLabelProvider()
41
	 */
42
	public CNavigatorLabelProvider() {
43
		super(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS,
44
				AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS
45
						| CElementImageProvider.SMALL_ICONS);
46
	}
47
48
	/*
49
	 * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite)
50
	 */
51
	public void init(ICommonContentExtensionSite extensionSite) {
52
		// no-op
53
	}
54
55
	/*
56
	 * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
57
	 */
58
	public void restoreState(IMemento memento) {
59
		// no-op
60
	}
61
62
	/*
63
	 * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento)
64
	 */
65
	public void saveState(IMemento memento) {
66
		// no-op
67
	}
68
69
	/*
70
	 * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object)
71
	 */
72
	public String getDescription(Object element) {
73
		if (element instanceof IResource) {
74
			return ((IResource) element).getFullPath().makeRelative().toString();
75
		} else if (element instanceof ICElement) {
76
			ICElement celement = (ICElement) element;
77
			IResource res = (IResource) celement.getAdapter(IResource.class);
78
			if (res != null) {
79
				return res.getFullPath().toString();
80
			} else if (celement.getElementType() == ICElement.C_VCONTAINER) {
81
				if (celement instanceof IBinaryContainer) {
82
					ICProject cproj = celement.getCProject();
83
					if (cproj != null) {
84
						return cproj.getPath() + CViewMessages.getString("CView.binaries"); //$NON-NLS-1$
85
					}
86
				} else if (celement instanceof IArchiveContainer) {
87
					ICProject cproj = celement.getCProject();
88
					if (cproj != null) {
89
						return cproj.getPath() + CViewMessages.getString("CView.archives"); //$NON-NLS-1$
90
					}
91
				} else if (celement instanceof IBinaryModule) {
92
					IBinary bin = ((IBinaryModule) celement).getBinary();
93
					return bin.getPath() + ":" + celement.getElementName(); //$NON-NLS-1$
94
				}
95
			} else if (celement.getElementType() > ICElement.C_UNIT) {
96
				return celement.getPath().toString() + " - [" + celement.getElementName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
97
			}
98
			return celement.getElementName();
99
		} else if (element instanceof IWorkbenchAdapter) {
100
			IWorkbenchAdapter wAdapter = (IWorkbenchAdapter)element;
101
			return wAdapter.getLabel(element);
102
		}
103
		return null;
104
	}
105
106
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java (+258 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.cdt.core.model.CModelException;
19
import org.eclipse.cdt.core.model.CoreModel;
20
import org.eclipse.cdt.core.model.ICElement;
21
import org.eclipse.cdt.core.model.ISourceReference;
22
import org.eclipse.cdt.core.model.ITranslationUnit;
23
import org.eclipse.cdt.internal.ui.cview.CViewMessages;
24
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
29
import org.eclipse.jface.operation.IRunnableContext;
30
import org.eclipse.jface.operation.IRunnableWithProgress;
31
import org.eclipse.jface.util.LocalSelectionTransfer;
32
import org.eclipse.jface.viewers.ISelection;
33
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.swt.dnd.DND;
35
import org.eclipse.swt.dnd.DropTargetEvent;
36
import org.eclipse.swt.dnd.TransferData;
37
import org.eclipse.ui.navigator.CommonDropAdapter;
38
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
39
40
/**
41
 * A Common Navigator drop adapter assistant handling dropping of <code>ICElement</code>s.
42
 * 
43
 * @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDropAdapter
44
 * @see org.eclipse.cdt.internal.ui.cview.CView#initDrop()
45
 */
46
public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant {
47
48
	/*
49
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
50
	 */
51
	public IStatus handleDrop(CommonDropAdapter dropAdapter,
52
			DropTargetEvent event, Object target) {
53
		try {
54
			switch(event.detail) {
55
				case DND.DROP_MOVE:
56
					return handleDropMove(target, event);
57
				case DND.DROP_COPY:
58
					return handleDropCopy(target, event);
59
			}
60
		} catch (CModelException e){
61
			ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$
62
			return e.getStatus();
63
		} catch(InvocationTargetException e) {
64
			ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.exception")); //$NON-NLS-1$ //$NON-NLS-2$
65
			return Status.CANCEL_STATUS;
66
		} catch (InterruptedException e) {
67
			//ok
68
		} finally {
69
			// The drag source listener must not perform any operation
70
			// since this drop adapter did the remove of the source even
71
			// if we moved something.
72
			event.detail= DND.DROP_NONE;
73
		}
74
		return Status.CANCEL_STATUS;
75
	}
76
77
	/*
78
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
79
	 */
80
	public IStatus validateDrop(Object target, int operation,
81
			TransferData transferType) {
82
		try {
83
			switch(operation) {
84
				case DND.DROP_DEFAULT:
85
					return handleValidateMove(target); 
86
				case DND.DROP_COPY:
87
					return handleValidateCopy(target);
88
				case DND.DROP_MOVE:
89
					return handleValidateMove(target);
90
			}
91
		} catch (CModelException e){
92
			ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$
93
		}	
94
		return Status.CANCEL_STATUS;
95
	}
96
97
	private IStatus handleValidateCopy(Object target) throws CModelException{
98
		if (target != null) {
99
100
			ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
101
			ICElement[] cElements= getCElements(selection);
102
			
103
			if (!canCopyElements(cElements))
104
				return Status.CANCEL_STATUS;	
105
	
106
			if (target instanceof ISourceReference) {
107
				return Status.OK_STATUS;
108
			}
109
		
110
		}
111
		return Status.CANCEL_STATUS;
112
	}
113
114
	private IStatus handleValidateMove(Object target) throws CModelException {
115
		if (target != null) {
116
117
			ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
118
			ICElement[] cElements= getCElements(selection);
119
			
120
			if (!canMoveElements(cElements))
121
				return Status.CANCEL_STATUS;	
122
	
123
			if (target instanceof ISourceReference) {
124
				return Status.OK_STATUS;
125
			}
126
		
127
		}
128
		return Status.CANCEL_STATUS;
129
	}
130
131
	private IStatus handleDropCopy(final Object target, DropTargetEvent event) throws CModelException, InvocationTargetException, InterruptedException{
132
		ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
133
		final ICElement[] cElements= getCElements(selection);
134
135
		if (target instanceof ICElement) {
136
			ICElement cTarget = (ICElement)target;
137
			ICElement parent = cTarget;
138
			boolean isTargetTranslationUnit = cTarget instanceof ITranslationUnit;
139
			if (!isTargetTranslationUnit) {
140
				parent = cTarget.getParent();
141
			}
142
			final ICElement[] containers = new ICElement[cElements.length];
143
			for (int i = 0; i < containers.length; ++i) {
144
				containers[i] = parent;
145
			}
146
			ICElement[] neighbours = null;
147
			if (!isTargetTranslationUnit) {
148
				neighbours = new ICElement[cElements.length];
149
				for (int i = 0; i < neighbours.length; ++i) {
150
					neighbours[i] = cTarget;
151
				}
152
			}
153
			final ICElement[] siblings = neighbours;
154
			IRunnableWithProgress runnable = new IRunnableWithProgress() {
155
				public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
156
					try {
157
						CoreModel.getDefault().getCModel().copy(cElements, containers, siblings, null, false, monitor);
158
					} catch (CModelException e) {
159
						throw new InvocationTargetException(e);
160
					}
161
				}
162
			};
163
			run(runnable);
164
			return Status.OK_STATUS;
165
		}
166
		return Status.CANCEL_STATUS;
167
	}
168
169
	private IStatus handleDropMove(final Object target, DropTargetEvent event) throws CModelException, InvocationTargetException, InterruptedException{
170
		ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
171
		final ICElement[] cElements= getCElements(selection);
172
		
173
		if (target instanceof ICElement) {
174
			ICElement cTarget = (ICElement)target;
175
			ICElement parent = cTarget;
176
			boolean isTargetTranslationUnit = cTarget instanceof ITranslationUnit;
177
			if (!isTargetTranslationUnit) {
178
				parent = cTarget.getParent();
179
			}
180
			final ICElement[] containers = new ICElement[cElements.length];
181
			for (int i = 0; i < containers.length; ++i) {
182
				containers[i] = parent;
183
			}
184
			ICElement[] neighbours = null;
185
			if (!isTargetTranslationUnit) {
186
				neighbours = new ICElement[cElements.length];
187
				for (int i = 0; i < neighbours.length; ++i) {
188
					neighbours[i] = cTarget;
189
				}
190
			}
191
			final ICElement[] siblings = neighbours;
192
			IRunnableWithProgress runnable = new IRunnableWithProgress() {
193
				public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
194
					try {
195
						CoreModel.getDefault().getCModel().move(cElements, containers, siblings, null, false, monitor);
196
					} catch (CModelException e) {
197
						throw new InvocationTargetException(e);
198
					}
199
				}
200
			};
201
			run(runnable);
202
			return Status.OK_STATUS;
203
		}
204
		return Status.CANCEL_STATUS;
205
	}
206
207
	public void run(IRunnableWithProgress runnable) throws InterruptedException, InvocationTargetException {
208
		IRunnableContext context= new ProgressMonitorDialog(getShell());
209
		context.run(true, true, runnable);
210
	}
211
212
	public static ICElement[] getCElements(ISelection selection) {
213
		if (!(selection instanceof IStructuredSelection)) {
214
			return null;
215
		}
216
		List elements = ((IStructuredSelection)selection).toList();
217
		List resources= new ArrayList(elements.size());
218
		for (Iterator iter= elements.iterator(); iter.hasNext();) {
219
			Object element= iter.next();
220
			if (element instanceof ITranslationUnit) {
221
				continue;
222
			}
223
			if (element instanceof ICElement)
224
				resources.add(element);
225
		}
226
		return (ICElement[]) resources.toArray(new ICElement[resources.size()]);
227
	}
228
229
	private static boolean canCopyElements(ICElement[] cElements) {
230
		if (cElements != null) {
231
			return hasCommonParent(cElements);
232
		}
233
		return false;
234
	}		
235
	
236
	private static boolean canMoveElements(ICElement[] cElements) {
237
		if (cElements != null) {
238
			return hasCommonParent(cElements);
239
		}
240
		return false;
241
	}		
242
	
243
	private static boolean hasCommonParent(ICElement[] elements) {
244
		if (elements.length > 1) {
245
			ICElement parent = elements[0];
246
			for (int i = 0; i < elements.length; ++i) {
247
				ICElement p = elements[i].getParent();
248
				if (parent == null && p!= null) {
249
					return false;
250
				} else if (!parent.equals(p)){
251
					return false;
252
				}
253
			}
254
		}
255
		return true;
256
	}
257
258
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenEditorActionGroup.java (+149 lines)
Added Link Here
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
 *     Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator
11
 *******************************************************************************/
12
13
package org.eclipse.cdt.internal.ui.navigator;
14
15
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
16
import org.eclipse.cdt.internal.ui.cview.CViewMessages;
17
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.jface.action.IAction;
21
import org.eclipse.jface.action.IMenuManager;
22
import org.eclipse.jface.action.MenuManager;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.ui.IActionBars;
25
import org.eclipse.ui.IViewPart;
26
import org.eclipse.ui.actions.OpenFileAction;
27
import org.eclipse.ui.actions.OpenInNewWindowAction;
28
import org.eclipse.ui.actions.OpenWithMenu;
29
import org.eclipse.ui.navigator.ICommonMenuConstants;
30
31
32
/**
33
 * This is basically a clone of {@link org.eclipse.cdt.internal.ui.OpenFileGroup},
34
 * but without explicit dependency on CView. This opens it up for use in the
35
 * Common Navigator framework.
36
 * <p>
37
 * Contributes an "Open" action for the default editor, an "Open With" sub-menu
38
 * for all applicable editors if one or more files are selected.
39
 * For all container selections, an "Open In New Window" action is contributed.
40
 * </p>
41
 * 
42
 * @see org.eclipse.cdt.internal.ui.cview.OpenFileGroup
43
 * @see org.eclipse.ui.actions.OpenFileAction
44
 * @see org.eclipse.ui.actions.OpenWithMenu
45
 * @see org.eclipse.ui.actions.OpenInNewWindowAction
46
 */
47
public class CNavigatorOpenEditorActionGroup extends AbstractCNavigatorActionGroup {
48
49
	/** The open file action. */
50
	private OpenFileAction fOpenFileAction;
51
52
	/**
53
	 * Create an action group for the given view part.
54
	 * 
55
	 * @param viewPart
56
	 */
57
	public CNavigatorOpenEditorActionGroup(IViewPart viewPart) {
58
		super(viewPart);
59
	}
60
61
	protected void makeActions() {
62
		fOpenFileAction= new OpenCElementAction(getViewPart().getSite().getPage());
63
	}
64
65
	public void fillContextMenu(IMenuManager menu) {
66
        IStructuredSelection celements= (IStructuredSelection) getContext().getSelection();
67
		IStructuredSelection selection= SelectionConverter.convertSelectionToResources(celements);
68
69
		fOpenFileAction.selectionChanged(celements);
70
		if (fOpenFileAction.isEnabled()) {
71
			menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, fOpenFileAction);
72
			fillOpenWithMenu(menu, selection);
73
		}
74
75
		addNewWindowAction(menu, selection);
76
	}
77
78
	/**
79
	 * Adds the OpenWith submenu to the context menu.
80
	 * 
81
	 * @param menu
82
	 *            the context menu
83
	 * @param selection
84
	 *            the current selection
85
	 */
86
	private void fillOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
87
		// Only supported if exactly one file is selected.
88
		if (selection.size() != 1) {
89
			return;
90
		}
91
		Object element= selection.getFirstElement();
92
		if (!(element instanceof IFile)) {
93
			return;
94
		}
95
96
		MenuManager submenu= new MenuManager(CViewMessages.getString("OpenWithMenu.label"), ICommonMenuConstants.GROUP_OPEN_WITH); //$NON-NLS-1$
97
		submenu.add(new OpenWithMenu(getViewPart().getSite().getPage(), (IFile) element));
98
		menu.insertAfter(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
99
	}
100
101
	/**
102
	 * Adds the Open in New Window action to the context menu.
103
	 * 
104
	 * @param menu
105
	 *            the context menu
106
	 * @param selection
107
	 *            the current selection
108
	 */
109
	private void addNewWindowAction(IMenuManager menu, IStructuredSelection selection) {
110
111
		// Only supported if exactly one container (i.e open project or folder) is selected.
112
		if (selection.size() != 1) {
113
			return;
114
		}
115
		Object element= selection.getFirstElement();
116
		if (!(element instanceof IContainer)) {
117
			return;
118
		}
119
		if (element instanceof IProject && !(((IProject) element).isOpen())) {
120
			return;
121
		}
122
123
		menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, new OpenInNewWindowAction(getViewPart().getSite().getWorkbenchWindow(), (IContainer) element));
124
	}
125
126
    /*
127
     * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
128
     */
129
    public void fillActionBars(IActionBars actionBars) {
130
    }
131
132
    /*
133
     * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
134
     */
135
    public void updateActionBars() {
136
        IStructuredSelection celements= (IStructuredSelection) getContext().getSelection();
137
		fOpenFileAction.selectionChanged(celements);
138
    }
139
140
	/**
141
	 * Returns the open action managed by this action group. 
142
	 *
143
	 * @return the open action
144
	 */
145
	IAction getOpenAction() {
146
		return fOpenFileAction;
147
	}
148
149
}
(-)src/org/eclipse/cdt/internal/ui/navigator/CNavigatorContentProvider.java (+334 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. 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
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.internal.ui.navigator;
12
13
import java.util.Arrays;
14
import java.util.Iterator;
15
import java.util.LinkedHashSet;
16
import java.util.List;
17
import java.util.Set;
18
19
import org.eclipse.cdt.core.model.CoreModel;
20
import org.eclipse.cdt.core.model.ICElement;
21
import org.eclipse.cdt.core.model.ICModel;
22
import org.eclipse.cdt.internal.ui.cview.CViewContentProvider;
23
import org.eclipse.cdt.ui.CUIPlugin;
24
import org.eclipse.cdt.ui.PreferenceConstants;
25
import org.eclipse.core.resources.IContainer;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.resources.IWorkspaceRoot;
28
import org.eclipse.core.runtime.IAdaptable;
29
import org.eclipse.jface.preference.IPreferenceStore;
30
import org.eclipse.jface.util.IPropertyChangeListener;
31
import org.eclipse.jface.util.PropertyChangeEvent;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.ui.IMemento;
34
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
35
import org.eclipse.ui.navigator.IExtensionStateModel;
36
import org.eclipse.ui.navigator.IPipelinedTreeContentProvider;
37
import org.eclipse.ui.navigator.PipelinedShapeModification;
38
import org.eclipse.ui.navigator.PipelinedViewerUpdate;
39
40
/**
41
 * A content provider populating a Common Navigator view with CDT model content.
42
 */
43
public class CNavigatorContentProvider extends CViewContentProvider implements IPipelinedTreeContentProvider {
44
45
	/** The CN extension state model for persisting viewer options */
46
	private IExtensionStateModel fStateModel;
47
	/** The input object as supplied in the call to {@link #inputChanged()} */
48
	private Object fRealInput;
49
	private IPropertyChangeListener fPropertyChangeListener;
50
51
	/*
52
	 * @see org.eclipse.ui.navigator.ICommonContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite)
53
	 */
54
	public void init(ICommonContentExtensionSite commonContentExtensionSite) {
55
		IExtensionStateModel stateModel= commonContentExtensionSite.getExtensionStateModel();
56
		IMemento memento= commonContentExtensionSite.getMemento();
57
58
		fStateModel= stateModel;
59
		restoreState(memento);
60
		fPropertyChangeListener= new IPropertyChangeListener() {
61
					public void propertyChange(PropertyChangeEvent event) {
62
						boolean refreshViewer= false;
63
						String property= event.getProperty();
64
		
65
						if (property.equals(PreferenceConstants.PREF_SHOW_CU_CHILDREN)) {
66
							boolean showCUChildren= fStateModel.getBooleanProperty(PreferenceConstants.PREF_SHOW_CU_CHILDREN);
67
							setProvideMembers(showCUChildren);
68
							refreshViewer= true;
69
						} else if (property.equals(PreferenceConstants.CVIEW_GROUP_INCLUDES)) {
70
							boolean groupIncludes= fStateModel.getBooleanProperty(PreferenceConstants.CVIEW_GROUP_INCLUDES);
71
							setIncludesGrouping(groupIncludes);
72
							refreshViewer= true;
73
						}
74
		
75
						if (refreshViewer && getViewer() != null) {
76
							getViewer().refresh();
77
						}
78
					}
79
				};
80
		CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
81
		// TLETODO [CN] use extension state model for view options persistence
82
//		fStateModel.addPropertyChangeListener(listener);
83
	}
84
85
	/*
86
	 * @see org.eclipse.cdt.ui.CElementContentProvider#dispose()
87
	 */
88
	public void dispose() {
89
		CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
90
		// TLETODO [CN] use extension state model for view options persistence
91
//		fStateModel.removePropertyChangeListener(fPropertyChangeListener);
92
		super.dispose();
93
	}
94
95
	/*
96
	 * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento)
97
	 */
98
	public void restoreState(IMemento memento) {
99
		IPreferenceStore store= PreferenceConstants.getPreferenceStore();
100
		boolean showCUChildren= store.getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN);
101
		boolean groupIncludes= store.getBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES);
102
		if (memento != null) {
103
			String mementoValue= memento.getString(PreferenceConstants.PREF_SHOW_CU_CHILDREN);
104
			if (mementoValue != null) {
105
				showCUChildren= Boolean.parseBoolean(mementoValue);
106
			}
107
			mementoValue= memento.getString(PreferenceConstants.CVIEW_GROUP_INCLUDES);
108
			if (mementoValue != null) {
109
				groupIncludes= Boolean.parseBoolean(mementoValue);
110
			}
111
		}
112
		setProvideMembers(showCUChildren);
113
		setIncludesGrouping(groupIncludes);
114
		setProvideWorkingCopy(true);
115
	}
116
117
	/*
118
	 * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento)
119
	 */
120
	public void saveState(IMemento memento) {
121
		if (memento != null) {
122
			memento.putString(PreferenceConstants.PREF_SHOW_CU_CHILDREN, String.valueOf(getProvideMembers()));
123
			memento.putString(PreferenceConstants.CVIEW_GROUP_INCLUDES, String.valueOf(areIncludesGroup()));
124
		}
125
	}
126
127
	/*
128
	 * @see org.eclipse.cdt.ui.CElementContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
129
	 */
130
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 
131
		fRealInput= newInput;
132
		super.inputChanged(viewer, oldInput, findInputElement(newInput));
133
	}
134
	
135
	private Object findInputElement(Object newInput) {
136
		if (newInput instanceof IWorkspaceRoot) {
137
			return CoreModel.create((IWorkspaceRoot) newInput);
138
		}
139
		return newInput;
140
	}
141
142
	/*
143
	 * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#getParent(java.lang.Object)
144
	 */
145
	public Object getParent(Object element) {
146
		Object parent= super.getParent(element);
147
		if (parent instanceof ICModel) {
148
			return getViewerInput() != null ? fRealInput : parent;
149
		}
150
		return parent;
151
	}
152
153
	/**
154
	 * Access the viewer input.
155
	 * @return the viewer input
156
	 */
157
	protected Object getViewerInput() {
158
		return fInput;
159
	}
160
161
	/**
162
	 * Access the viewer.
163
	 * @return the viewer
164
	 */
165
	protected Viewer getViewer() {
166
		return fViewer;
167
	}
168
169
	/*
170
	 * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#getElements(java.lang.Object)
171
	 */
172
	public Object[] getElements(Object parent) {
173
		if (parent instanceof IWorkspaceRoot) {
174
			return super.getElements(CoreModel.create((IWorkspaceRoot)parent));
175
		}
176
		return super.getElements(parent);
177
	}
178
179
	/*
180
	 * @see org.eclipse.cdt.internal.ui.cview.CViewContentProvider#getChildren(java.lang.Object)
181
	 */
182
	public Object[] getChildren(Object element) {
183
		Object children[];
184
		if (element instanceof IWorkspaceRoot) {
185
			children =  super.getChildren(CoreModel.create((IWorkspaceRoot)element));
186
		} else {
187
			children = super.getChildren(element);
188
		}
189
		return children;
190
	}
191
192
	/*
193
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set)
194
	 */
195
	public void getPipelinedChildren(Object parent, Set currentChildren) {
196
		Object[] children= getChildren(parent);
197
		for (Iterator iter= currentChildren.iterator(); iter.hasNext();) {
198
			if (iter.next() instanceof IResource) {
199
				iter.remove();
200
			}
201
		}
202
		currentChildren.addAll(Arrays.asList(children));
203
	}
204
205
	/*
206
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedElements(java.lang.Object, java.util.Set)
207
	 */
208
	public void getPipelinedElements(Object input, Set currentElements) {
209
		// only replace plain resource elements with custom elements
210
		// and avoid duplicating elements already customized
211
		// by upstream content providers
212
		Object[] elements= getElements(input);
213
		List elementList= Arrays.asList(elements);
214
		for (Iterator iter= currentElements.iterator(); iter.hasNext();) {
215
			Object element= iter.next();
216
			IResource resource= null;
217
			if (element instanceof IResource) {
218
				resource= (IResource)element;
219
			} else if (element instanceof IAdaptable) {
220
				resource= (IResource)((IAdaptable)element).getAdapter(IResource.class);
221
			}
222
			if (resource != null) {
223
				int i= elementList.indexOf(resource);
224
				if (i >= 0) {
225
					elements[i]= null;
226
				}
227
			}
228
		}
229
		for (int i= 0; i < elements.length; i++) {
230
			Object element= elements[i];
231
			if (element instanceof ICElement) {
232
				ICElement cElement= (ICElement)element;
233
				IResource resource= cElement.getResource();
234
				if (resource != null) {
235
					currentElements.remove(resource);
236
				}
237
				currentElements.add(element);
238
			} else if (element != null) {
239
				currentElements.add(element);
240
			}
241
		}
242
	}
243
244
	/*
245
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedParent(java.lang.Object, java.lang.Object)
246
	 */
247
	public Object getPipelinedParent(Object object, Object suggestedParent) {
248
		return getParent(object);
249
	}
250
251
	/*
252
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification)
253
	 */
254
	public PipelinedShapeModification interceptAdd(PipelinedShapeModification addModification) {
255
		convertToCElements(addModification);
256
		return addModification;
257
	}
258
259
	/*
260
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRefresh(org.eclipse.ui.navigator.PipelinedViewerUpdate)
261
	 */
262
	public boolean interceptRefresh(PipelinedViewerUpdate refreshSynchronization) {
263
		return convertToCElements(refreshSynchronization.getRefreshTargets());
264
	}
265
266
	/*
267
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRemove(org.eclipse.ui.navigator.PipelinedShapeModification)
268
	 */
269
	public PipelinedShapeModification interceptRemove(PipelinedShapeModification removeModification) {
270
		convertToCElements(removeModification.getChildren());
271
		return removeModification;
272
	}
273
274
	/*
275
	 * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptUpdate(org.eclipse.ui.navigator.PipelinedViewerUpdate)
276
	 */
277
	public boolean interceptUpdate(PipelinedViewerUpdate updateSynchronization) {
278
		return convertToCElements(updateSynchronization.getRefreshTargets());
279
	}
280
281
	/**
282
	 * Converts the shape modification to use ICElements.
283
	 * 
284
	 * @param modification
285
	 *            the shape modification to convert
286
	 * @return <code>true</code> if the shape modification set was modified
287
	 */
288
	private boolean convertToCElements(
289
			PipelinedShapeModification modification) {
290
		Object parent= modification.getParent();
291
		if (parent instanceof IContainer) {
292
			ICElement element= CoreModel.getDefault().create((IContainer) parent);
293
			if (element != null && element.exists()) {
294
				// don't convert the root
295
				if( !(element instanceof ICModel)) {
296
					modification.setParent(element);
297
				}
298
				return convertToCElements(modification.getChildren());
299
				
300
			}
301
		}
302
		return false;
303
	}
304
305
	/**
306
	 * Converts the given set to ICElements.
307
	 * 
308
	 * @param currentChildren
309
	 *            The set of current children that would be contributed or 
310
	 *            refreshed in the viewer.
311
	 * @return <code>true</code> if the input set was modified
312
	 */
313
	private boolean convertToCElements(Set currentChildren) {
314
		LinkedHashSet convertedChildren= new LinkedHashSet();
315
		ICElement newChild;
316
		for (Iterator iter= currentChildren.iterator(); iter.hasNext();) {
317
			Object child= iter.next();
318
			if (child instanceof IResource) {
319
				if ((newChild= CoreModel.getDefault().create((IResource) child)) != null
320
						&& newChild.exists()) {
321
					iter.remove();
322
					convertedChildren.add(newChild);
323
				}
324
			}
325
		}
326
		if (!convertedChildren.isEmpty()) {
327
			currentChildren.addAll(convertedChildren);
328
			return true;
329
		}
330
		return false;
331
332
	}
333
334
}

Return to bug 140337