KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.debug.internal.ui.views.breakpoints;
12
13 import org.eclipse.core.resources.IMarker;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.debug.core.DebugPlugin;
18 import org.eclipse.ui.IElementFactory;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.PlatformUI;
21
22 /**
23  * Factory to restore breakpoints from mementos for breakpoint working sets.
24  */

25 public class BreakpointFactory implements IElementFactory {
26
27     /* (non-Javadoc)
28      * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
29      */

30     public IAdaptable createElement(IMemento memento) {
31         String JavaDoc longString = memento.getString(BreakpointPersistableElementAdapter.TAG_MARKER_ID);
32         String JavaDoc factoryId = memento.getString(BreakpointPersistableElementAdapter.TAG_RESOURCE_FACTORY_ID);
33         if (factoryId != null && longString != null) {
34             IElementFactory elementFactory = PlatformUI.getWorkbench().getElementFactory(factoryId);
35             if (elementFactory != null) {
36                 IAdaptable adaptable = elementFactory.createElement(memento);
37                 if (adaptable instanceof IResource) {
38                     IResource resource = (IResource) adaptable;
39                     try {
40                         long id = Long.parseLong(longString);
41                         IMarker marker = resource.findMarker(id);
42                         if (marker != null) {
43                             return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
44                         }
45                     } catch (NumberFormatException JavaDoc e) {
46                     } catch (CoreException e) {
47                     }
48                 }
49             }
50         }
51         return null;
52     }
53
54 }
55
Popular Tags