KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > universal > contentdetect > ContentDetector


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.internal.intro.universal.contentdetect;
13
14 import java.util.HashSet JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.core.runtime.IExtension;
18 import org.eclipse.core.runtime.Platform;
19 import org.eclipse.ui.intro.IntroContentDetector;
20
21 public class ContentDetector extends IntroContentDetector {
22
23     private static Set JavaDoc newContributors;
24     private static boolean detectorCalled = false;
25     
26     public ContentDetector() {
27     }
28
29     public boolean isNewContentAvailable() {
30         try {
31             detectorCalled = true;
32             // If we have previously found new content no need to recompute
33
if (newContributors != null && !newContributors.isEmpty()) {
34                 return true;
35             }
36             IExtension[] extensions = Platform
37                     .getExtensionRegistry()
38                     .getExtensionPoint("org.eclipse.ui.intro.configExtension").getExtensions(); //$NON-NLS-1$
39
int numIntroExtensions = extensions.length;
40       
41             ContentDetectHelper helper = new ContentDetectHelper();
42             int previous = helper.getExtensionCount();
43             if (numIntroExtensions != previous) {
44                 helper.saveExtensionCount(numIntroExtensions);
45                 Set JavaDoc contributors = new HashSet JavaDoc();
46                 for (int i = 0; i < extensions.length; i++) {
47                     contributors.add(extensions[i].getContributor().getName());
48                 }
49                 if (numIntroExtensions > previous && previous != ContentDetectHelper.NO_STATE) {
50                     Set JavaDoc previousContributors = helper.getContributors();
51                     newContributors = helper.findNewContributors(contributors, previousContributors);
52                     helper.saveContributors(contributors);
53                     return true;
54                 }
55                 helper.saveContributors(contributors);
56             }
57         } catch (Exception JavaDoc e) {
58             return false;
59         }
60         newContributors = new HashSet JavaDoc();
61         return false;
62     }
63     
64     /**
65      * @return The set of the ids of config extensions which are new since the last time
66      * intro was opened. May be null if there are no contributors.
67      */

68     public static Set JavaDoc getNewContributors() {
69         if (!detectorCalled) {
70             detectorCalled = true;
71             new ContentDetector().isNewContentAvailable();
72         }
73         return newContributors;
74     }
75     
76     /**
77      * Test to see if this contribution was newly installed
78      * @param contributionId
79      * @return
80      */

81     public static boolean isNew(String JavaDoc contributionId) {
82         if (!detectorCalled) {
83             detectorCalled = true;
84             new ContentDetector().isNewContentAvailable();
85         }
86         return newContributors != null && newContributors.contains(contributionId);
87     }
88
89 }
90
Popular Tags