All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.modules.welcome.ui.ActionBuilder Maven / Gradle / Ivy

There is a newer version: 14.06-beta
Show newest version
/**
 * Copyright (C) 2008-2013 LimeTri. All rights reserved.
 *
 * AgroSense is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
 * this software, see the FLOSS License Exception
 * .
 *
 * AgroSense is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AgroSense.  If not, see .
 */
package org.netbeans.modules.welcome.ui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;

/**
 *
 * @author Merijn Zengers 
 */
public class ActionBuilder {
    
    public List getDataObjects(String actionPath) {
        List returnList = new ArrayList<>();
        FileObject root = FileUtil.getConfigFile(actionPath);
        if (null == root) {
            Logger.getLogger(GetStarted.class.getName()).log(Level.INFO,
                    "Start page content not found: " + "FileObject: {0}", actionPath); //NOI18N
            return null;
        }
        DataFolder folder = DataFolder.findFolder(root);
        if (null == folder) {
            Logger.getLogger(GetStarted.class.getName()).log(Level.INFO,
                    "Start page content not found: " + "DataFolder: {0}", actionPath); //NOI18N
            return null;
        }
        DataObject[] children = folder.getChildren();
        if (null == children) {
            Logger.getLogger(GetStarted.class.getName()).log(Level.INFO,
                    "Start page content not found: " + "DataObject: {0}", actionPath); //NOI18N
            return null;
        }
        for (DataObject dataObject : children) {
            if (dataObject.getPrimaryFile().isFolder()) {
                DataFolder subFolder = DataFolder.findFolder(dataObject.getPrimaryFile());
                DataObject[] subFolderChildren = subFolder.getChildren();
                returnList.addAll(Arrays.asList(subFolderChildren));                
            } else {
                returnList.add(dataObject);
            }
        }
        return returnList;
    }
    
    /**
     * Extract the action from the data object
     * @param dob
     * @return 
     */
    public Action extractAction(DataObject dob) {
        InstanceCookie.Of instCookie = dob.getLookup().lookup(InstanceCookie.Of.class);
        if (null != instCookie && instCookie.instanceOf(Action.class)) {
            try {
                Action res = (Action) instCookie.instanceCreate();
                if (null != res) {
                    res.putValue(Action.NAME, dob.getNodeDelegate().getDisplayName());
                    res.putValue(Action.SHORT_DESCRIPTION, dob.getNodeDelegate().getDisplayName());
                    res.putValue(Action.LONG_DESCRIPTION, dob.getNodeDelegate().getDisplayName());
                    res.putValue(Action.LARGE_ICON_KEY, null);
                    res.putValue(Action.SMALL_ICON, null);
                }
                return res;
            } catch (IOException | ClassNotFoundException e) {
                Logger.getLogger(GetStarted.class.getName()).log(Level.INFO, null, e);
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy