Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
blob: d6984b3a05a8df27fc5badf12cac5a5fbadc656e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.search.actions;

import java.util.List;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.wst.xsd.ui.internal.search.SearchMessages;

public class ReferencesSearchGroup extends SearchGroup  {
    protected static final String MENU_TEXT= SearchMessages.group_references; 

    protected IEditorPart fEditor;
    private IWorkbenchSite fSite;
    private IActionBars fActionBars;
    
//    private String fGroupId;
    
    protected FindAction fFindReferencesAction;
    protected FindAction fFindReferencesInProjectAction;
    protected FindAction fFindReferencesInWorkingSetAction;


    /**
     * Note: This constructor is for internal use only. Clients should not call this constructor.
     * @param editor
     */
    public ReferencesSearchGroup(IEditorPart editor) {
        Assert.isNotNull(editor);
        fEditor= editor;
        fSite= fEditor.getSite();
        
        initialize();
    }
    
    protected void initialize() {
//      fGroupId= ITextEditorActionConstants.GROUP_FIND;

        fFindReferencesAction= new FindReferencesAction(fEditor);
        fFindReferencesAction.setText(SearchMessages.Search_FindDeclarationAction_label);
        fFindReferencesAction.setActionDefinitionId("SEARCH_REFERENCES_IN_WORKSPACE");
        //fEditor.setAction("SearchReferencesInWorkspace", fFindReferencesAction); //$NON-NLS-1$

        fFindReferencesInProjectAction= new FindReferencesInProjectAction(fEditor);
        fFindReferencesInProjectAction.setText(SearchMessages.Search_FindDeclarationsInProjectAction_label);        
        fFindReferencesInProjectAction.setActionDefinitionId("SEARCH_REFERENCES_IN_PROJECT");
        //fEditor.setAction("SearchReferencesInProject", fFindReferencesInProjectAction); //$NON-NLS-1$
    
        fFindReferencesInWorkingSetAction= new FindReferencesInWorkingSetAction(fEditor);
        fFindReferencesInWorkingSetAction.setText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_label);         
        fFindReferencesInWorkingSetAction.setActionDefinitionId(".SEARCH_REFERENCES_IN_WORKING_SET");
        //fEditor.setAction("SearchReferencesInWorkingSet", fFindReferencesInWorkingSetAction); //$NON-NLS-1$    	
    }

    /*
    private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) {
        action.update(selection);
        provider.addSelectionChangedListener(action);
    }*/

    /**
     * Note: this method is for internal use only. Clients should not call this method.
     * 
     * @return the menu label
     */
    protected String getName() {
        return MENU_TEXT;
    }
    
    public void fillActions(List list)
    {
      list.add(fFindReferencesAction);
      //list.add(fFindReferencesInHierarchyAction);
      list.add(fFindReferencesInProjectAction);
      list.add(new Separator());
      list.add(fFindReferencesInWorkingSetAction);
    }
    
    /* (non-Javadoc)
     * Method declared in ActionGroup
     */
    public void fillActionBars(IActionBars actionBars) {
        Assert.isNotNull(actionBars);
        super.fillActionBars(actionBars);
        fActionBars= actionBars;
        updateGlobalActionHandlers();
    }

    
//    private void addAction(IAction action, IMenuManager manager) {
//        if (action.isEnabled()) {
//            manager.add(action);
//        }
//    }

    /*
    private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) {
        FindAction action;
        if (fEditor != null)
            action= new WorkingSetFindAction(fEditor, new FindReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets));
        else
            action= new WorkingSetFindAction(fSite, new FindReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets));
        action.update(getContext().getSelection());
        addAction(action, manager);
    }
    */
    
    /* (non-Javadoc)
     * Method declared on ActionGroup.
     */
    public void fillContextMenu(IMenuManager manager) {
      /*
        MenuManager javaSearchMM= new MenuManager(getName(), IContextMenuConstants.GROUP_SEARCH);
        addAction(fFindReferencesAction, javaSearchMM);
        addAction(fFindReferencesInProjectAction, javaSearchMM);
        addAction(fFindReferencesInHierarchyAction, javaSearchMM);
        
        javaSearchMM.add(new Separator());
        
        Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator();
        while (iter.hasNext()) {
            addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM);
        }
        addAction(fFindReferencesInWorkingSetAction, javaSearchMM);

        if (!javaSearchMM.isEmpty())
            manager.appendToGroup(fGroupId, javaSearchMM);
        */    
    }
    
    /* 
     * Overrides method declared in ActionGroup
     */
    public void dispose() {
        ISelectionProvider provider= fSite.getSelectionProvider();
        if (provider != null) {
            disposeAction(fFindReferencesAction, provider);
            disposeAction(fFindReferencesInProjectAction, provider);
          //  disposeAction(fFindReferencesInHierarchyAction, provider);
            disposeAction(fFindReferencesInWorkingSetAction, provider);
        }
        fFindReferencesAction= null;
        fFindReferencesInProjectAction= null;
        //fFindReferencesInHierarchyAction= null;
        fFindReferencesInWorkingSetAction= null;
        updateGlobalActionHandlers();
        super.dispose();
    }

    private void updateGlobalActionHandlers() {
        if (fActionBars != null) {
//            fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_WORKSPACE, fFindReferencesAction);
//            fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_PROJECT, fFindReferencesInProjectAction);
//            fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_HIERARCHY, fFindReferencesInHierarchyAction);
//            fActionBars.setGlobalActionHandler(JdtActionConstants.FIND_REFERENCES_IN_WORKING_SET, fFindReferencesInWorkingSetAction);
        }
    }

    private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) {
        if (action != null)
            provider.removeSelectionChangedListener(action);
    }
}

Back to the top