KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > ExternalModelManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.io.File JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16 import java.util.Vector JavaDoc;
17
18 import org.eclipse.core.runtime.Preferences;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20
21 public class ExternalModelManager extends AbstractModelManager {
22     
23     private IPluginModelBase[] fModels = new IPluginModelBase[0];
24     
25     protected IPluginModelBase[] getAllModels() {
26         return fModels;
27     }
28     
29     protected void initializeModels(IPluginModelBase[] models) {
30         fModels = models;
31         Preferences pref = PDECore.getDefault().getPluginPreferences();
32         String JavaDoc saved = pref.getString(ICoreConstants.CHECKED_PLUGINS);
33         if (saved.equals(ICoreConstants.VALUE_SAVED_ALL)) {
34             for (int i = 0; i < fModels.length; i++)
35                 fModels[i].setEnabled(true);
36         } else if (!saved.equals(ICoreConstants.VALUE_SAVED_NONE)) {
37             Vector JavaDoc result = new Vector JavaDoc();
38             StringTokenizer JavaDoc stok = new StringTokenizer JavaDoc(saved);
39             while (stok.hasMoreTokens()) {
40                 result.add(stok.nextToken());
41             }
42             for (int i = 0; i < fModels.length; i++) {
43                 fModels[i].setEnabled(!result.contains(fModels[i].getPluginBase().getId()));
44             }
45         }
46     }
47     
48     public void setModels(IPluginModelBase[] models) {
49         fModels = models;
50     }
51     
52     protected URL JavaDoc[] getPluginPaths() {
53         Preferences pref = PDECore.getDefault().getPluginPreferences();
54         URL JavaDoc[] base = PluginPathFinder.getPluginPaths(pref.getString(ICoreConstants.PLATFORM_PATH));
55
56         String JavaDoc value = pref.getString(ICoreConstants.ADDITIONAL_LOCATIONS);
57         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, ","); //$NON-NLS-1$
58

59         if (tokenizer.countTokens() == 0)
60             return base;
61                 
62         File JavaDoc[] extraLocations = new File JavaDoc[tokenizer.countTokens()];
63         for (int i = 0; i < extraLocations.length; i++) {
64             String JavaDoc location = tokenizer.nextToken();
65             File JavaDoc dir = new File JavaDoc(location, "plugins"); //$NON-NLS-1$
66
if (!dir.exists() || !dir.isDirectory())
67                 dir = new File JavaDoc(location);
68             extraLocations[i] = dir;
69         }
70         URL JavaDoc[] additional = PluginPathFinder.scanLocations(extraLocations);
71         
72         if (additional.length == 0)
73             return base;
74         
75         URL JavaDoc[] result = new URL JavaDoc[base.length + additional.length];
76         System.arraycopy(base, 0, result, 0, base.length);
77         System.arraycopy(additional, 0, result, base.length, additional.length);
78         
79         return result;
80     }
81
82 }
83
Popular Tags