Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b71fcf5b75f8e3d402515277a9d25b8827a78a65 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright (c) 2012, 2013 Sebastian Schmidt and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Sebastian Schmidt - initial API and implementation
 *     IBM Corporation - bug fixing
 *******************************************************************************/
package org.eclipse.debug.internal.ui.importexport.breakpoints;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.core.BreakpointManager;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer;
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsViewer;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.actions.ImportBreakpointsOperation;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;

/**
 * @since 3.8
 * @noextend This class is not intended to be subclassed by clients.
 */
public class WizardImportBreakpointsSelectionPage extends WizardPage {

	private EmbeddedBreakpointsViewer fTView;
	private boolean fIsVisible;

	protected WizardImportBreakpointsSelectionPage(String pageName) {
		super(pageName, ImportExportMessages.WizardImportBreakpointsSelectionPage_2, null);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		setDescription(ImportExportMessages.WizardImportBreakpointsSelectionPage_1);
		Composite composite = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH);
		SWTFactory.createLabel(composite, ImportExportMessages.WizardExportBreakpointsPage_2, 1);
		BreakpointManager breakpointManager = new BreakpointManager();
		fTView = new EmbeddedBreakpointsViewer(composite, breakpointManager, null);
		BreakpointsViewer viewer = fTView.getViewer();
		viewer.setLabelProvider(new DecoratingLabelProvider((ILabelProvider) viewer.getLabelProvider(), new BreakpointsPathDecorator()));
		setControl(composite);
	}

	public List<IMarker> getSelectedMarkers() {
		if(!fIsVisible) {
			return null;
		}
		List<IMarker> markers = new ArrayList<>();
		List<IBreakpoint> breakpoints = fTView.getCheckedElements().toList();
		for(int i = 0; i < breakpoints.size(); i++) {
			markers.add(breakpoints.get(i).getMarker());
		}
		return markers;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
	 */
	@Override
	public void setVisible(boolean visible) {
		if (visible) {
			fIsVisible = true;
			try {
				updateBreakpointsPreviewList(fTView);
			} catch (Exception e) {
				setErrorMessage(e.getMessage());
			}
		} else {
			fIsVisible = false;
		}

		super.setVisible(visible);
	}

	private void updateBreakpointsPreviewList(final EmbeddedBreakpointsViewer currentTView) throws InvocationTargetException, InterruptedException {
		getContainer().run(false, true, new IRunnableWithProgress() {
			@Override
			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
				WizardImportBreakpointsPage mainPage = (WizardImportBreakpointsPage) getWizard().getPage(
						ImportExportMessages.WizardImportBreakpoints_0);
				ImportBreakpointsOperation operation = new ImportBreakpointsOperation(mainPage.getFileNameField().getText()
						.trim(), mainPage.getAutoRemoveDuplicates(), false, false);
				operation.run(monitor);
				BreakpointContainer breakpointManager = new BreakpointContainer(null, null);
				IBreakpoint[] importedBreakpoints = operation.getImportedBreakpoints();
				for(int i = 0; i < importedBreakpoints.length; i++) {
					breakpointManager.addBreakpoint(importedBreakpoints[i], new ModelDelta(null, IModelDelta.ADDED));
				}
				currentTView.getViewer().setInput(breakpointManager);
				currentTView.getViewer().refresh();
			}
		});
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
	 */
	@Override
	public Image getImage() {
		return DebugUITools.getImage(IInternalDebugUIConstants.IMG_WIZBAN_IMPORT_BREAKPOINTS);
	}
}

Back to the top