01: package net.xoetrope.builder.editor.helper;
02:
03: import java.util.ArrayList;
04:
05: import java.awt.event.KeyEvent;
06: import javax.swing.text.BadLocationException;
07:
08: import net.xoetrope.builder.editor.XEditorProject;
09: import net.xoetrope.builder.editor.XPageResource;
10: import net.xoetrope.builder.editor.XSourceEditor;
11: import net.xoetrope.builder.editor.dialog.XPageSelectionDialog;
12: import net.xoetrope.xui.XPage;
13:
14: /**
15: * <p>Title: Xui</p>
16: * <p>Description: </p>
17: * <p>Copyright: Copyright (c) Xoeotrope Ltd., 1998-2003</p>
18: * <p>Company: Xoetrope Ltd.</p>
19: * @author not attributable
20: * @version 1.0
21: */
22:
23: public class NavCodeHelper extends CodeHelper {
24: private static NavCodeHelper instance = new NavCodeHelper();
25:
26: private NavCodeHelper() {
27: }
28:
29: public static void register(ArrayList resources) {
30: if ((resources != null) && (!resources.contains(instance)))
31: resources.add(instance);
32: }
33:
34: /**
35: * Insert the new member reference, imports and initialization code
36: */
37: public void doInsert(XSourceEditor editor,
38: XEditorProject currentProject, XPageResource pageRes) {
39: String page = getPage(editor, pageRes.getPage(), currentProject);
40: if (page == null)
41: return;
42:
43: try {
44: String text = "\n\tXProjectManager.getCurrentProject().getPageManager().showPage(\""
45: + page + "\");";
46: editor.getDocument().insertString(
47: editor.getCaretPosition(), text, null);
48: } catch (BadLocationException ex1) {
49: ex1.printStackTrace();
50: }
51: }
52:
53: /**
54: * Get the caption displayed on the popup menu
55: * @return the caption
56: */
57: public String getCaption() {
58: return "page navigation";
59: }
60:
61: /**
62: * Get the mnemonic key for this item
63: * @return the mnemonic
64: */
65: public Integer getMnemonic() {
66: return new Integer(KeyEvent.VK_C);
67: }
68:
69: /**
70: * Get the component to reference
71: * @param editor the source editor window/the parent for the popup
72: * @param page the page whose components are to be listed
73: * @return the selected component or null
74: */
75: protected String getPage(XSourceEditor editor, XPage page,
76: XEditorProject currentProject) {
77: try {
78: XPageSelectionDialog dlg = new XPageSelectionDialog(
79: currentProject);
80: dlg.show();
81: return dlg.getSelectedPage();
82: } catch (Exception ex) {
83: return null;
84: }
85: }
86: }
|