1 /* 2 * Created on Jan 19, 2004 3 * 4 * Copyright (C) 2004 Sean Ruff 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 package org.un4gvn.editorviewer.internal; 21 22 import java.net.URL; 23 24 import org.eclipse.core.runtime.IPluginDescriptor; 25 import org.eclipse.core.runtime.Path; 26 import org.eclipse.jface.resource.ImageDescriptor; 27 import org.eclipse.swt.graphics.Image; 28 import org.eclipse.ui.IEditorReference; 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.IWorkbenchPage; 31 import org.eclipse.ui.IWorkbenchWindow; 32 import org.eclipse.ui.plugin.AbstractUIPlugin; 33 34 /*** 35 * AbstractUIPlugin subclass to provide common functionality 36 * <p> 37 * @author Sean Ruff 38 */ 39 public class EditorViewerPlugin extends AbstractUIPlugin { 40 41 /*** 42 * Singleton instance 43 */ 44 private static EditorViewerPlugin helper = null; 45 46 /*** 47 * Plugin ID 48 */ 49 public static final String PLUGIN_ID = Messages.getString("EditorViewerPlugin.0"); //$NON-NLS-1$ 50 51 52 //////////////////////////////////////////////////////////////// 53 ////////////// HIERARCHY MODE ///////////////////// 54 //////////////////////////////////////////////////////////////// 55 /*** 56 * Structured Mode - Mimic the Structure found in the Navigator 57 */ 58 public static final int HIERARCHICAL_MODE = 0; 59 60 /*** 61 * Every Editor will be in a sub-folder of a single parent folder 62 * made up up the full path to all parent folders 63 */ 64 public static final int SEMI_FLAT_MODE = 1; 65 66 /*** 67 * Completely Flat with all files at the root level 68 */ 69 public static final int FLAT_MODE = 2; 70 71 /*** 72 * Every editor will be placed into a folder by it's Extension (Type) 73 */ 74 public static final int TYPE_MODE = 3; 75 76 77 //////////////////////////////////////////////////////////////// 78 ////////////// SORT MODE ///////////////////// 79 //////////////////////////////////////////////////////////////// 80 81 /*** 82 * Indicates no sorting will take place 83 */ 84 public static final int NONE_SORT_MODE = 0; 85 86 /*** 87 * Indicates the sort should be performed by Name 88 */ 89 public static final int NAME_SORT_MODE = 1; 90 91 /*** 92 * Indicates the sort should be performed by type, then name 93 */ 94 public static final int TYPE_SORT_MODE = 2; 95 96 97 //////////////////////////////////////////////////////////////// 98 ////////////// LINK MODE ///////////////////// 99 //////////////////////////////////////////////////////////////// 100 101 /*** 102 * Inidcates the selection in the view is linked to the active editor 103 */ 104 public static final int LINKED_MODE = 0; 105 106 /*** 107 * Inidcates the selection in the view is NOT linked to the active editor 108 */ 109 public static final int NON_LINKED_MODE = 1; 110 111 112 /*** 113 * Initialize the Plugin 114 * @param desc 115 */ 116 public EditorViewerPlugin(IPluginDescriptor desc){ 117 super(desc); 118 helper = this; 119 } 120 121 /*** 122 * Retreive the singleton instance 123 * @return 124 */ 125 public static EditorViewerPlugin getInstance(){ 126 return helper; 127 } 128 129 /*** 130 * Retreive the Active window from the Workbench 131 * @return 132 */ 133 public IWorkbenchWindow getActiveWindow(){ 134 return getWorkbench().getActiveWorkbenchWindow(); 135 } 136 137 /*** 138 * Get a list of currently open editors 139 * @return IEditorReference[] 140 */ 141 public IEditorReference[] getOpenEditors(){ 142 IWorkbench bench = getWorkbench(); 143 if ( bench == null ) 144 return new IEditorReference[]{}; 145 IWorkbenchWindow window = bench.getActiveWorkbenchWindow(); 146 if ( window == null ) 147 return new IEditorReference[]{}; 148 IWorkbenchPage page = window.getActivePage(); 149 if ( page == null ) 150 return new IEditorReference[]{}; 151 IEditorReference[] editors = page.getEditorReferences(); 152 return ( editors == null ) ? new IEditorReference[]{} : editors; 153 } 154 155 /*** 156 * Get a shared image descriptor from the workbench SharedImages 157 * @param id String id of the image descriptor to return 158 * @return ImageDescriptor 159 */ 160 private ImageDescriptor getSharedImageDescriptor(String id){ 161 return getWorkbench().getSharedImages().getImageDescriptor(id); 162 } 163 164 /*** 165 * Get a ImageDescriptor for an image via a path 166 * @param path Path to the image to retreive the description for 167 * @return 168 */ 169 private ImageDescriptor getLocalImageDescriptor(String path){ 170 URL url = this.getDescriptor().find(new Path(path)); 171 if ( url == null ) 172 return null; 173 return ImageDescriptor.createFromURL(url); 174 } 175 176 public ImageDescriptor getImageDescriptor(String key){ 177 ImageDescriptor desc = this.getImageRegistry().getDescriptor(key); 178 if ( desc != null ) 179 return desc; 180 desc = getLocalImageDescriptor(key); 181 if ( desc != null ){ 182 this.getImageRegistry().put(key,desc); 183 return desc; 184 } 185 desc = getSharedImageDescriptor(key); 186 if ( desc != null ){ 187 this.getImageRegistry().put(key,desc); 188 return desc; 189 } 190 return null; 191 } 192 193 public Image getImage(String key){ 194 Image img = this.getImageRegistry().get(key); 195 if ( img != null ) 196 return img; 197 ImageDescriptor desc = getImageDescriptor(key); 198 if ( desc == null ) 199 return null; 200 return this.getImageRegistry().get(key); 201 202 } 203 204 205 206 }

This page was automatically generated by Maven