Ignore:
Timestamp:
12/06/11 21:40:11 (13 years ago)
Author:
masberg
Message:

Fix so that the hide protected variables button in the outline view actually filters. Remember all filter settings. Add missing override annotations. Avoid unnecessary casts. Formatting fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/view/ModelicaContentOutlinePage.java

    r1104 r1182  
    2525package org.modelica.mdt.ui.view;
    2626
     27import java.util.ArrayList;
    2728import java.util.Collection;
    2829import java.util.Hashtable;
     
    9091import org.modelica.mdt.ui.ModelicaElementChangeListener;
    9192
    92 public class ModelicaContentOutlinePage extends ContentOutlinePage
    93 {
     93public class ModelicaContentOutlinePage extends ContentOutlinePage {
    9494    static Object[] NO_CHILDREN= new Object[0];
     95    static IPreferenceStore prefStore = UIPlugin.getDefault().getPreferenceStore();
    9596
    9697    ModelicaEditor fEditor = null; 
     
    110111
    111112    private CompositeActionGroup fActionGroups;
    112    
     113
    113114    private IPreferenceStore fCorePreferenceStore = CorePlugin.getDefault().getPreferenceStore();
    114115
     
    168169        }
    169170
     171        @Override
    170172        public Object[] getChildren(Object parent) {
     173            // TODO: Use a better name for this property and don't hard-code it here. Use modern-style enum.
     174            String filterProtectedProperty = "MemberFilterActionGroup.org.modelica.mdt.ui.ModelicaContentOutlinePage.1";
     175            boolean shouldFilterProtected = false;
     176
     177            if (prefStore.contains(filterProtectedProperty)) {
     178                shouldFilterProtected = prefStore.getBoolean(filterProtectedProperty);
     179            }
     180            else {
     181                // We are not storing a preference for this filter, so we disable it, i.e., no filtering.
     182            }
     183
     184            Object[] result = NO_CHILDREN;
     185
    171186            if (parent instanceof IParent) {
    172                 IParent c= (IParent) parent;
    173                 try
    174                 {
    175                     Collection<? extends IModelicaElement> z = c.getChildren();
    176                     IModelicaElement[] arr = new IModelicaElement[z.size()];
    177                     int i = 0;
    178                     for (IModelicaElement el : z)
    179                     {
    180                         arr[i++] = el;
     187                try {
     188                    Collection<? extends IModelicaElement> children = ((IParent)parent).getChildren();
     189                    List<IModelicaElement> filteredChildren = new ArrayList<IModelicaElement>();
     190                    for (IModelicaElement el : children) {
     191                        if (shouldFilterProtected && el.getVisibility() == IModelicaElement.Visibility.PROTECTED) {
     192                            // Filter out this protected item.
     193                        }
     194                        else {
     195                            filteredChildren.add(el);
     196                        }
    181197                    }
    182                     return arr; //filter(arr);
     198
     199                    result = filteredChildren.toArray();
    183200                }
    184                 catch (Exception x)
    185                 {
     201                catch (Exception x) {
    186202                    x.printStackTrace();
    187203                }
    188204            }
    189             return NO_CHILDREN;
    190         }
    191 
     205
     206            return result;
     207        }
     208
     209        @Override
    192210        public Object[] getElements(Object parent) {
    193211            return getChildren(parent);
    194212        }
    195213
     214        @Override
    196215        public Object getParent(Object child) {
    197216            if (child instanceof IModelicaElement) {
     
    202221        }
    203222
     223        @Override
    204224        public boolean hasChildren(Object parent) {
    205225            if (parent instanceof IParent) {
     
    221241        }
    222242
     243        @Override
    223244        public void dispose()
    224245        {
     
    231252         * @see IContentProvider#inputChanged(Viewer, Object, Object)
    232253         */
     254        @Override
    233255        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    234256            boolean isMO= (newInput instanceof IModelicaFile);
     
    296318         * @see TreeViewer#internalExpandToLevel
    297319         */
     320        @Override
    298321        protected void internalExpandToLevel(Widget node, int level) {
    299322            if (node instanceof Item) {
     
    348371         * @see org.eclipse.jface.viewers.AbstractTreeViewer#isExpandable(java.lang.Object)
    349372         */
     373        @Override
    350374        public boolean isExpandable(Object element) {
    351375            if (hasFilters()) {
     
    416440        }
    417441
     442        @Override
    418443        public void run() {
    419444            valueChanged(isChecked(), true);
     
    423448            setChecked(on);
    424449            BusyIndicator.showWhile(fOutlineViewer.getControl().getDisplay(), new Runnable() {
     450                @Override
    425451                public void run() {
    426452                    if (on)
     
    430456                }
    431457            });
    432            
     458
    433459            if (store) fCorePreferenceStore.setValue("ModeilcaEditor.Outline.LexicalSortingAction.isChecked", on); //$NON-NLS-1$
    434            
     460
    435461        }
    436462    }
     
    461487         * Runs the action.
    462488         */
     489        @Override
    463490        public void run()
    464491        {
     
    498525        fEditor= editor;
    499526        fPropertyChangeListener= new IPropertyChangeListener() {
     527            @Override
    500528            public void propertyChange(PropertyChangeEvent event) {
    501529                doPropertyChange(event);
     
    508536        if (fOutlineViewer != null) {
    509537            // TODO! FIXME! update only if is a sort action! if (event.getProperty() ) {
    510                 fOutlineViewer.refresh(false);
     538            fOutlineViewer.refresh(false);
    511539            //}
    512540        }
    513541    }
    514    
     542
    515543    /* (non-Modelicadoc)
    516544     * Method declared on Page
    517545     */
     546    @Override
    518547    public void init(IPageSite pageSite) {
    519548        super.init(pageSite);
     
    523552     * @see ISelectionProvider#addSelectionChangedListener(ISelectionChangedListener)
    524553     */
     554    @Override
    525555    public void addSelectionChangedListener(ISelectionChangedListener listener) {
    526556        if (fOutlineViewer != null)
     
    533563     * @see ISelectionProvider#removeSelectionChangedListener(ISelectionChangedListener)
    534564     */
     565    @Override
    535566    public void removeSelectionChangedListener(ISelectionChangedListener listener) {
    536567        if (fOutlineViewer != null)
     
    543574     * @see ISelectionProvider#setSelection(ISelection)
    544575     */
     576    @Override
    545577    public void setSelection(ISelection selection) {
    546578        if (fOutlineViewer != null)
     
    551583     * @see ISelectionProvider#getSelection()
    552584     */
     585    @Override
    553586    public ISelection getSelection() {
    554587        if (fOutlineViewer == null)
     
    596629     * @see IPage#createControl
    597630     */
     631    @Override
    598632    public void createControl(Composite parent) {
    599633
     
    604638        // use a non decorating label provider for outline!
    605639        // fOutlineViewer.setLabelProvider(new DecoratingLabelProvider(
    606         //        new WorkbenchLabelProvider(), UIPlugin.getDefault().getWorkbench()
    607         //        .getDecoratorManager().getLabelDecorator()));
     640        //        new WorkbenchLabelProvider(), UIPlugin.getDefault().getWorkbench()
     641        //        .getDecoratorManager().getLabelDecorator()));
    608642        fOutlineViewer.setLabelProvider(new WorkbenchLabelProvider());
    609643
     
    623657        manager.setRemoveAllWhenShown(true);
    624658        manager.addMenuListener(new IMenuListener() {
     659            @Override
    625660            public void menuAboutToShow(IMenuManager m) {
    626661                contextMenuAboutToShow(m);
     
    635670        updateSelectionProvider(site);
    636671
    637 //      we must create the groups after we have set the selection provider to the site
     672        //      we must create the groups after we have set the selection provider to the site
    638673        fActionGroups= new CompositeActionGroup(new ActionGroup[] {});
    639674
    640 //      register global actions
     675        //      register global actions
    641676        IActionBars actionBars= site.getActionBars();
    642677        actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, fEditor.getAction(ITextEditorActionConstants.UNDO));
     
    652687        fActionGroups.fillActionBars(actionBars);
    653688
    654 //      Custom filter group
     689        //      Custom filter group
    655690        fCustomFiltersActionGroup= new CustomFiltersActionGroup("org.modelica.mdt.ui.ModelicaContentOutlinePage", fOutlineViewer); //$NON-NLS-1$
    656691
     
    671706    }
    672707
     708    @Override
    673709    public void dispose() {
    674710
     
    708744    }
    709745
     746    @Override
    710747    public Control getControl() {
    711748        if (fOutlineViewer != null)
     
    739776    public IAction getAction(String actionID) {
    740777        Assert.isNotNull(actionID);
    741         return (IAction) fActions.get(actionID);
     778        return fActions.get(actionID);
    742779    }
    743780
     
    751788        if (key == IModelicaElement.class) {
    752789            return new IShowInTargetList() {
     790                @Override
    753791                public String[] getShowInTargetIds() {
    754792                    return new String[] { UIPlugin.ID_PROJECTSVIEW };
     
    800838     * @see Page#setFocus()
    801839     */
     840    @Override
    802841    public void setFocus() {
    803842        if (fOutlineViewer != null)
     
    817856            if (element != null && element instanceof IModelicaClass)
    818857                if(((IModelicaClass)element).getRestriction() == IModelicaClass.Restriction.TYPE ||
    819                    ((IModelicaClass)element).getRestriction() == IModelicaClass.Restriction.UNIONTYPE)
    820                        return true;
     858                ((IModelicaClass)element).getRestriction() == IModelicaClass.Restriction.UNIONTYPE)
     859                    return true;
    821860        }
    822861        catch (Exception e) {
     
    833872    protected IShowInSource getShowInSource() {
    834873        return new IShowInSource() {
     874            @Override
    835875            public ShowInContext getShowInContext() {
    836876                return new ShowInContext(null, getSite().getSelectionProvider().getSelection());
     
    846886    protected IShowInTarget getShowInTarget() {
    847887        return new IShowInTarget() {
     888            @Override
    848889            public boolean show(ShowInContext context) {
    849890                ISelection sel= context.getSelection();
     
    864905        };
    865906    }
    866    
    867    
     907
     908
    868909    protected void handleOpen(OpenEvent event)
    869910    {
     
    887928        }
    888929    }
    889    
     930
    890931
    891932}
Note: See TracChangeset for help on using the changeset viewer.