Skip to content
Snippets Groups Projects
Commit 2b45eaba authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Remove convert v6 project function

parent 8a38ebfd
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@ import de.tobias.playpad.profile.ref.ProfileReference;
import de.tobias.playpad.project.Project;
import de.tobias.playpad.project.ProjectNotFoundException;
import de.tobias.playpad.project.ProjectReader;
import de.tobias.playpad.project.importer.ConverterV6;
import de.tobias.playpad.project.loader.ProjectLoader;
import de.tobias.playpad.project.ref.ProjectReference;
import de.tobias.playpad.project.ref.ProjectReferenceManager;
......@@ -196,37 +195,6 @@ public class LaunchDialog extends NVC implements ChangeListener<ConnectionState>
}
}
@FXML
void convertProjectButtonHandler(ActionEvent event) {
try {
List<ProjectReference> projects = ConverterV6.loadProjectReferences();
ChoiceDialog<ProjectReference> dialog = new ChoiceDialog<>(null, projects);
dialog.setHeaderText(Localization.getString(Strings.UI_DIALOG_PROJECT_CONVERT_HEADER));
dialog.setContentText(Localization.getString(Strings.UI_DIALOG_PROJECT_CONVERT_CONTENT));
dialog.initOwner(getContainingWindow());
dialog.initModality(Modality.WINDOW_MODAL);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(PlayPadPlugin.getInstance().getIcon());
Optional<ProjectReference> result = dialog.showAndWait();
result.ifPresent((ref) -> {
try {
ConverterV6.convert(ref.getUuid(), ref.getName());
ProjectReferenceManager.addProjectReference(ref);
setProjectListValues();
} catch (IOException | DocumentException e) {
Logger.error(e);
showErrorMessage(Localization.getString(Strings.ERROR_PROJECT_CONVERT));
}
});
} catch (IOException | DocumentException e) {
Logger.error(e);
showErrorMessage(Localization.getString(Strings.ERROR_STANDARD_GEN));
}
}
@FXML
void openButtonHandler(ActionEvent event) {
launchProject(getSelectedProject());
......
......@@ -19,7 +19,6 @@
<children>
<Button fx:id="newProjectButton" layoutX="115.0" layoutY="259.0" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#newProjectButtonHandler" text="%launch.button.new" VBox.vgrow="ALWAYS" />
<Button fx:id="importProject" layoutX="109.0" layoutY="292.0" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#importProjectButtonHandler" text="%launch.button.import" VBox.vgrow="ALWAYS" />
<Button fx:id="convertProjectButton" layoutX="109.0" layoutY="292.0" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#convertProjectButtonHandler" text="%launch.button.convert" VBox.vgrow="ALWAYS" />
<Label fx:id="cloudLabel" graphicTextGap="8.0" onMouseClicked="#cloudIconClicked" />
</children>
</VBox>
......
package de.tobias.playpad.project.importer;
import de.thecodelabs.utils.application.ApplicationUtils;
import de.thecodelabs.utils.application.container.PathType;
import de.tobias.playpad.project.ref.ProjectReference;
import de.tobias.playpad.project.ref.ProjectReferenceManager;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Created by tobias on 25.02.17.
*/
public class ConverterV6 {
private static final String CONTENT_TYPE_ATTR = "type";
private static final String CONTENT_PATHS_ELEMENT = "Paths";
private static final String CONTENT_PATH_ELEMENT = "Path";
private static final String CONTENT_PATH_UUID = "id";
private static final String CONTENT_PATH_PATH = "path";
public static void convert(UUID src, String name) throws IOException, DocumentException {
ProjectReference ref = new ProjectReference(src, name);
Path srcPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS).resolve("../../de.tobias.playpad.v6/Documents/" + src + ".xml");
Path desPath = ref.getProjectPath();
Files.copy(srcPath, desPath, StandardCopyOption.REPLACE_EXISTING);
SAXReader reader = new SAXReader();
Document document = reader.read(Files.newInputStream(desPath));
Element rootElement = document.getRootElement();
for (Object pageObj : rootElement.elements("Page")) {
Element pageElement = (Element) pageObj;
for (Object padObj : pageElement.elements("Pad")) {
Element padElement = (Element) padObj;
Element contentElement = padElement.element("Content");
if (contentElement != null) {
String type = contentElement.attributeValue("type");
String path = contentElement.getStringValue();
// Remove Old
padElement.remove(contentElement);
// Add New
contentElement = padElement.addElement("Content");
contentElement.addAttribute(CONTENT_TYPE_ATTR, type);
Element pathsElement = contentElement.addElement(CONTENT_PATHS_ELEMENT);
Element pathElement = pathsElement.addElement(CONTENT_PATH_ELEMENT);
pathElement.addAttribute(CONTENT_PATH_UUID, UUID.randomUUID().toString());
pathElement.addAttribute(CONTENT_PATH_PATH, path);
}
}
}
XMLWriter writer = new XMLWriter(Files.newOutputStream(desPath), OutputFormat.createPrettyPrint());
writer.write(document);
writer.close();
}
public static List<ProjectReference> loadProjectReferences() throws IOException, DocumentException {
List<ProjectReference> projects = new ArrayList<>();
Path projectReferencesPath = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION).resolve("../../de.tobias.playpad.v6/Config/Projects.xml");
if (Files.exists(projectReferencesPath)) {
SAXReader reader = new SAXReader();
Document document = reader.read(Files.newInputStream(projectReferencesPath));
for (Object object : document.getRootElement().elements(ProjectReferenceManager.PROJECT_ELEMENT)) {
if (object instanceof Element) {
Element element = (Element) object;
UUID uuid = UUID.fromString(element.attributeValue("uuid"));
String name = element.attributeValue("name");
ProjectReference ref = new ProjectReference(uuid, name);
projects.add(ref);
}
}
}
return projects;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment