Skip to content

Commit ef6e3ad

Browse files
committed
trac#18139 Importieren von Formularinhalten
1 parent 84497a6 commit ef6e3ad

File tree

8 files changed

+261
-1
lines changed

8 files changed

+261
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*-
2+
* #%L
3+
* WollMux
4+
* %%
5+
* Copyright (C) 2005 - 2020 Landeshauptstadt München
6+
* %%
7+
* Licensed under the EUPL, Version 1.1 or – as soon they will be
8+
* approved by the European Commission - subsequent versions of the
9+
* EUPL (the "Licence");
10+
*
11+
* You may not use this work except in compliance with the Licence.
12+
* You may obtain a copy of the Licence at:
13+
*
14+
* http://ec.europa.eu/idabc/eupl5
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the Licence is distributed on an "AS IS" basis,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the Licence for the specific language governing permissions and
20+
* limitations under the Licence.
21+
* #L%
22+
*/
23+
package de.muenchen.allg.itd51.wollmux.dispatch;
24+
25+
import com.sun.star.beans.PropertyValue;
26+
import com.sun.star.frame.XDispatch;
27+
import com.sun.star.frame.XFrame;
28+
import com.sun.star.util.URL;
29+
30+
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
31+
import de.muenchen.allg.itd51.wollmux.event.handlers.OnImportFormularinhalt;
32+
33+
/**
34+
* Dispatch, which shows the GUI for creating or modifying a form.
35+
*/
36+
public class ImportFormularinhaltDispatch extends WollMuxDispatch
37+
{
38+
/**
39+
* Command of this dispatch.
40+
*/
41+
public static final String COMMAND = "wollmux:ImportFormularinhalt";
42+
43+
ImportFormularinhaltDispatch(XDispatch origDisp, URL origUrl, XFrame frame)
44+
{
45+
super(origDisp, origUrl, frame);
46+
}
47+
48+
@Override
49+
public void dispatch(URL url, PropertyValue[] props)
50+
{
51+
new OnImportFormularinhalt(DocumentManager.getTextDocumentController(frame)).emit();
52+
}
53+
54+
}

Diff for: core/src/main/java/de/muenchen/allg/itd51/wollmux/dispatch/WollMuxDispatcher.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public WollMuxDispatcher()
4242
TextbausteinDispatch.COMMAND_REFERENCE, PlatzhalterAnspringenDispatch.COMMAND,
4343
FormularMaxDispatch.COMMAND, SeriendruckDispatch.COMMAND, FunctionDialogDispatch.COMAND,
4444
DumpInfoDispatch.COMMAND, AboutDispatch.COMMAND, OpenTemplateDispatch.COMMAND_TEMPLATE,
45-
OpenTemplateDispatch.COMMAND_DOCUMENT, KillDispatch.COMMAND);
45+
OpenTemplateDispatch.COMMAND_DOCUMENT, KillDispatch.COMMAND, ImportFormularinhaltDispatch.COMMAND);
4646
}
4747

4848
@Override
@@ -82,6 +82,8 @@ public WollMuxDispatch create(XDispatch origDisp, URL origUrl, XFrame frame)
8282
return new OpenTemplateDispatch(origDisp, origUrl, frame, false);
8383
case KillDispatch.COMMAND:
8484
return new KillDispatch(origDisp, origUrl, frame);
85+
case ImportFormularinhaltDispatch.COMMAND:
86+
return new ImportFormularinhaltDispatch(origDisp, origUrl, frame);
8587
default:
8688
return null;
8789
}

Diff for: core/src/main/java/de/muenchen/allg/itd51/wollmux/document/TextDocumentModel.java

+10
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,16 @@ public void importFormValues(File file) throws IOException
558558
parseFormValues(data);
559559
}
560560

