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

eu.agrosense.client.grid.impl.GridDataObject Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2008-2012 AgroSense Foundation.
 *
 * 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 .
 * 
 * Contributors:
 *    monezz - initial API and implementation and/or initial documentation
 */
package eu.agrosense.client.grid.impl;

import eu.agrosense.client.grid.Grid;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.cloudfarming.client.geoviewer.BaseLayer;
import nl.cloudfarming.client.geoviewer.RandomColorPalette;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.MIMEResolver;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.util.lookup.ProxyLookup;

@Messages({
    "LBL_Grid_LOADER=Files of Grid"
})
@MIMEResolver.ExtensionRegistration(
    displayName = "#LBL_Grid_LOADER",
    mimeType = GridDataObject.MIME_TYPE,
    extension = {"grd"})
@DataObject.Registration(
    mimeType = GridDataObject.MIME_TYPE,
    iconBase = GridDataObject.ICON_BASE,
    displayName = "#LBL_Grid_LOADER",
    position = 300)
@ActionReferences({
    @ActionReference(
        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
        id =@ActionID(category = "System", id = "org.openide.actions.OpenAction"),
        position = 100,
        separatorAfter = 200
    )
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
//    position = 300),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
//    position = 400,
//    separatorAfter = 500),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
//    position = 600),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
//    position = 700,
//    separatorAfter = 800),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
//    position = 900,
//    separatorAfter = 1000),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
//    position = 1100,
//    separatorAfter = 1200),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
//    position = 1300),
//    @ActionReference(
//        path = "Loaders/" + GridDataObject.MIME_TYPE + "/Actions",
//    id =
//    @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
//    position = 1400)
})
public class GridDataObject extends MultiDataObject implements PropertyChangeListener {

    public final static String MIME_TYPE = "application/x-agrosense-grid";
    public final static String ICON_BASE = "eu/agrosense/client/grid/impl/grid.png";
    private InstanceContent ic;
    private Lookup intern;
    private GridManagerImpl gridManager;
    private static final Logger LOGGER = Logger.getLogger(GridDataObject.class.getName());
    private final Grid grid;

    public GridDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
        super(pf, loader);
        registerEditor(MIME_TYPE, true);

        LOGGER.log(Level.FINE, "GridDataObject");
        
        this.ic = new InstanceContent();
        this.intern = new AbstractLookup(this.ic);

        gridManager = Lookup.getDefault().lookup(GridManagerImpl.class);
        assert gridManager != null : "No GridManager class found in the default lookup, unable to load the DataObject";

        grid = gridManager.loadGrid(getPrimaryFile());
        assert grid != null;
        LOGGER.log(Level.FINE, "GridDataObject loaded {0}", System.identityHashCode(grid));
        ic.add(grid);

        LOGGER.log(Level.FINE, "Adding new SingleObjectLayer in GridDataObject lookup");
        ic.add(new BaseLayer(new RandomColorPalette(),grid.getName()));
        grid.addPropertyChangeListener(this);
    }

    @Override
    protected Node createNodeDelegate() {
        LOGGER.log(Level.FINE, "Creating new node delegate for GridDataObject");
        return new GridNode(super.createNodeDelegate(), grid);
    }

    
    
    @Override
    protected int associateLookup() {
        return 1;
    }

    @Override
    public final Lookup getLookup() {
        return new ProxyLookup(super.getLookup(), intern);
    }


    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        //TODO implement savable
//        Savable savable =
//                this.getLookup().
//                lookup(Savable.class);
//        if (null == savable) {
//            this.ic.add(new FieldSavable());
//        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy