Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trac#18139 Importieren von Formularinhalten #324

Open
wants to merge 1 commit into
base: WollMux_18.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*-
* #%L
* WollMux
* %%
* Copyright (C) 2005 - 2022 Landeshauptstadt München
* %%
* Licensed under the EUPL, Version 1.1 or – as soon they will be
* approved by the European Commission - subsequent versions of the
* EUPL (the "Licence");
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* #L%
*/
package de.muenchen.allg.itd51.wollmux.dispatch;

import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XFrame;
import com.sun.star.util.URL;

import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnImportFormularinhalt;


/**
* Dispatch, which shows the GUI for creating or modifying a form.
*/
public class ImportFormularinhaltDispatch extends WollMuxDispatch
{
/**
* Command of this dispatch.
*/
public static final String COMMAND = "wollmux:ImportFormularinhalt";

ImportFormularinhaltDispatch(XDispatch origDisp, URL origUrl, XFrame frame)
{
super(origDisp, origUrl, frame);
}

@Override
public void dispatch(URL url, PropertyValue[] props)
{
new OnImportFormularinhalt(DocumentManager.getTextDocumentController(frame)).emit();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public WollMuxDispatcher()
TextbausteinDispatch.COMMAND_REFERENCE, PlatzhalterAnspringenDispatch.COMMAND,
FormularMaxDispatch.COMMAND, SeriendruckDispatch.COMMAND, FunctionDialogDispatch.COMAND,
DumpInfoDispatch.COMMAND, AboutDispatch.COMMAND, OpenTemplateDispatch.COMMAND_TEMPLATE,
OpenTemplateDispatch.COMMAND_DOCUMENT, KillDispatch.COMMAND);
OpenTemplateDispatch.COMMAND_DOCUMENT, KillDispatch.COMMAND, ImportFormularinhaltDispatch.COMMAND);
}

@Override
Expand Down Expand Up @@ -82,9 +82,12 @@ public WollMuxDispatch create(XDispatch origDisp, URL origUrl, XFrame frame)
return new OpenTemplateDispatch(origDisp, origUrl, frame, false);
case KillDispatch.COMMAND:
return new KillDispatch(origDisp, origUrl, frame);
case ImportFormularinhaltDispatch.COMMAND:
return new ImportFormularinhaltDispatch(origDisp, origUrl, frame);
default:
return null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import de.muenchen.allg.itd51.wollmux.event.handlers.OnTextDocumentClosed;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnTextbausteinEinfuegen;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnUpdateInputFields;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnImportFormularinhalt;

