alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is Forte for Java, Community Edition. The Initial
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.mdrxml.looks;

import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import javax.jmi.reflect.*;
import javax.jmi.model.*;
import org.openide.util.NbBundle;
import org.netbeans.api.looks.*;
import org.netbeans.spi.looks.*;
import org.netbeans.api.mdr.*;
import xmlmodel.XmlmodelPackage;
import xmlmodel.RootNodeClass;
import xmlmodel.RootNode;
import org.netbeans.modules.mdrxml.util.XMLModelEventTranslator;
import org.netbeans.modules.mdrxml.util.NodeEventTranslator;
/**
 *
 * @author  Tomas Zezula
 */
public class DocumentsLook extends DefaultLook {
    
    private static final String ICON = "org/netbeans/modules/mdrxml/resources/packageproxy";
    
    /** Creates a new instance of DocumentsLook */
    public DocumentsLook() {
        super (NbBundle.getMessage (DocumentsLook.class, "TXT_DocumentsLook"));
    }
    
    public Object attachTo (Look.NodeSubstitute substitute) {
        super.attachTo (substitute);
        XMLModelEventTranslator translator = XMLModelEventTranslator.addXMLPackage(substitute);
        return new NodeEventTranslator (translator,(RefBaseObject)substitute.getRepresentedObject(),substitute);
    }
    
    public String getName (Look.NodeSubstitute substitute) {
        RefPackage pkg = (RefPackage) substitute.getRepresentedObject ();
        MDRepository repo = ((MDRObject)pkg).repository();
        String[] names = repo.getExtentNames ();
        for (int i=0; i< names.length; i++) {
            if (repo.getExtent (names[i]).equals (pkg))
                return names[i];
        }
        return ((MofPackage)pkg.refMetaObject()).getName();
    }
    
    public String getDisplayName (Look.NodeSubstitute substitute) {
        return this.getName (substitute);
    }
    
    public String iconBase (Look.NodeSubstitute substitute) {
        return ICON;
    }
    
    public Object[] getChildObjects (Look.NodeSubstitute substitute) {
        XmlmodelPackage pkg = (XmlmodelPackage) substitute.getRepresentedObject ();
        MDRepository repo = ((MDRObject)pkg).repository ();
        repo.beginTrans (false);
        try {
            RootNodeClass rnClass = pkg.getRootNode ();
            Collection rootNodes = rnClass.refAllOfClass ();
            Object[] result = new Object [rootNodes.size()];
            Iterator it = rootNodes.iterator ();
            for (int i=0; it.hasNext(); i++) {
                result[i] = it.next();
            }
            return result;
        }finally {
            repo.endTrans ();
        }
    }
    
    public Transferable clipboardCopy (Look.NodeSubstitute substitute) throws IOException {
        return new StringSelection (this.getName(substitute));
    }
    
    public boolean canCopy (Look.NodeSubstitute substitute) {
        return true;
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.