Skip to main content
summaryrefslogtreecommitdiffstats
blob: ceab27f4dfcc3141db53add96f2728a2bbedd0fd (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
/*******************************************************************************
 * Copyright (c) 2009, 2015 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.ua.tests.doc.internal.dialogs;

import java.util.ArrayList;

import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.toc.Toc;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;

public class SelectTocDialog extends Dialog {

	private int[] selectedTocs = {};
	private List tocList;
	private Toc[] tocs;
	private Button existButton, loadButton, followLinksButton;
	public static final int PAGES_EXIST = 1;
	public static final int LOAD_PAGES = 2;
	public static final int FOLLOW_LINKS = 3;
	public static final int NO_SELECTION = 3;
	private int buttonState;

	public SelectTocDialog(Shell parentShell) {
		super(parentShell);
		String locale = Platform.getNL();
		tocs = HelpPlugin.getTocManager().getTocs(locale);
		setShellStyle(getShellStyle() | SWT.RESIZE);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Check Table of Contents");
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		Composite inner = new Composite(parent, SWT.NULL);
		inner.setLayout(new GridLayout());
		inner.setLayoutData(new GridData(GridData.FILL_BOTH));
		Label selectLabel = new Label(inner, SWT.NULL);
		selectLabel.setText("Select a TOC to check");
		tocList = new List(inner, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
		for (Toc toc : tocs) {
			tocList.add(toc.getLabel());
		}
		tocList.setSelection(0);
		GridData tocData = new GridData(GridData.FILL_BOTH);
		tocData.widthHint = 300;
		tocData.heightHint = 300;
		tocList.setLayoutData(tocData);
		existButton = new Button(inner, SWT.RADIO);
		existButton.setText("Check files in TOC exist");
		loadButton = new Button(inner, SWT.RADIO);
		loadButton.setText("Check files in TOC can load including css/images/javascript");
		followLinksButton = new Button(inner, SWT.RADIO);
		followLinksButton.setText("Check files in TOC can load and check hyperlinks");
		existButton.setSelection(true);
		return inner;
	}

	@Override
	protected void okPressed() {
		selectedTocs = tocList.getSelectionIndices();
		if (existButton.getSelection()) {
			buttonState = PAGES_EXIST;
		} else if (loadButton.getSelection()) {
			buttonState = LOAD_PAGES;
		} else if (followLinksButton.getSelection()) {
			buttonState = FOLLOW_LINKS;
		} else {
			buttonState = NO_SELECTION;
		}
		super.okPressed();
	}

	public Toc[] getTocsToCheck() {
		ArrayList<Toc> selected = new ArrayList<Toc>();
		for (int selectedToc : selectedTocs) {
		    selected.add(tocs[selectedToc]);
		}
		Toc[] tocsToCheck = selected.toArray(new Toc[0]) ;
		return tocsToCheck;
	}

	public int getTestKind() {
		return buttonState;
	}

}

Back to the top