FileDocCategorySizeDatePackage
MultiPageEditor.javaAPI DocExample2958Wed Dec 10 13:18:30 GMT 2003org.eclipsebook.ch12.Ch1201.editors

MultiPageEditor

public class MultiPageEditor extends org.eclipse.ui.part.MultiPageEditorPart

Fields Summary
private org.eclipse.ui.editors.text.TextEditor
editor
private org.eclipse.swt.custom.StyledText
text
Constructors Summary
public MultiPageEditor()

		super();
	
Methods Summary
voidcreatePage0()

		try {
			editor = new TextEditor();
			int index = addPage(editor, getEditorInput());
			setPageText(index, editor.getTitle());
		} catch (PartInitException e) {
			ErrorDialog.openError(
				getSite().getShell(),
				"Error creating nested text editor",
				null,
				e.getStatus());
		}
	
voidcreatePage1()


		Composite composite = new Composite(getContainer(), SWT.NONE);
		FillLayout layout = new FillLayout();
		composite.setLayout(layout);
		text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL);
		text.setEditable(false);

		int index = addPage(composite);
		setPageText(index, "Sorted");
	
protected voidcreatePages()

		createPage0();
		createPage1();
	
public voiddoSave(org.eclipse.core.runtime.IProgressMonitor monitor)

		getEditor(0).doSave(monitor);
	
public voiddoSaveAs()

		IEditorPart editor = getEditor(0);
		editor.doSaveAs();
		setPageText(0, editor.getTitle());
		setInput(editor.getEditorInput());
	
public voidgotoMarker(org.eclipse.core.resources.IMarker marker)

		setActivePage(0);
		getEditor(0).gotoMarker(marker);
	
public voidinit(IEditorSite site, IEditorInput editorInput)

		if (!(editorInput instanceof IFileEditorInput))
			throw new PartInitException("Invalid Input: Must be IFileEditorInput");
		super.init(site, editorInput);
	
public booleanisSaveAsAllowed()

		return true;
	
protected voidpageChange(int newPageIndex)

		super.pageChange(newPageIndex);
		if (newPageIndex == 1) {
			sort();
		}
	
voidsort()

		String unsortedText =
			editor.getDocumentProvider().getDocument(editor.getEditorInput()).get();

		StringTokenizer stringTokenizer =
			new StringTokenizer(unsortedText, " \t\n\r");
		ArrayList wordArrayList = new ArrayList();
		while (stringTokenizer.hasMoreTokens()) {
			wordArrayList.add(stringTokenizer.nextToken());
		}

		Collections.sort(wordArrayList, Collator.getInstance());
		StringWriter sortedText = new StringWriter();
		for (int loopIndex = 0; loopIndex < wordArrayList.size(); loopIndex++) {
			sortedText.write(((String) wordArrayList.get(loopIndex)));
			sortedText.write(System.getProperty("line.separator"));
		}
		
		text.setText(sortedText.toString());