Skip to content

Commit cca87b3

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

File tree

6 files changed

+260
-1
lines changed

6 files changed

+260
-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,165 @@
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.Collection;
28+
import java.util.Iterator;
29+
import java.util.List;
30+
import java.util.ListIterator;
31+
import java.util.Map;
32+
import java.util.Map.Entry;
33+
34+
import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException;
35+
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
36+
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
37+
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler;
38+
import de.muenchen.allg.itd51.wollmux.util.L;
39+
40+
import com.sun.star.ui.dialogs.FilePicker;
41+
import com.sun.star.ui.dialogs.TemplateDescription;
42+
import com.sun.star.ui.dialogs.XFilePicker3;
43+
import com.sun.star.uno.UnoRuntime;
44+
import com.sun.star.text.XTextDocument;
45+
import com.sun.star.document.XEventListener;
46+
import com.sun.star.lang.EventObject;
47+
48+
import org.slf4j.Logger;
49+
import org.slf4j.LoggerFactory;
50+
51+
import de.muenchen.allg.itd51.wollmux.dialog.InfoDialog;
52+
import de.muenchen.allg.afid.UNO;
53+
import de.muenchen.allg.afid.UnoHelperException;
54+
55+
56+
/**
57+
* Event for importing content of formular.
58+
*/
59+
public class OnImportFormularinhalt extends WollMuxEvent
60+
{
61+
62+
private static final Logger LOGGER = LoggerFactory.getLogger(OnImportFormularinhalt.class);
63+
64+
private TextDocumentController documentController;
65+
/**
66+
* Create this event.
67+
*
68+
* @param documentController
69+
* The document associated with the FormularMax.
70+
*/
71+
public OnImportFormularinhalt(TextDocumentController documentController)
72+
{
73+
this.documentController = documentController;
74+
}
75+
76+
77+
@Override
78+
protected void doit() throws WollMuxFehlerException
79+
{
80+
XFilePicker3 picker = FilePicker.createWithMode(UNO.defaultContext,
81+
TemplateDescription.FILEOPEN_SIMPLE);
82+
String filterName = "Tabellendokument";
83+
picker.appendFilter(filterName, "*.odt");
84+
picker.appendFilter("Alle Dateien", "*");
85+
picker.setCurrentFilter(filterName);
86+
picker.setMultiSelectionMode(false);
87+
88+
short res = picker.execute();
89+
if (res != com.sun.star.ui.dialogs.ExecutableDialogResults.OK)
90+
return;
91+
92+
String[] files = picker.getFiles();
93+
try
94+
{
95+
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, true));
96+
97+
XEventListener listener = new XEventListener()
98+
{
99+
@Override
100+
public void disposing(EventObject arg0)
101+
{
102+
// nothing to do
103+
}
104+
105+
@Override
106+
public void notifyEvent(com.sun.star.document.EventObject event)
107+
{
108+
if (importDoc!=null
109+
&& UnoRuntime.areSame(importDoc, event.Source)
110+
&& WollMuxEventHandler.ON_WOLLMUX_PROCESSING_FINISHED.equals(event.EventName))
111+
{
112+
new OnRemoveDocumentEventListener(this).emit();
113+
try(ByteArrayOutputStream out = new ByteArrayOutputStream())
114+
{
115+
TextDocumentController importDocumentController =
116+
DocumentManager.getTextDocumentController(importDoc);
117+
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap();
118+
Map<String, String> id2valueTo = documentController.getModel().getFormFieldValuesMap();
119+
List<String> notfound = new ArrayList<String>();
120+
for (Entry<String, String> e : id2value.entrySet())
121+
{
122+
if(id2valueTo.containsKey(e.getKey()))
123+
{
124+
if (e.getValue() != null)
125+
{
126+
new OnSetFormValue(documentController.getModel().doc, e.getKey(),
127+
e.getValue(), null).emit();
128+
}
129+
}
130+
else
131+
{
132+
notfound.add(e.getKey());
133+
}
134+
}
135+
136+
if(!notfound.isEmpty())
137+
{
138+
String msg = L.m("Die folgenden Schlüssel können nicht importiert werden:\n") +
139+
String.join("\n", notfound);
140+
141+
InfoDialog.showInfoModal(L.m("WollMux"), msg );
142+
}
143+
} catch(Exception e)
144+
{
145+
LOGGER.error("", e);
146+
InfoDialog.showInfoModal(L.m("WollMux-Fehler"), e.getMessage());
147+
}
148+
}
149+
}
150+
};
151+
152+
new OnAddDocumentEventListener(listener).emit();
153+
} catch ( UnoHelperException e )
154+
{
155+
LOGGER.error("", e);
156+
}
157+
}
158+
159+
@Override
160+
public String toString()
161+
{
162+
return this.getClass().getSimpleName() + "(" + documentController.getModel()
163+
+ ")";
164+
}
165+
}

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)