Skip to content

Commit ccbca3e

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

File tree

6 files changed

+257
-1
lines changed

6 files changed

+257
-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/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,162 @@
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.ArrayList;
27+
import java.util.List;
28+
import java.util.Map;
29+
import java.util.Map.Entry;
30+
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
34+
import com.sun.star.document.XEventListener;
35+
import com.sun.star.lang.EventObject;
36+
import com.sun.star.text.XTextDocument;
37+
import com.sun.star.ui.dialogs.FilePicker;
38+
import com.sun.star.ui.dialogs.TemplateDescription;
39+
import com.sun.star.ui.dialogs.XFilePicker3;
40+
import com.sun.star.uno.UnoRuntime;
41+
42+
import de.muenchen.allg.afid.UNO;
43+
import de.muenchen.allg.afid.UnoHelperException;
44+
import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException;
45+
import de.muenchen.allg.itd51.wollmux.dialog.InfoDialog;
46+
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
47+
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
48+
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler;
49+
import de.muenchen.allg.itd51.wollmux.util.L;
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+
return;
87+
88+
String[] files = picker.getFiles();
89+
try
90+
{
91+
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, true));
92+
93+
XEventListener listener = new XEventListener()
94+
{
95+
@Override
96+
public void disposing(EventObject arg0)
97+
{
98+
// nothing to do
99+
}
100+
101+
@Override
102+
public void notifyEvent(com.sun.star.document.EventObject event)
103+
{
104+
if (importDoc!=null
105+
&& UnoRuntime.areSame(importDoc, event.Source)
106+
&& WollMuxEventHandler.ON_WOLLMUX_PROCESSING_FINISHED.equals(event.EventName))
107+
{
108+
109+
new OnRemoveDocumentEventListener(this).emit();
110+
try(ByteArrayOutputStream out = new ByteArrayOutputStream())
111+
{
112+
TextDocumentController importDocumentController =
113+
DocumentManager.getTextDocumentController(importDoc);
114+
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap();
115+
Map<String, String> id2valueTo = documentController.getModel().getFormFieldValuesMap();
116+
List<String> notfound = new ArrayList<>();
117+
for (Entry<String, String> e : id2value.entrySet())
118+
{
119+
if(id2valueTo.containsKey(e.getKey()))
120+
{
121+
if (e.getValue() != null)
122+
{
123+
new OnSetFormValue(documentController.getModel().doc, e.getKey(),
124+
e.getValue(), null).emit();
125+
}
126+
}
127+
else
128+
{
129+
notfound.add(e.getKey());
130+
}
131+
}
132+
133+
if (!notfound.isEmpty())
134+
{
135+
String msg = L.m("Die folgenden Schlüssel können nicht importiert werden:\n")
136+
+ String.join("\n", notfound);
137+
138+
InfoDialog.showInfoModal(L.m("WollMux"), msg);
139+
}
140+
} catch(Exception e)
141+
{
142+
LOGGER.error("", e);
143+
InfoDialog.showInfoModal(L.m("WollMux-Fehler"), e.getMessage());
144+
}
145+
}
146+
}
147+
};
148+
149+
new OnAddDocumentEventListener(listener).emit();
150+
} catch ( UnoHelperException e )
151+
{
152+
LOGGER.error("", e);
153+
}
154+
}
155+
156+
@Override
157+
public String toString()
158+
{
159+
return this.getClass().getSimpleName() + "(" + documentController.getModel()
160+
+ ")";
161+
}
162+
}

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)