Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9a146b44275110f66313d1856a71520e499373b4 (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
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle 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:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.ui.internal.component;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jst.jsf.common.ui.JSFUICommonPlugin;
import org.eclipse.jst.jsf.common.ui.internal.utils.JSFSharedImages;
import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ResolverUtil;
import org.eclipse.jst.jsf.designtime.DesignTimeApplicationManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.IPage;
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.PageBookView;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;

/**
 * A basic page-based view, similar to outline, that shows the design-time
 * component tree for a JSF view definition.
 */

public class ComponentTreeView extends PageBookView
{

    private FormToolkit _toolkit;

    @Override
    public void init(IViewSite site) throws PartInitException
    {
        super.init(site);
        setTitleImage(JSFUICommonPlugin.getDefault().getImage(JSFSharedImages.GENERIC_VIEWROOT_IMG));
    }

    @Override
    protected IPage createDefaultPage(final PageBook book)
    {
        final MessagePage page = new MessagePage();
        initPage(page);
        page.createControl(book);
        page.setMessage(Messages.ComponentTreeView_NothingToDisplayMessage);
        return page;
    }

    @Override
    protected PageRec doCreatePage(final IWorkbenchPart part)
    {
        _toolkit = new FormToolkit(getPageBook().getDisplay());
        final ComponentPage page = new ComponentPage(getDocumentFromPart(part),
                _toolkit);
        initPage(page);
        page.createControl(getPageBook());
        return new PageRec(part, page);
    }

    @Override
    protected void doDestroyPage(final IWorkbenchPart part,
            final PageRec pageRecord)
    {
        pageRecord.page.dispose();
        pageRecord.dispose();
    }

    private IDocument getDocumentFromPart(final IWorkbenchPart part)
    {
        return (IDocument) part.getAdapter(IDocument.class);
    }

    /**
     * The view shows the palette associated with the active editor.
     * 
     * @see PageBookView#getBootstrapPart()
     */
    @Override
    protected IWorkbenchPart getBootstrapPart()
    {
        final IWorkbenchPage page = getSite().getPage();
        if (page != null)
        {
            return page.getActiveEditor();
        }
        return null;
    }

    @Override
    protected boolean isImportant(final IWorkbenchPart part)
    {
        final IDocument document = getDocumentFromPart(part);

        if (document != null)
        {
            final IFile file = ResolverUtil.getFileForDocument(document);

            if (file != null)
            {
                final DesignTimeApplicationManager manager = DesignTimeApplicationManager
                .getInstance(file.getProject());

                if (manager != null)
                {
                    return manager.hasDTFacesContext(file);
                }
            }
        }

        // fall through, then no, not important.
        return false;
    }

    private static class ComponentPage extends Page
    {
        private final IDocument            _document;
        private final FormToolkit          _toolkit;
        private ComponentMasterDetailBlock _masterDetailBlock;
        private Form                       _form;
        private DTJSFViewModel             _model;

        public ComponentPage(final IDocument document, final FormToolkit toolkit)
        {
            _document = document;
            _toolkit = toolkit;
        }

        @Override
        public void createControl(final Composite parent)
        {
            _model = new DTJSFViewModel(
                    (IStructuredDocument) _document);

            _form = _toolkit.createForm(parent);
            _form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            _masterDetailBlock = new ComponentMasterDetailBlock(_model);
            _masterDetailBlock.createContent(_toolkit, _form);
        }

        @Override
        public void dispose()
        {
            super.dispose();
            _model.dispose();
        }

        @Override
        public Control getControl()
        {
            return _form;
        }

        @Override
        public void setFocus()
        {
            // do nothing
        }
        
        
    }
}

Back to the top