# HG changeset patch # Parent 3ab0c0f660edd47d7883198549992b51d4709e1b diff --git a/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FileTreeElement.java b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FileTreeElement.java new file mode 100644 --- /dev/null +++ b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FileTreeElement.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.refactoring.php.ui.tree; + +import java.beans.BeanInfo; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.refactoring.spi.ui.TreeElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; + +/** + * + * @author Ondrej Brejla + */ +public class FileTreeElement implements TreeElement { + + private final FileObject fileObject; + + FileTreeElement(FileObject fileObject) { + this.fileObject = fileObject; + } + + @Override + public TreeElement getParent(boolean isLogical) { + if (isLogical) { + return TreeElementFactory.getTreeElement(fileObject.getParent()); + } else { + Project project = FileOwnerQuery.getOwner(fileObject); + return TreeElementFactory.getTreeElement(project != null ? project : fileObject.getParent()); + } + } + + @Override + public Icon getIcon() { + Icon result = null; + try { + result = new ImageIcon(DataObject.find(fileObject).getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)); + } catch (DataObjectNotFoundException ex) { + //no-op + } + return result; + } + + @Override + public String getText(boolean isLogical) { + return fileObject.getNameExt(); + } + + @Override + public Object getUserObject() { + return fileObject; + } +} diff --git a/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FolderTreeElement.java b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FolderTreeElement.java new file mode 100644 --- /dev/null +++ b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/FolderTreeElement.java @@ -0,0 +1,97 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.refactoring.php.ui.tree; + +import java.beans.BeanInfo; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.refactoring.spi.ui.TreeElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; + +/** + * + * @author Ondrej Brejla + */ +public class FolderTreeElement implements TreeElement { + + private final FileObject fileObject; + + FolderTreeElement(FileObject fileObject) { + this.fileObject = fileObject; + } + + @Override + public TreeElement getParent(boolean isLogical) { + Project project = FileOwnerQuery.getOwner(fileObject); + if (project != null) { + return TreeElementFactory.getTreeElement(project); + } else { + return null; + } + } + + @Override + public Icon getIcon() { + Icon result = null; + try { + result = new ImageIcon(DataObject.find(fileObject).getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)); + } catch (DataObjectNotFoundException ex) { + //no-op + } + return result; + } + + @Override + public String getText(boolean isLogical) { + return fileObject.getPath(); + } + + @Override + public Object getUserObject() { + return fileObject; + } +} diff --git a/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/ProjectTreeElement.java b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/ProjectTreeElement.java new file mode 100644 --- /dev/null +++ b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/ProjectTreeElement.java @@ -0,0 +1,96 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.refactoring.php.ui.tree; + +import java.lang.ref.WeakReference; +import javax.swing.Icon; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.refactoring.spi.ui.TreeElement; +import org.openide.filesystems.FileObject; + +/** + * + * @author Ondrej Brejla + */ +public class ProjectTreeElement implements TreeElement { + + private final String name; + private final Icon icon; + private final WeakReference projectReference; + private final FileObject projectDirectory; + + public ProjectTreeElement(Project project) { + ProjectInformation projectInformation = ProjectUtils.getInformation(project); + name = projectInformation.getDisplayName(); + icon = projectInformation.getIcon(); + projectReference = new WeakReference(project); + projectDirectory = project.getProjectDirectory(); + } + + @Override + public TreeElement getParent(boolean isLogical) { + return null; + } + + @Override + public Icon getIcon() { + return icon; + } + + @Override + public String getText(boolean isLogical) { + return name; + } + + @Override + public Object getUserObject() { + Project project = projectReference.get(); + if (project == null) { + project = FileOwnerQuery.getOwner(projectDirectory); + } + return project; + } + +} diff --git a/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/RefactoringTreeElement.java b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/RefactoringTreeElement.java new file mode 100644 --- /dev/null +++ b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/RefactoringTreeElement.java @@ -0,0 +1,84 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.refactoring.php.ui.tree; + +import javax.swing.Icon; +import org.netbeans.modules.refactoring.api.RefactoringElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory; +import org.openide.util.Lookup; + +/** + * + * @author Ondrej Brejla + */ +public class RefactoringTreeElement implements TreeElement { + + private RefactoringElement refactoringElement; + private Icon icon; + + RefactoringTreeElement(RefactoringElement element) { + final Lookup lookup = element.getLookup(); + this.refactoringElement = element; + icon = lookup.lookup(Icon.class); + } + + @Override + public TreeElement getParent(boolean isLogical) { + return TreeElementFactory.getTreeElement(refactoringElement.getParentFile()); + } + + @Override + public Icon getIcon() { + return icon; + } + + @Override + public String getText(boolean isLogical) { + return refactoringElement.getDisplayText(); + } + + @Override + public Object getUserObject() { + return refactoringElement; + } +} diff --git a/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/TreeElementFactoryImpl.java b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/TreeElementFactoryImpl.java new file mode 100644 --- /dev/null +++ b/php.refactoring/src/org/netbeans/modules/refactoring/php/ui/tree/TreeElementFactoryImpl.java @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.modules.refactoring.php.ui.tree; + +import java.util.Map; +import java.util.WeakHashMap; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.modules.refactoring.api.RefactoringElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElement; +import org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation; +import org.openide.filesystems.FileObject; + +/** + * + * @author Ondrej Brejla + */ +@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation.class, position=1983) +public class TreeElementFactoryImpl implements TreeElementFactoryImplementation { + + public Map map = new WeakHashMap(); + + @Override + public TreeElement getTreeElement(Object o) { + TreeElement result; + if (o instanceof SourceGroup) { + result = map.get(((SourceGroup)o).getRootFolder()); + } else { + result = map.get(o); + } + if (result == null) { + if (o instanceof FileObject) { + FileObject fo = (FileObject) o; + if (fo.isFolder()) { + result = new FolderTreeElement(fo); + } else { + result = new FileTreeElement(fo); + } + } else if (o instanceof Project) { + result = new ProjectTreeElement((Project) o); + } else if (o instanceof RefactoringElement) { + RefactoringElement refactoringElement = (RefactoringElement) o; + result = new RefactoringTreeElement(refactoringElement); + } + if (result != null) { + if (o instanceof SourceGroup) { + map.put(((SourceGroup)o).getRootFolder(), result); + } else { + map.put(o, result); + } + } + } + return result; + } + + @Override + public void cleanUp() { + map.clear(); + } +}