Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8281f8c69eb70be4f090006ff91d77bfd788839a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.breakpoints;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.PlatformUI;

/**
 * Factory to restore breakpoints from mementos for breakpoint working sets.
 */
public class BreakpointFactory implements IElementFactory {

    /* (non-Javadoc)
     * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
     */
    @Override
	public IAdaptable createElement(IMemento memento) {
        String longString = memento.getString(BreakpointPersistableElementAdapter.TAG_MARKER_ID);
        String factoryId = memento.getString(BreakpointPersistableElementAdapter.TAG_RESOURCE_FACTORY_ID);
        if (factoryId != null && longString != null) {
            IElementFactory elementFactory = PlatformUI.getWorkbench().getElementFactory(factoryId);
            if (elementFactory != null) {
                IAdaptable adaptable = elementFactory.createElement(memento);
                if (adaptable instanceof IResource) {
                    IResource resource = (IResource) adaptable;
                    try {
                        long id = Long.parseLong(longString);
                        IMarker marker = resource.findMarker(id);
                        if (marker != null) {
                            return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
                        }
                    } catch (NumberFormatException e) {
                    } catch (CoreException e) {
                    }
                }
            }
        }
        return null;
    }

}

Back to the top