561+
/**
562+
* Import the form values form a file.
563+
*
564+
* @param data
565+
* A string containing a description of form values.
566+
*/public void importFormValues(String data)
567+
{
568+
parseFormValues(data);
569+
}
570+
561571
/**
562572
* Parses the string as {@link ConfigThingy} of the form "WM(FormularWerte(...))" and adds the
563573
* values to {@link #formFieldValues}.

Diff for: core/src/main/java/de/muenchen/allg/itd51/wollmux/event/WollMuxEventListenerImpl.java

+13
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import de.muenchen.allg.itd51.wollmux.event.handlers.OnTextDocumentClosed;
5858
import de.muenchen.allg.itd51.wollmux.event.handlers.OnTextbausteinEinfuegen;
5959
import de.muenchen.allg.itd51.wollmux.event.handlers.OnUpdateInputFields;
60+
import de.muenchen.allg.itd51.wollmux.event.handlers.OnImportFormularinhalt;
6061

6162
/**
6263
* An event listener for all unspecified events.
@@ -459,5 +460,17 @@ public void onActivateSidebar(OnActivateSidebar event)
459460
{
460461
event.process();
461462
}
463+
464+
/**
465+
* Execute the event
466+
*
467+
* @param event
468+
* The event.
469+
*/
470+
@Subscribe
471+
public void onImportFormularinhalt(OnImportFormularinhalt event)
472+
{
473+
event.process();
474+
}
462475

463476
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*-
2+
* #%L
3+
* WollMux
4+
* %%
5+
* Copyright (C) 2005 - 2020 Landeshauptstadt München
6+
* %%
7+
* Licensed under the EUPL, Version 1.1 or – as soon they will be
8+
* approved by the European Commission - subsequent versions of the
9+
* EUPL (the "Licence");
10+
*
11+
* You may not use this work except in compliance with the Licence.
12+
* You may obtain a copy of the Licence at:
13+
*
14+
* http://ec.europa.eu/idabc/eupl5
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the Licence is distributed on an "AS IS" basis,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the Licence for the specific language governing permissions and
20+
* limitations under the Licence.
21+
* #L%
22+
*/
23+
package de.muenchen.allg.itd51.wollmux.event.handlers;
24+
25+
import java.io.ByteArrayOutputStream;
26+
import java.util.Map;
27+
import java.util.Map.Entry;
28+
29+
import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException;
30+
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
31+
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
32+
import de.muenchen.allg.itd51.wollmux.form.control.FormController;
33+
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler;
34+
35+
import com.sun.star.ui.dialogs.FilePicker;
36+
import com.sun.star.ui.dialogs.TemplateDescription;
37+
import com.sun.star.ui.dialogs.XFilePicker3;
38+
import com.sun.star.uno.UnoRuntime;
39+
import com.sun.star.text.XTextDocument;
40+
import com.sun.star.document.XEventListener;
41+
import com.sun.star.lang.EventObject;
42+
43+
import org.slf4j.Logger;
44+
import org.slf4j.LoggerFactory;
45+
46+
47+
48+
import de.muenchen.allg.afid.UNO;
49+
import de.muenchen.allg.afid.UnoHelperException;
50+
51+
52+
/**
53+
* Event for importing content of formular.
54+
*/
55+
public class OnImportFormularinhalt extends WollMuxEvent
56+
{
57+
58+
private static final Logger LOGGER = LoggerFactory.getLogger(OnImportFormularinhalt.class);
59+
60+
private TextDocumentController documentController;
61+
/**
62+
* Create this event.
63+
*
64+
* @param documentController
65+
* The document associated with the FormularMax.
66+
*/
67+
public OnImportFormularinhalt(TextDocumentController documentController)
68+
{
69+
this.documentController = documentController;
70+
}
71+
72+
73+
@Override
74+
protected void doit() throws WollMuxFehlerException
75+
{
76+
XFilePicker3 picker = FilePicker.createWithMode(UNO.defaultContext,
77+
TemplateDescription.FILEOPEN_SIMPLE);
78+
String filterName = "Tabellendokument";
79+
picker.appendFilter(filterName, "*.odt");
80+
picker.appendFilter("Alle Dateien", "*");
81+
picker.setCurrentFilter(filterName);
82+
picker.setMultiSelectionMode(false);
83+
84+
short res = picker.execute();
85+
if (res == com.sun.star.ui.dialogs.ExecutableDialogResults.OK)
86+
{
87+
String[] files = picker.getFiles();
88+
try
89+
{
90+
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, false));
91+
92+
XEventListener listener = new XEventListener()
93+
{
94+
@Override
95+
public void disposing(EventObject arg0)
96+
{
97+
// nothing to do
98+
}
99+
100+
@Override
101+
public void notifyEvent(com.sun.star.document.EventObject event)
102+
{
103+
if (importDoc!=null
104+
&& UnoRuntime.areSame(importDoc, event.Source)
105+
&& WollMuxEventHandler.ON_WOLLMUX_PROCESSING_FINISHED.equals(event.EventName))
106+
{
107+
new OnRemoveDocumentEventListener(this).emit();
108+
try(ByteArrayOutputStream out = new ByteArrayOutputStream())
109+
{
110+
FormController fc = DocumentManager.getDocumentManager().getFormController(importDoc);
111+
fc.exportFormValues(out);
112+
fc.importFormValues(out.toString());
113+
TextDocumentController importDocumentController = DocumentManager.getDocumentManager().getTextDocumentController(importDoc);
114+
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap();
115+
for (Entry<String, String> e : id2value.entrySet())
116+
{
117+
if (e.getValue() != null)
118+
{
119+
new OnSetFormValue(documentController.getModel().doc, e.getKey(),
120+
e.getValue(), null).emit();
121+
}
122+
}
123+
} catch(Exception e)
124+
{
125+
LOGGER.error("", e);
126+
}
127+
}
128+
}
129+
};
130+
131+
new OnAddDocumentEventListener(listener).emit();
132+
} catch ( UnoHelperException e )
133+
{
134+
LOGGER.error("", e);
135+
}
136+
}
137+
}
138+
139+
@Override
140+
public String toString()
141+
{
142+
return this.getClass().getSimpleName() + "(" + documentController.getModel()
143+
+ ")";
144+
}
145+
}

