KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > WelcomeEditorInputFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.internal.ide.dialogs;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.ui.IElementFactory;
15 import org.eclipse.ui.IMemento;
16 import org.eclipse.ui.internal.ide.AboutInfo;
17
18 /**
19  * A simple factory for the welcome editor
20  */

21 public class WelcomeEditorInputFactory implements IElementFactory {
22     /**
23      * WelcomeEditorInputFactory constructor comment.
24      */

25     public WelcomeEditorInputFactory() {
26         super();
27     }
28
29     /**
30      * Re-creates and returns an object from the state captured within the given
31      * memento.
32      * <p>
33      * Under normal circumstances, the resulting object can be expected to be
34      * persistable; that is,
35      * <pre>
36      * result.getAdapter(org.eclipse.ui.IPersistableElement.class)
37      * </pre>
38      * should not return <code>null</code>.
39      * </p>
40      *
41      * @param memento a memento containing the state for the object
42      * @return an object, or <code>null</code> if the element could not be created
43      */

44     public IAdaptable createElement(IMemento memento) {
45         // Get the feature id.
46
String JavaDoc versionedFeatureId = memento
47                 .getString(WelcomeEditorInput.FEATURE_ID);
48         if (versionedFeatureId == null) {
49             return null;
50         }
51         int colonPos = versionedFeatureId.indexOf(':');
52         if (colonPos == -1) {
53             // assume the memento is stale or mangled
54
return null;
55         }
56         String JavaDoc featureId = versionedFeatureId.substring(0, colonPos);
57         String JavaDoc versionId = versionedFeatureId.substring(colonPos + 1);
58         // @issue using feature id for plug-in id
59
AboutInfo info = AboutInfo.readFeatureInfo(featureId, versionId);
60         if (info == null) {
61             return null;
62         }
63         return new WelcomeEditorInput(info);
64     }
65 }
66
Popular Tags