Skip to content

Commit

Permalink
trac#18139 Importieren von Formularinhalten
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhany359 committed Nov 25, 2020
1 parent 84497a6 commit ef6e3ad
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*-
* #%L
* WollMux
* %%
* Copyright (C) 2005 - 2020 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,6 +82,8 @@ 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,16 @@ public void importFormValues(File file) throws IOException
parseFormValues(data);
}

/**
* Import the form values form a file.
*
* @param data
* A string containing a description of form values.
*/public void importFormValues(String data)
{
parseFormValues(data);
}

/**
* Parses the string as {@link ConfigThingy} of the form "WM(FormularWerte(...))" and adds the
* values to {@link #formFieldValues}.
Expand Down
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,17 @@ 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,145 @@
/*-
* #%L
* WollMux
* %%
* Copyright (C) 2005 - 2020 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.Map;
import java.util.Map.Entry;

import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException;
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
import de.muenchen.allg.itd51.wollmux.form.control.FormController;
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler;

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 com.sun.star.text.XTextDocument;
import com.sun.star.document.XEventListener;
import com.sun.star.lang.EventObject;

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



import de.muenchen.allg.afid.UNO;
import de.muenchen.allg.afid.UnoHelperException;


/**
* 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)
{
String[] files = picker.getFiles();
try
{
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, false));

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

@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())
{
FormController fc = DocumentManager.getDocumentManager().getFormController(importDoc);
fc.exportFormValues(out);
fc.importFormValues(out.toString());
TextDocumentController importDocumentController = DocumentManager.getDocumentManager().getTextDocumentController(importDoc);
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap();
for (Entry<String, String> e : id2value.entrySet())
{
if (e.getValue() != null)
{
new OnSetFormValue(documentController.getModel().doc, e.getKey(),
e.getValue(), null).emit();
}
}
} catch(Exception e)
{
LOGGER.error("", e);
}
}
}
};

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

@Override
public String toString()
{
return this.getClass().getSimpleName() + "(" + documentController.getModel()
+ ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -231,6 +232,11 @@ public void formControllerInitCompleted()
new OnResetDocumentState(documentController).emit();
}

public void exportFormValues(OutputStream out)
{
documentController.getModel().exportFormValues(out);
}

public void exportFormValues(File f) throws IOException
{
try (FileOutputStream out = new FileOutputStream(f))
Expand All @@ -244,6 +250,11 @@ public void importFormValues(File f) throws IOException
documentController.getModel().importFormValues(f);
}

public void importFormValues(String s)
{
documentController.getModel().importFormValues(s);
}

/**
* Besitzt das Formular, welches von diesem Controller verwaltet wird, ein Feld mit der ID
* fieldId?
Expand Down
21 changes: 21 additions & 0 deletions oxt/src/main/oxt/Addons.xcu
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@
<value>com.sun.star.text.TextDocument</value>
</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>

Expand Down
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

0 comments on commit ef6e3ad

Please sign in to comment.