Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: faeb61c3b5ff17cfb57f18f8ddd580f0d7ab6af6 (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
/*******************************************************************************
 * Copyright (c) 2018 Remain Software
 * 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:
 *     wim.jongman@remainsoftware.com - initial API and implementation
 *******************************************************************************/
package org.eclipse.tips.examples.swttip;

import java.util.Date;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tips.core.Tip;
import org.eclipse.tips.examples.DateUtil;
import org.eclipse.tips.ui.ISwtTip;

public class SwtTipImpl extends Tip implements ISwtTip {

	private final class Beeper extends SelectionAdapter {
		@Override
		public void widgetSelected(SelectionEvent e) {
			e.widget.getDisplay().beep();
			if (((Button) e.widget).getText().contains("2")) {
				try {
					Thread.sleep(600);
				} catch (InterruptedException e1) {
				}
				e.widget.getDisplay().beep();
			}
		}
	}

	private String fSubject;

	public SwtTipImpl(String providerId, int  number) {
		super(providerId);
		fSubject = "This is a tip " + number;
	}

	@Override
	public Date getCreationDate() {
		return DateUtil.getDateFromYYMMDD("10/01/2018");
	}

	@Override
	public String getSubject() {
		return fSubject;
	}

	@Override
	public void createControl(Composite pParent) {
		pParent.setLayout(new GridLayout(2, false));
		Group group = new Group(pParent, SWT.NONE);
		GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).grab(true, true).applyTo(group);
		group.setLayout(new FillLayout());
		group.setText(fSubject);
		Text text = new Text(group, SWT.MULTI | SWT.WRAP);
		text.setText(fSubject + System.lineSeparator() + System.lineSeparator()
				+ "There are thousands of these tips. Just press next tip and you will see.");
		Button button1 = new Button(pParent, SWT.PUSH);
		button1.setText("Beep once");
		button1.addSelectionListener(new Beeper());
		GridDataFactory.fillDefaults().applyTo(button1);
		Button button2 = new Button(pParent, SWT.PUSH);
		button2.setText("Beep 2 times");
		button2.addSelectionListener(new Beeper());
		GridDataFactory.fillDefaults().applyTo(button2);
	}
}

Back to the top