Changeset 1306

Show
Ignore:
Timestamp:
11/13/07 19:43:05 (1 year ago)
Author:
nozawa
Message:

#208 Fixed bug.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.jalcedo.templates/trunk/org.jalcedo.templates.editor.ui/src/org/jalcedo/templates/editor/ui/internal/MasterViewAndDetailEditorWizard.java

    r1294 r1306  
    3636import org.eclipse.pde.core.plugin.IPluginImport; 
    3737import org.eclipse.pde.core.plugin.IPluginModelBase; 
    38 import org.eclipse.pde.core.plugin.IPluginModelFactory; 
    3938import org.eclipse.pde.core.plugin.IPluginObject; 
     39import org.eclipse.pde.core.plugin.IPluginParent; 
    4040import org.eclipse.pde.ui.IExtensionWizard; 
    4141import org.eclipse.ui.IWorkbenchWindow; 
     
    148148        this.addExtention(pluginModelBase, viewExtension); 
    149149 
    150         IPluginElement perspectiveElement = findPluginElement(pluginModelBase, 
    151                 "org.eclipse.ui.perspectives"); 
     150        IPluginElement perspectiveElement = findPluginExtensionElement( 
     151                pluginModelBase, "org.eclipse.ui.perspectives"); 
    152152        if (perspectiveElement != null) { 
    153153            IPluginExtension perspectiveExtension = createPerspectiveExtension( 
     
    194194    } 
    195195 
    196     private IPluginElement findPluginElement(IPluginModelBase pluginModelBase, 
    197             String extensionPoint) { 
     196    private IPluginElement findPluginExtensionElement( 
     197            IPluginModelBase pluginModelBase, String extensionPoint) { 
    198198 
    199199        IPluginBase plugin = pluginModelBase.getPluginBase(); 
     
    243243                pluginModelBase, "org.eclipse.ui.perspectiveExtensions", true); 
    244244 
    245         IPluginModelFactory factory = pluginModelBase.getPluginFactory(); 
    246  
    247         IPluginElement peElement = factory.createElement(perspectiveExtension); 
    248         peElement.setName("perspectiveExtension"); 
    249         peElement.setAttribute("targetID", perspectiveElement 
    250                 .getAttribute("id").getValue()); 
    251         perspectiveExtension.add(peElement); 
    252  
    253         IPluginElement viewElement = factory.createElement(peElement); 
    254  
    255         viewElement.setName("view"); 
    256         viewElement.setAttribute("id", viewModel.getPackageName() + "." 
    257                 + viewModel.getClassName()); 
     245        String perspectiveID = perspectiveElement.getAttribute("id").getValue(); 
     246 
     247        IPluginElement peElement = createPluginElement(perspectiveExtension, 
     248                "perspectiveExtension", "targetID", perspectiveID); 
     249 
     250        String viewID = viewModel.getPackageName() + "." 
     251                + viewModel.getClassName(); 
     252 
     253        IPluginElement viewElement = createPluginElement(peElement, "view", 
     254                "id", viewID); 
    258255        viewElement.setAttribute("ratio", "0.5"); 
    259256        viewElement.setAttribute("relationship", "left"); 
    260257        viewElement.setAttribute("relative", "org.eclipse.ui.editorss"); 
    261         peElement.add(viewElement); 
     258 
    262259        return perspectiveExtension; 
    263260    } 
     
    274271            GeneratableClassModel viewModel, IPluginModelBase pluginModelBase) 
    275272            throws CoreException { 
     273 
    276274        IPluginExtension extension = createExtension(pluginModelBase, 
    277275                "org.eclipse.ui.views", true); 
    278         IPluginModelFactory factory = pluginModelBase.getPluginFactory(); 
    279  
    280         IPluginElement viewElement = factory.createElement(extension); 
    281276 
    282277        String modelFQDN = viewModel.getPackageName() + "." 
    283278                + viewModel.getClassName(); 
    284279 
    285         viewElement.setName("view"); 
    286         viewElement.setAttribute("id", modelFQDN); 
     280        IPluginElement viewElement = createPluginElement(extension, "view", 
     281                "id", modelFQDN); 
     282 
    287283        viewElement.setAttribute("name", viewModel.getClassName()); 
    288284        viewElement.setAttribute("class", modelFQDN); 
    289         extension.add(viewElement); 
    290285        return extension; 
     286    } 
     287 
     288    private IPluginElement createPluginElement(IPluginParent parent, 
     289            String elementName, String idAttributeName, String idValue) 
     290            throws CoreException { 
     291        IPluginObject[] children = parent.getChildren(); 
     292        for (IPluginObject pluginObject : children) { 
     293            if (pluginObject instanceof IPluginElement) { 
     294                IPluginElement element = (IPluginElement) pluginObject; 
     295                if (element.getName().equals(elementName) 
     296                        && element.getAttribute(idAttributeName).getValue() 
     297                                .equals(idValue)) { 
     298                    return element; 
     299                } 
     300            } 
     301        } 
     302        IPluginElement pluginElement = pluginModelBase.getPluginFactory() 
     303                .createElement(parent); 
     304        pluginElement.setName(elementName); 
     305        pluginElement.setAttribute(idAttributeName, idValue); 
     306        parent.add(pluginElement); 
     307        return pluginElement; 
    291308    } 
    292309 
     
    304321        IPluginExtension extension = createExtension(pluginModelBase, 
    305322                "org.eclipse.ui.editors", true); 
    306         IPluginModelFactory factory = pluginModelBase.getPluginFactory(); 
    307  
    308         IPluginElement editorElement = factory.createElement(extension); 
    309323 
    310324        String modelFQDN = editorModel.getPackageName() + "." 
    311325                + editorModel.getClassName(); 
    312326 
    313         editorElement.setName("editor"); 
    314         editorElement.setAttribute("id", modelFQDN); 
     327        IPluginElement editorElement = createPluginElement(extension, "editor", 
     328                "id", modelFQDN); 
     329 
    315330        editorElement.setAttribute("name", editorModel.getClassName()); 
    316331        editorElement.setAttribute("class", modelFQDN); 
    317332        editorElement.setAttribute("icon", EDITOR_ICON_PATH); 
    318         extension.add(editorElement); 
    319333        return extension; 
    320334    }