Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 50ee7e8b1be0fd958fef6f5fcf17f8aac2778eb9 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*******************************************************************************
 * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.views.outlineview;

import org.eclipse.gef.GraphicalViewer;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.sirius.common.ui.tools.api.util.IObjectActionDelegateWrapper;
import org.eclipse.sirius.common.ui.tools.api.util.SWTUtil;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.internal.editor.DiagramOutlinePage;
import org.eclipse.sirius.diagram.ui.tools.internal.editor.DiagramOutlinePageListener;
import org.eclipse.sirius.diagram.ui.tools.internal.views.providers.filters.FiltersTableViewer;
import org.eclipse.sirius.diagram.ui.tools.internal.views.providers.layers.LayersTableViewer;
import org.eclipse.sirius.diagram.ui.tools.internal.views.providers.outline.OutlineComparator;
import org.eclipse.sirius.diagram.ui.tools.internal.views.providers.outline.OutlineContentProvider;
import org.eclipse.sirius.diagram.ui.tools.internal.views.providers.outline.OutlineLabelProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.part.PageBook;

/**
 * A diagram outline page which has layer page, to hide or show layers, and a
 * filter page to hide or show layers.
 * 
 * @author mchauvin
 */
public class DiagramOutlineWithBookPages extends DiagramOutlinePage {

    /** The id of the layers. 3 */
    protected static final int ID_LAYERS = 3;

    /** The id of the layers. 4 */
    protected static final int ID_FILTERS = 4;

    /** The layers icon descriptor. */
    private static final ImageDescriptor DESC_LAYER = DiagramUIPlugin.Implementation.getBundledImageDescriptor("icons/layers.gif"); //$NON-NLS-1$

    /** The filters icon descriptor. */
    private static final ImageDescriptor DESC_FILTER = DiagramUIPlugin.Implementation.getBundledImageDescriptor("icons/filters.gif"); //$NON-NLS-1$

    /** The show layers action */
    private IAction showLayersAction;

    /** The show layers action */
    private IAction showFiltersAction;

    /** The layers SWT control */
    private Control layers;

    /** The filters SWT control */
    private Control filters;

    /**
     * Constructor.
     * 
     * @param input
     *            the input for the outline tree viewer
     * @param viewer
     *            the graphical viewer the graphical viewer reference
     * @param menuContributions
     *            the popup menu contribution for the outline tree viewer
     */
    public DiagramOutlineWithBookPages(final Object input, final GraphicalViewer viewer, final IObjectActionDelegateWrapper[] menuContributions) {
        super(input, new OutlineLabelProvider(), new OutlineContentProvider(), new OutlineComparator(), viewer, menuContributions);
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.sirius.diagram.tools.internal.editor.DiagramOutlinePage#createControls(org.eclipse.ui.part.PageBook)
     */
    @Override
    protected void createControls(final PageBook pb) {
        super.createControls(pb);
        layers = createLayersControl(pb);
        filters = createFiltersControl(pb);
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.sirius.diagram.tools.internal.editor.DiagramOutlinePage#configureControls(org.eclipse.jface.action.IToolBarManager)
     */
    @Override
    protected void configureControls(final IToolBarManager tbm) {
        super.configureControls(tbm);
        configureLayers(tbm);
        configureFilters(tbm);
    }

    private void configureLayers(final IToolBarManager tbm) {
        showLayersAction = new Action() {
            @Override
            public void run() {
                showPage(ID_LAYERS);
            }
        };
        showLayersAction.setImageDescriptor(DESC_LAYER);
        showLayersAction.setToolTipText(Messages.DiagramOutlineWithBookPages_layersTooltip);
        tbm.add(showLayersAction);
    }

    private void configureFilters(final IToolBarManager tbm) {
        showFiltersAction = new Action() {
            @Override
            public void run() {
                showPage(ID_FILTERS);
            }
        };
        showFiltersAction.setImageDescriptor(DESC_FILTER);
        showFiltersAction.setToolTipText(Messages.DiagramOutlineWithBookPages_filtersTooltip);
        tbm.add(showFiltersAction);
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.sirius.diagram.tools.internal.editor.DiagramOutlinePage#showPage(int)
     */
    @Override
    protected void showPage(final int id) {
        switch (id) {
        case ID_FILTERS:
            super.uncheckProvidedActions();
            showLayersAction.setChecked(false);
            showFiltersAction.setChecked(true);
            super.showPage(filters);
            break;
        case ID_LAYERS:
            super.uncheckProvidedActions();
            showFiltersAction.setChecked(false);
            showLayersAction.setChecked(true);
            super.showPage(layers);
            break;
        default:
            showLayersAction.setChecked(false);
            showFiltersAction.setChecked(false);
            super.showPage(id);
            break;
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.sirius.diagram.tools.internal.editor.DiagramOutlinePage#dispose()
     */
    @Override
    public void dispose() {
        if (contentProvider instanceof DiagramOutlinePageListener) {
            this.removeListener((DiagramOutlinePageListener) contentProvider);
        }
        this.filters.dispose();
        this.layers.dispose();
        super.dispose();
    }

    /**
     * Create the main control for layers.
     * 
     * @param parent
     *            the parent
     * @return the created control.
     */
    protected Control createLayersControl(final Composite parent) {

        final Composite control = SWTUtil.createCompositeBothFill(parent, 1, false);
        LayersTableViewer.createLayersTableViewer(control, this.diagramWorkbenchPart);
        return control;
    }

    /**
     * Create the main control for layers.
     * 
     * @param parent
     *            the parent
     * @return the created control.
     */
    protected Control createFiltersControl(final Composite parent) {

        final Composite control = SWTUtil.createCompositeBothFill(parent, 1, false);
        FiltersTableViewer.createFiltersTableViewer(control, this.diagramWorkbenchPart);
        return control;
    }

}

Back to the top