001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.midp.palette;
043:
044: import org.netbeans.modules.vmd.api.model.Debug;
045: import org.netbeans.modules.vmd.api.palette.PaletteProvider;
046: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
047: import org.netbeans.modules.vmd.midp.palette.wizard.AddToPaletteWizardAction;
048: import org.openide.filesystems.FileObject;
049: import org.openide.filesystems.Repository;
050: import org.openide.util.actions.SystemAction;
051: import javax.swing.*;
052: import java.io.IOException;
053: import java.net.URL;
054: import java.util.Collections;
055: import java.util.List;
056:
057: /**
058: *
059: * @author Anton Chechel
060: */
061: public class MidpPaletteProvider implements PaletteProvider {
062:
063: public static final String CATEGORY_COMMANDS = "commands"; // NOI18N
064: public static final String CATEGORY_DISPLAYABLES = "displayables"; // NOI18N
065: public static final String CATEGORY_ELEMENTS = "elements"; // NOI18N
066: public static final String CATEGORY_ITEMS = "items"; // NOI18N
067: public static final String CATEGORY_PROCESS_FLOW = "flow"; // NOI18N
068: public static final String CATEGORY_RESOURCES = "resources"; // NOI18N
069: public static final String CATEGORY_CUSTOM = "custom"; // NOI18N
070: private String[] paletteCategories = { CATEGORY_DISPLAYABLES,
071: CATEGORY_COMMANDS, CATEGORY_ELEMENTS, CATEGORY_ITEMS,
072: CATEGORY_PROCESS_FLOW, CATEGORY_RESOURCES, CATEGORY_CUSTOM };
073: private int[] categoryPositions = { 100, 200, 300, 400, 500, 600,
074: 1000 }; // custom should be the last
075:
076: public MidpPaletteProvider() {
077: }
078:
079: public void initPaletteCategories(String projectType) {
080: if (!MidpDocumentSupport.PROJECT_TYPE_MIDP.equals(projectType)) {
081: return;
082: }
083:
084: try {
085: FileObject paletteFolder = Repository.getDefault()
086: .getDefaultFileSystem().findResource(
087: projectType + "/palette"); // NOI18N
088: if (paletteFolder == null) {
089: FileObject root = Repository.getDefault()
090: .getDefaultFileSystem().getRoot();
091: assert root != null;
092: FileObject projectFolder = root
093: .getFileObject(projectType);
094: if (projectFolder == null) {
095: projectFolder = root.createFolder(projectType);
096: }
097: paletteFolder = projectFolder.createFolder("palette"); // NOI18N
098: }
099: paletteFolder.refresh(true);
100:
101: for (int i = 0; i < paletteCategories.length; i++) {
102: String categoryName = paletteCategories[i];
103: FileObject catFO = paletteFolder
104: .getFileObject(categoryName);
105: if (catFO == null) {
106: catFO = paletteFolder.createFolder(categoryName);
107: }
108: catFO.setAttribute("SystemFileSystem.localizingBundle",
109: "org.netbeans.modules.vmd.midp.palette.Bundle"); // NOI18N
110: catFO.setAttribute("SystemFileSystem.icon", new URL(
111: "nbresloc:/org/netbeans/modules/vmd/midp/resources/components/category_"
112: + categoryName + "_16.png")); // NOI18N
113: catFO.setAttribute("isExpanded", "true"); // NOI18N
114: catFO.setAttribute("position", categoryPositions[i]); // NOI18N
115: }
116: } catch (IOException e) {
117: Debug.warning(
118: "Can't set attributes for palette category folder",
119: e); // NOI18N
120: }
121: }
122:
123: public List<? extends Action> getActions(String projectType) {
124: if (!MidpDocumentSupport.PROJECT_TYPE_MIDP.equals(projectType)) {
125: return null;
126: }
127:
128: return Collections.singletonList(SystemAction
129: .get(AddToPaletteWizardAction.class));
130: }
131: }
|