/**
* An event listener for all unspecified events.
Expand Down Expand Up @@ -459,5 +460,16 @@ public void onActivateSidebar(OnActivateSidebar event)
{
event.process();
}


/**
* Execute the event
*
* @param event
* The event.
*/
@Subscribe
public void onImportFormularinhalt(OnImportFormularinhalt event)
{
event.process();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*-
* #%L
* WollMux
* %%
* Copyright (C) 2005 - 2022 Landeshauptstadt München
* %%
* Licensed under the EUPL, Version 1.1 or – as soon they will be
* approved by the European Commission - subsequent versions of the
* EUPL (the "Licence");
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* #L%
*/
package de.muenchen.allg.itd51.wollmux.event.handlers;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.star.document.XEventListener;
import com.sun.star.lang.EventObject;
import com.sun.star.text.XTextDocument;
import com.sun.star.ui.dialogs.FilePicker;
import com.sun.star.ui.dialogs.TemplateDescription;
import com.sun.star.ui.dialogs.XFilePicker3;
import com.sun.star.uno.UnoRuntime;

import de.muenchen.allg.afid.UNO;
import de.muenchen.allg.afid.UnoHelperException;
import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException;
import de.muenchen.allg.itd51.wollmux.dialog.InfoDialog;
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
import de.muenchen.allg.itd51.wollmux.document.FormFieldFactory.FormField;
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler;
import de.muenchen.allg.itd51.wollmux.util.L;

/**
* Event for importing content of formular.
*/
public class OnImportFormularinhalt extends WollMuxEvent
{

private static final Logger LOGGER = LoggerFactory.getLogger(OnImportFormularinhalt.class);

private TextDocumentController documentController;
/**
* Create this event.
*
* @param documentController
* The document associated with the FormularMax.
*/
public OnImportFormularinhalt(TextDocumentController documentController)
{
this.documentController = documentController;
}

@Override
protected void doit() throws WollMuxFehlerException
{
XFilePicker3 picker = FilePicker.createWithMode(UNO.defaultContext,
TemplateDescription.FILEOPEN_SIMPLE);
String filterName = "Tabellendokument";
picker.appendFilter(filterName, "*.odt");
picker.appendFilter("Alle Dateien", "*");
picker.setCurrentFilter(filterName);
picker.setMultiSelectionMode(false);

short res = picker.execute();
if (res != com.sun.star.ui.dialogs.ExecutableDialogResults.OK)
return;

String[] files = picker.getFiles();
try
{
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, true));

XEventListener listener = new XEventListener()
{
@Override
public void disposing(EventObject arg0)
{
// nothing to do
}

private void setFormValue(Entry<String, String> e)
{
if (e.getValue() == null)
return;
new OnSetFormValue(documentController.getModel().doc, e.getKey(), e.getValue(), null).emit();
}

private List<String> keysNotInList(Map<String, String> id2value, Map<String, List<FormField>> id2valueTo)
{
List<String> notFound = new ArrayList<>();

for (Entry<String, String> e : id2value.entrySet())
{
if (id2valueTo.containsKey(e.getKey()))
{
setFormValue(e);
} else
{
notFound.add(e.getKey());
}
}
if (!notFound.isEmpty())
{
String msg = L.m("Die folgenden Schlüssel können nicht importiert werden:\n") + String.join("\n", notFound);

InfoDialog.showInfoModal(L.m("WollMux"), msg);
}

return notFound;
}

@Override
public void notifyEvent(com.sun.star.document.EventObject event)
{
if (importDoc!=null
&& UnoRuntime.areSame(importDoc, event.Source)
&& WollMuxEventHandler.ON_WOLLMUX_PROCESSING_FINISHED.equals(event.EventName))
{

new OnRemoveDocumentEventListener(this).emit();
try(ByteArrayOutputStream out = new ByteArrayOutputStream())
{
TextDocumentController importDocumentController =
DocumentManager.getTextDocumentController(importDoc);
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap();
Map<String, List<FormField>> id2valueTo = documentController.getModel().getIdToFormFields();
keysNotInList(id2value, id2valueTo);

} catch(Exception e)
{
LOGGER.error("", e);
InfoDialog.showInfoModal(L.m("WollMux-Fehler"), e.getMessage());
}
}
}
};

new OnAddDocumentEventListener(listener).emit();
} catch ( UnoHelperException e )
{
LOGGER.error("", e);
}
}

@Override
public String toString()
{
return this.getClass().getSimpleName() + "(" + documentController.getModel()
+ ")";
}
}
23 changes: 22 additions & 1 deletion oxt/src/main/oxt/Addons.xcu
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,27 @@
</prop>
</node>

<node oor:name="m4" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>wollmux:ImportFormularinhalt</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value>Importiere Formularinhalt</value>
<value xml:lang="de">Importiere Formularinhalt</value>
<value xml:lang="nl">Inhoud van formulier importeren</value>
<value xml:lang="en">Import content of formular</value>
</prop>
<prop oor:name="ImageIdentifier" oor:type="xs:string">
<value/>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>

</node>

<node oor:name="de.muenchen.allg.itd51.wollmux.WerkzeugeFuerVorlagenersteller" oor:op="replace">
Expand Down Expand Up @@ -407,8 +428,8 @@
</prop>
</node>
</node>


</node>

</node>
</oor:component-data>
4 changes: 4 additions & 0 deletions oxt/src/main/oxt/basic/WollMux/Call.xba
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Sub TextbausteinVerweisEinfuegen
dispatchURL(&quot;wollmux:TextbausteinVerweisEinfuegen&quot;)
End Sub

Sub ImportFormularinhalt
dispatchURL(&quot;wollmux:ImportFormularinhalt&quot;)
End Sub

Sub Seriendruck
dispatchURL(&quot;wollmux:Seriendruck&quot;)
End Sub
Expand Down