Skip to main content
summaryrefslogtreecommitdiffstats
blob: fa3272fe9ad5becd7dbd27304fdac5ff0d7895e2 (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
/*******************************************************************************
 * 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.tests.tagcreator;

import org.eclipse.jst.jsf.common.dom.TagIdentifier;
import org.eclipse.jst.pagedesigner.editors.palette.ITagDropSourceData;
import org.eclipse.jst.pagedesigner.editors.palette.TagToolCreationAdapter;
import org.eclipse.jst.pagedesigner.editors.palette.TagToolPaletteEntry;
import org.eclipse.jst.pagedesigner.editors.palette.impl.PaletteItemManager;
import org.eclipse.jst.pagedesigner.editors.palette.impl.TaglibPaletteDrawer;
import org.eclipse.jst.pagedesigner.itemcreation.ITagCreator;
import org.eclipse.jst.pagedesigner.itemcreation.internal.UserCustomizedTagCreator;
import org.eclipse.jst.pagedesigner.tests.tagcreator.base.BaseTagCreatorTestCase;
import org.eclipse.jst.pagedesigner.tests.tagcreatorPlugin.UserCustomizedElementEditFactory;

/**
 * Base test case for a UserCustomizedTagCreator.
 * 
 * @author Debajit Adhikary
 *
 */
public class BaseUserCustomizedTagCreatorTestCase extends BaseTagCreatorTestCase 
{
    /** Label for mock category to be added to the JSF tools palette (for testing only) */
	private static final String CATEGORY_LABEL = "Category label (for testing only)";

    /** Label for mock tag to be added to the JSF tools palette (for testing only) */
	private static final String TAG_LABEL = "User Customized Tag";
	
	/** Label for description for mock tag added to the JSF tools palette (for testing only) */
	private static final String TAG_DESCRIPTION_SHORT = "User Customized Tag (for testing only)";


	public BaseUserCustomizedTagCreatorTestCase() 
	{
		 super("h", "jsf");
	}

	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	
	@Override
	protected void initializePaletteItemManager(PaletteItemManager pim) {
		
		// Setup mock (user-customized) tags.
		// In the current implementation, this requires setting up a tool palette
		// category, and adding the tag(s) to the tool palette. Only then can the
		// tag be inserted.
		
		final TaglibPaletteDrawer category = pim
			.findOrCreateCategory(UserCustomizedElementEditFactory.TAGCREATOR_URI_1, CATEGORY_LABEL);
		assertNotNull(category);
		addItemsToCategory(category);
		
	}


	private void addItemsToCategory(TaglibPaletteDrawer category) {
		if (category.getChildren().size() == 0) {
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG1, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG2, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG3, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG4, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG5, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG6, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG7, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG8, category);
			addTagToPaletteCategory(UserCustomizedElementEditFactory.TAG9, category);
		}
	}

	@Override
	protected ITagCreator getTagCreator(TagIdentifier tagId) 
	{
		return new UserCustomizedTagCreator();
	}


    /**
     * Adds a tag to a section in the tool palette.
     * 
     * @param tagId
     *            TagIdentifier of tag to add
     * @param category
     *            Category in the tool palette
     * 
     */
    @SuppressWarnings("unchecked")
    private final void addTagToPaletteCategory(final TagIdentifier tagId,
            final TaglibPaletteDrawer category)
    {
        final ITagDropSourceData tagDropSourceData = new TagToolCreationAdapter(
                tagId.getUri(), tagId.getTagName(),
                category.getDefaultPrefix(), tagId.getTagName());
        final TagToolPaletteEntry paletteItem = new TagToolPaletteEntry(
                tagDropSourceData, TAG_LABEL, TAG_DESCRIPTION_SHORT, null, null);
        category.getChildren().add(paletteItem);
        paletteItem.setParent(category);
    }
}

Back to the top