Skip to main content
summaryrefslogtreecommitdiffstats
blob: f04b3b15adda043a4a5864174fbb7fa01cb316fc (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
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.editors.actions;

import org.eclipse.gef.EditDomain;
import org.eclipse.gef.ui.views.palette.PaletteView;
import org.w3c.dom.Element;

/**
 * @author mengbo
 * @version 1.5
 */
public class PaletteViewAction extends ShowViewAction {
	public final static String ID = "org.eclipse.jst.pagedesigner.editors.actions.PaletteViewAction"; //$NON-NLS-1$
	// TODO: dead?
	//private final Element   _element;
    //private final EditDomain _editDomain;
    
	public PaletteViewAction(Element element, EditDomain editDomain) {
        super(ActionsMessages.getString("PaletteViewAction.Menu.PaletteView")
                , PaletteView.ID); //$NON-NLS-1$
        //_element = element;
        //_editDomain = editDomain;
	}
    
    /** 
     * Add to default behavior because pallete view doesn't automatically track
     * selection to currently selected edit part
     */
    public void run()
    {
        super.run();
        
        //TODO: for some reason getting a palette item to select doesn't work
//        if (_element != null && _editDomain != null)
//        {
//            PaletteItemManager manager = PaletteItemManager
//                                          .getInstance(getProject(_element));
//            if (manager != null) {
//                IPaletteItemCategory category = manager.findOrCreateCategory(CMUtil
//                        .getElementNamespaceURI(_element), null);
//                
//              if (category != null) {
//                  String name = _element.getLocalName();
//                  if (category.getURI().equals(IJMTConstants.URI_JSP)) {
//                      name = _element.getTagName();
//                  }
//                  IPaletteItemDescriptor descriptor = category
//                      .getItemByTagName(name);
//                  if (descriptor != null)
//                  {
//                      PaletteEntry paletteEntry = descriptor.getPaletteEntry();
//                      final RootEditPart editPart = 
//                          _editDomain.getPaletteViewer().getRootEditPart();
//                      EditPart newSelection = findMatchingPart(editPart.getContents(), paletteEntry);
//
//                      if (newSelection != null)
//                      {
//                          _editDomain.getPaletteViewer().setSelection(new StructuredSelection(newSelection));
//                      }
//                   }
//                }
//            }
//        }
    }
    
//    private EditPart findMatchingPart(EditPart curPart, PaletteEntry paletteEntry)
//    {
//        EditPart match = null;
//
//        if (curPart.getModel() == paletteEntry)
//        {
//            return curPart;
//        }
//        
//        for (final Iterator it = curPart.getChildren().iterator(); it.hasNext();)
//        {
//            match = findMatchingPart((EditPart)it.next(), paletteEntry);
//            
//            if (match != null)
//            {
//                break;
//            }
//        }
//        
//        return match;
//    }
//    private IProject getProject(Element element) {
//        if (element instanceof IDOMElement) {
//            IDOMModel model = ((IDOMElement) element).getModel();
//            IFile file = StructuredModelUtil.getFileFor(model);
//            if (file != null) {
//                return file.getProject();
//            }
//        }
//        return null;
//    }
}

Back to the top