Alpha working
This commit is contained in:
parent
adf19bc4ab
commit
90617b8120
4 changed files with 81 additions and 27 deletions
|
@ -82,16 +82,18 @@ public class Document {
|
||||||
reader.parse();
|
reader.parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeOutlineMetadata() {
|
public void writeOutlineMetadata() {
|
||||||
cleanMetadataInDocument();
|
cleanMetadataInDocument();
|
||||||
for (OutlineElement element : outline){
|
for (OutlineElement element : outline){
|
||||||
Object annotation;
|
if (!element.isEmpty()) {
|
||||||
try {
|
Object annotation;
|
||||||
annotation = multiServiceFactory.createInstance("com.sun.star.text.textfield.annotation");
|
try {
|
||||||
element.writeMetadata(annotation);
|
annotation = multiServiceFactory.createInstance("com.sun.star.text.TextField.Annotation");
|
||||||
} catch (com.sun.star.uno.Exception e) {
|
element.writeMetadata(annotation);
|
||||||
e.printStackTrace();
|
} catch (com.sun.star.uno.Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,22 @@ public class OutlineElement {
|
||||||
|
|
||||||
private String elementName;
|
private String elementName;
|
||||||
private ArrayList<MetadataElement> metadata = null;
|
private ArrayList<MetadataElement> metadata = null;
|
||||||
|
private XTextRange textRange;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return elementName;
|
return elementName;
|
||||||
}
|
}
|
||||||
|
public boolean isEmpty() {
|
||||||
private XTextRange textRange;
|
if (metadata.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < metadata.size(); i++) {
|
||||||
|
if (!metadata.get(i).getName().isEmpty() && !metadata.get(i).getValue().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public OutlineElement(XTextRange textRange, String name) {
|
public OutlineElement(XTextRange textRange, String name) {
|
||||||
this.textRange = textRange;
|
this.textRange = textRange;
|
||||||
|
@ -39,9 +49,9 @@ public class OutlineElement {
|
||||||
int size = metadata.size();
|
int size = metadata.size();
|
||||||
if (metadata.size() == 0) {
|
if (metadata.size() == 0) {
|
||||||
result = new Object[][] {
|
result = new Object[][] {
|
||||||
{null, null},
|
{"", ""},
|
||||||
{null, null},
|
{"", ""},
|
||||||
{null, null},
|
{"", ""},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
result = new Object [size] [2];
|
result = new Object [size] [2];
|
||||||
|
@ -83,14 +93,15 @@ private String metadataToString() {
|
||||||
|
|
||||||
public void writeMetadata(Object annotation) {
|
public void writeMetadata(Object annotation) {
|
||||||
XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, annotation);
|
XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, annotation);
|
||||||
XText startText = textRange.getText();
|
XText text = textRange.getText();
|
||||||
try {
|
try {
|
||||||
properties.setPropertyValue("Author", METADATA_EXTENSION);
|
properties.setPropertyValue("Author", METADATA_EXTENSION);
|
||||||
properties.setPropertyValue("Content", metadataToString());
|
properties.setPropertyValue("Content", metadataToString());
|
||||||
|
|
||||||
XTextRange annotationRange = null;
|
XTextRange annotationRange = null;
|
||||||
annotationRange = textRange;
|
annotationRange = textRange;
|
||||||
XTextField textField = UnoRuntime.queryInterface(XTextField.class, annotation);
|
XTextField textField = UnoRuntime.queryInterface(XTextField.class, annotation);
|
||||||
startText.insertTextContent( annotationRange, textField, true );
|
text.insertTextContent( annotationRange, textField, false );
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (UnknownPropertyException e) {
|
} catch (UnknownPropertyException e) {
|
||||||
|
@ -101,6 +112,10 @@ public void writeMetadata(Object annotation) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void setMetadata(ArrayList<MetadataElement> metadataInput) {
|
||||||
|
this.metadata.clear();
|
||||||
|
this.metadata.addAll(metadataInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class EditorGUI extends JFrame {
|
||||||
//Components
|
//Components
|
||||||
private JTable tableDocStandard;
|
private JTable tableDocStandard;
|
||||||
private JTable tableDocCustom;
|
private JTable tableDocCustom;
|
||||||
|
private ArrayList<MetadataTableModel> tableModels ;
|
||||||
|
|
||||||
//Component models
|
//Component models
|
||||||
private DefaultTableModel docPropertiesModel;
|
private DefaultTableModel docPropertiesModel;
|
||||||
|
@ -121,6 +121,7 @@ public class EditorGUI extends JFrame {
|
||||||
docProps = document.getDocumentProperties();
|
docProps = document.getDocumentProperties();
|
||||||
docCustomProps = document.getDocumentCustomProperties();
|
docCustomProps = document.getDocumentCustomProperties();
|
||||||
outline = document.getOutline();
|
outline = document.getOutline();
|
||||||
|
tableModels = new ArrayList<MetadataTableModel>();
|
||||||
initComponents();
|
initComponents();
|
||||||
createEvents();
|
createEvents();
|
||||||
}
|
}
|
||||||
|
@ -176,7 +177,6 @@ public class EditorGUI extends JFrame {
|
||||||
tabbedPane.addTab("Метаданные либры", null, panelStandardMetadata, null);
|
tabbedPane.addTab("Метаданные либры", null, panelStandardMetadata, null);
|
||||||
tabbedPane.setEnabledAt(0, true);
|
tabbedPane.setEnabledAt(0, true);
|
||||||
if (true) {
|
if (true) {
|
||||||
//TEST ONLY
|
|
||||||
addMetadataTab(new OutlineElement(null, "Тестовое название"));
|
addMetadataTab(new OutlineElement(null, "Тестовое название"));
|
||||||
}
|
}
|
||||||
for (OutlineElement element : outline) {
|
for (OutlineElement element : outline) {
|
||||||
|
@ -213,7 +213,8 @@ public class EditorGUI extends JFrame {
|
||||||
private void addMetadataTab(OutlineElement element) {
|
private void addMetadataTab(OutlineElement element) {
|
||||||
JPanel panelOutline = new JPanel();
|
JPanel panelOutline = new JPanel();
|
||||||
JTable tableOutline = new JTable();
|
JTable tableOutline = new JTable();
|
||||||
DefaultTableModel outlineTableModel = createOutlineTableModel(element);
|
MetadataTableModel outlineTableModel = createOutlineTableModel(element);
|
||||||
|
tableModels.add(outlineTableModel);
|
||||||
configureTableOutline(tableOutline, outlineTableModel);
|
configureTableOutline(tableOutline, outlineTableModel);
|
||||||
|
|
||||||
JButton btnOutlineSave = new JButton("Сохранить");
|
JButton btnOutlineSave = new JButton("Сохранить");
|
||||||
|
@ -354,14 +355,9 @@ public class EditorGUI extends JFrame {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultTableModel createOutlineTableModel(OutlineElement element) {
|
private MetadataTableModel createOutlineTableModel(OutlineElement element) {
|
||||||
|
|
||||||
DefaultTableModel outlineTableModel = new DefaultTableModel(
|
MetadataTableModel outlineTableModel = new MetadataTableModel(element);
|
||||||
element.metadataToArray(),
|
|
||||||
new String[] {
|
|
||||||
"Metadata Name", "Metadata Value"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return outlineTableModel;
|
return outlineTableModel;
|
||||||
}
|
}
|
||||||
private void createCustomDocPropsModel() {
|
private void createCustomDocPropsModel() {
|
||||||
|
@ -387,7 +383,7 @@ public class EditorGUI extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
private static void addPopup(Component component, JPopupMenu popup) {
|
||||||
component.addMouseListener(new MouseAdapter() {
|
component.addMouseListener(new MouseAdapter() {
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if (e.isPopupTrigger()) {
|
if (e.isPopupTrigger()) {
|
||||||
|
@ -409,5 +405,12 @@ public class EditorGUI extends JFrame {
|
||||||
document.setDocumentProperties(docProps);
|
document.setDocumentProperties(docProps);
|
||||||
updateDocCustomProps();
|
updateDocCustomProps();
|
||||||
document.setCustomDocumentProperties(docCustomProps);
|
document.setCustomDocumentProperties(docCustomProps);
|
||||||
|
updateOutlineMetadata();
|
||||||
|
document.writeOutlineMetadata();
|
||||||
|
}
|
||||||
|
private void updateOutlineMetadata() {
|
||||||
|
for (MetadataTableModel table : tableModels) {
|
||||||
|
table.writeToOutline();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package pro.litvinovg.libreoffice.metadata.views;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
|
||||||
|
import pro.litvinovg.libreoffice.metadata.CustomDocumentProperty;
|
||||||
|
import pro.litvinovg.libreoffice.metadata.MetadataElement;
|
||||||
|
import pro.litvinovg.libreoffice.metadata.OutlineElement;
|
||||||
|
|
||||||
|
public class MetadataTableModel extends DefaultTableModel {
|
||||||
|
private OutlineElement outlineElement;
|
||||||
|
public MetadataTableModel(OutlineElement element) {
|
||||||
|
super(element.metadataToArray(), new String[] { "Metadata Name", "Metadata Value" });
|
||||||
|
this.outlineElement = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToOutline() {
|
||||||
|
Vector dataVector = this.getDataVector();
|
||||||
|
Enumeration elements = dataVector.elements();
|
||||||
|
ArrayList<MetadataElement> metadata = new ArrayList<MetadataElement>();
|
||||||
|
while (elements.hasMoreElements()) {
|
||||||
|
Vector row = (Vector) elements.nextElement();
|
||||||
|
String name = (String) row.get(0);
|
||||||
|
String value = (String) row.get(1);
|
||||||
|
if (!name.isEmpty() && !value.isEmpty()) {
|
||||||
|
metadata.add(new MetadataElement(name, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outlineElement.setMetadata(metadata);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue