001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.text;
019:
020: import java.awt.BorderLayout;
021: import java.awt.event.FocusAdapter;
022: import java.awt.event.FocusEvent;
023: import java.io.UnsupportedEncodingException;
024: import java.net.URLEncoder;
025: import java.util.logging.Logger;
026:
027: import javax.swing.Action;
028: import javax.swing.JScrollPane;
029:
030: import de.finix.contelligent.client.base.ContelligentConstants;
031: import de.finix.contelligent.client.base.ServerInfo;
032: import de.finix.contelligent.client.event.ContelligentEvent;
033: import de.finix.contelligent.client.gui.AbstractComponentEditor;
034: import de.finix.contelligent.client.remote.ActionResult;
035: import de.finix.contelligent.client.remote.Actions;
036: import de.finix.contelligent.client.remote.NetAccess;
037: import de.finix.contelligent.client.remote.RemoteActionException;
038: import de.finix.contelligent.client.util.ExceptionDialog;
039:
040: public class SourcefileEditor extends AbstractComponentEditor {
041:
042: private static Logger logger = Logger
043: .getLogger(SourcefileEditor.class.getName());
044:
045: private ContelligentTextPane textEditor = new ContelligentTextPane();
046:
047: private Action[] actions;
048:
049: public void init() {
050: final ContelligentEditorKit contelligentEditorKit = new ContelligentEditorKit(
051: ContelligentEditorKit.HANDLE_CONTELLIGENT_TAG,
052: getView());
053: textEditor.setEditorKit(contelligentEditorKit);
054: actions = contelligentEditorKit.getActions(this .getComponent());
055:
056: ContelligentStyledDocument contelligentDocument = new ContelligentStyledDocument(
057: getComponent(), textEditor);
058: textEditor.setStyledDocument(contelligentDocument);
059:
060: update();
061:
062: textEditor.setEditable(isEditable());
063:
064: JScrollPane scrollPane = new JScrollPane(textEditor);
065: add(scrollPane, BorderLayout.CENTER);
066:
067: this .textEditor.addFocusListener(new FocusAdapter() {
068: public void focusGained(FocusEvent e) {
069: getView()
070: .setActions(SourcefileEditor.this .getActions());
071: }
072: });
073: }
074:
075: public void update() {
076: String sourceURL = null;
077: String source = null;
078:
079: sourceURL = ServerInfo.getInstance().getServer()
080: + getComponent().getPath() + ".bin";
081: try {
082: source = NetAccess.getStringFromURL(sourceURL);
083: } catch (Exception e) {
084: source = "";
085: }
086: textEditor.setText(source);
087: }
088:
089: protected void updateComponent() {
090: }
091:
092: protected void componentChanged(ContelligentEvent event) {
093: update();
094: }
095:
096: protected void childComponentAdded(ContelligentEvent event) {
097: }
098:
099: protected void childComponentRemoved(ContelligentEvent event) {
100: }
101:
102: protected void childComponentChanged(ContelligentEvent event) {
103: }
104:
105: protected void descendentComponentChanged(ContelligentEvent event) {
106: }
107:
108: private void updateSourcefile() {
109: /* String jspSource = null;
110: String parameter = null;
111: byte[] data = null;
112: ActionResult response = null;
113:
114: try {
115: jspSource = URLEncoder.encode(textEditor.getText(), ContelligentConstants.CHARACTER_ENCODING);
116: parameter = "PATH=" + getComponent().getPath() + "&OVERWRITE=true&JSP_SOURCE=" + jspSource;
117: data = parameter.getBytes();
118:
119: response = Actions.jspUpload(data, "application/x-www-form-urlencoded");
120: response.showErrors();
121: } catch (RemoteActionException rae) {
122: ExceptionDialog.show(rae);
123: } catch (UnsupportedEncodingException uee) {
124: ExceptionDialog.show(uee);
125: } */
126: }
127:
128: public void setEditable(boolean editable) {
129: super .setEditable(editable);
130: if (isEditable()) {
131: textEditor.setEditable(isEditable());
132: }
133: }
134:
135: public void rollback() {
136: }
137:
138: public void commit() {
139: textEditor.setEditable(false);
140: updateSourcefile();
141: }
142:
143: public Action[] getActions() {
144: if (isEditable()) {
145: return actions;
146: } else {
147: return new Action[] { getAction("copy_action") };
148: }
149: }
150:
151: private Action getAction(String name) {
152: for (int i = 0; i < actions.length; i++) {
153: if (actions[i].getValue(Action.NAME).equals(name)) {
154: return actions[i];
155: }
156: }
157: return null;
158: }
159: }
|