Skip to main content
summaryrefslogtreecommitdiffstats
blob: e48baec77141cd39911cbd2eb872000793be1915 (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
/*******************************************************************************
 * Copyright (c) 2009, 2019 IBM Corporation and others.
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.editors.palette;


import javax.xml.namespace.QName;

import org.eclipse.jst.pagedesigner.editors.palette.impl.PaletteItemManager;
import org.eclipse.jst.pagedesigner.editors.palette.impl.TaglibPaletteDrawer;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;

/**
 * ITagDropSourceData implementation useable by TagToolPaletteEntry for its 
 * drop transfer object.
 * 
 * @author cbateman
 * 
 */
public final class TagToolCreationAdapter implements ITagDropSourceData
{
    private String _uri;
    private String _tagName;
    private String _defaultPrefix;
    private String _id;

    /**
     * @param uri 
     * @param tagName 
     * @param defaultPrefix 
     * @param id 
     */
    public TagToolCreationAdapter(final String uri,  final String tagName, final String defaultPrefix,
            final String id)
    {
        _uri = uri;
        _tagName = tagName;
        _defaultPrefix = defaultPrefix;
        _id = id;        
    }

    public String getDefaultPrefix()
    {
        return _defaultPrefix;
    }

    public String getTagName()
    {
        return _tagName;
    }

    public String getNamespace()
    {
        return _uri;
    }

    public String getId()
    {
        return _id;
    }

    /**
     * @param provider
     * @param model
     * @return a metadata tag creation adapter for an existing tag
     * creation provider (which need not itself be a TagToolCreationAdapter)
     * and a dom model.
     */
    public static MetadataTagDropSourceData createMdTagCreationProvider(final ITagDropSourceData provider, final IDOMModel model)
    {
        return new MetadataTagDropSourceData(provider, model);
    }

    /**
     * @param container
     * @param paletteContext 
     * @return the tag creation provider
     */
    public static ITagDropSourceData findProviderForContainer(
            final QName container, final IPaletteContext paletteContext)
    {
    	
        return findProviderForContainer(container.getNamespaceURI(), container
                .getLocalPart(), paletteContext);
    }

    /**
     * @param uri
     * @param tagName
     * @param paletteContext
     * @return the tag creation provider
     */
    public static ITagDropSourceData findProviderForContainer(
            final String uri, final String tagName,
            final IPaletteContext paletteContext)
    {
    	final PaletteItemManager itemManager = PaletteItemManager.getInstance(paletteContext);
        if (itemManager != null) {
	    	final TaglibPaletteDrawer category = itemManager.findCategoryByURI(uri);
	        if (category != null)
	        {
	            final TagToolPaletteEntry tagItem = category
	                    .getTagPaletteEntryByTagName(tagName);
	            if (tagItem != null)
	            {
	                return tagItem.getTemplate();
	            }
	        }
        }
        return null;
    }

}

Back to the top