Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b19b4cfa279cfdddaafe26f640137b4920e9880e (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
/*******************************************************************************
 *  Copyright (c) 2000, 2008 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.pde.internal.ui.tests.macro;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchWindow;

public class RecordBlock implements IRecorderListener {
	private IWorkbenchWindow window;
	private static RecordBlock instance;

	private RecordBlock() {
	}

	public static RecordBlock getInstance() {
		if (instance == null) {
			instance = new RecordBlock();
		}
		return instance;
	}

	public static void init(IWorkbenchWindow window) {
		if (instance == null) {
			getInstance().internalInit(window);
		}
	}

	private void internalInit(IWorkbenchWindow window) {
		this.window = window;
		MacroManager recorder = MacroPlugin.getDefault().getMacroManager();
		recorder.addRecorderListener(this);
	}

	public static void dispose() {
		if (instance != null) {
			instance.internalDispose();
			instance = null;
		}
	}

	private void internalDispose() {
		MacroManager recorder = MacroPlugin.getDefault().getMacroManager();
		recorder.removeRecorderListener(this);
	}

	public void startRecording() {
		MacroManager recorder = MacroPlugin.getDefault().getMacroManager();
		recorder.startRecording();
	}

	public void stopRecording() {
		MacroManager recorder = MacroPlugin.getDefault().getMacroManager();
		Macro macro = recorder.stopRecording();
		StringWriter swriter = new StringWriter();
		PrintWriter pwriter = new PrintWriter(swriter);
		macro.write("", pwriter);
		pwriter.close();
		try {
			swriter.close();
		} catch (IOException e) {
			System.out.println(e);
		}
		String contents = swriter.toString();
		NewMacroWizard wizard = new NewMacroWizard(contents);
		WizardDialog wd = new WizardDialog(window.getShell(), wizard);
		wd.setMinimumPageSize(500, 500);
		wd.open();
	}

	public void recordingStarted() {
	}

	public void recordingStopped() {
	}

	public void recordingInterrupted(int interruptType) {
		if (interruptType == STOP)
			stopRecording();
		else if (interruptType == INDEX)
			insertIndex();
	}

	public void insertIndex() {
		MacroManager recorder = MacroPlugin.getDefault().getMacroManager();
		IndexWizard wizard = new IndexWizard(recorder);
		WizardDialog wd = new WizardDialog(window.getShell(), wizard);
		//wd.setMinimumPageSize(300, 400);
		wd.create();
		wd.getShell().setData(MacroManager.IGNORE, Boolean.TRUE);
		wd.getShell().setSize(300, 400);
		wd.open();
	}
}

Back to the top