Diff for: core/src/main/java/de/muenchen/allg/itd51/wollmux/form/control/FormController.java

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.awt.event.ActionListener;
2626
import java.io.File;
2727
import java.io.FileOutputStream;
28+
import java.io.OutputStream;
2829
import java.io.IOException;
2930
import java.util.List;
3031

@@ -231,6 +232,11 @@ public void formControllerInitCompleted()
231232
new OnResetDocumentState(documentController).emit();
232233
}
233234

235+
public void exportFormValues(OutputStream out)
236+
{
237+
documentController.getModel().exportFormValues(out);
238+
}
239+
234240
public void exportFormValues(File f) throws IOException
235241
{
236242
try (FileOutputStream out = new FileOutputStream(f))
@@ -244,6 +250,11 @@ public void importFormValues(File f) throws IOException
244250
documentController.getModel().importFormValues(f);
245251
}
246252

253+
public void importFormValues(String s)
254+
{
255+
documentController.getModel().importFormValues(s);
256+
}
257+
247258
/**
248259
* Besitzt das Formular, welches von diesem Controller verwaltet wird, ein Feld mit der ID
249260
* fieldId?

Diff for: oxt/src/main/oxt/Addons.xcu

+21
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@
257257
<value>com.sun.star.text.TextDocument</value>
258258
</prop>
259259
</node>
260+
261+
<node oor:name="m4" oor:op="replace">
262+
<prop oor:name="URL" oor:type="xs:string">
263+
<value>wollmux:ImportFormularinhalt</value>
264+
</prop>
265+
<prop oor:name="Title" oor:type="xs:string">
266+
<value>Importiere Formularinhalt</value>
267+
<value xml:lang="de">Importiere Formularinhalt</value>
268+
<value xml:lang="nl">Inhoud van formulier importeren</value>
269+
<value xml:lang="en">Import content of formular</value>
270+
</prop>
271+
<prop oor:name="ImageIdentifier" oor:type="xs:string">
272+
<value/>
273+
</prop>
274+
<prop oor:name="Target" oor:type="xs:string">
275+
<value>_self</value>
276+
</prop>
277+
<prop oor:name="Context" oor:type="xs:string">
278+
<value>com.sun.star.text.TextDocument</value>
279+
</prop>
280+
</node>
260281

261282
</node>
262283

Diff for: oxt/src/main/oxt/basic/WollMux/Call.xba

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Sub TextbausteinVerweisEinfuegen
3636
dispatchURL(&quot;wollmux:TextbausteinVerweisEinfuegen&quot;)
3737
End Sub
3838

39+
Sub ImportFormularinhalt
40+
dispatchURL(&quot;wollmux:ImportFormularinhalt&quot;)
41+
End Sub
42+
3943
Sub Seriendruck
4044
dispatchURL(&quot;wollmux:Seriendruck&quot;)
4145
End Sub

0 commit comments

Comments
 (0)