primer commit
This commit is contained in:
commit
0a08cb9943
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.class
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ProyectosIES-GUI-Swing</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
8
.settings/org.eclipse.jdt.core.prefs
Normal file
8
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
31
pom.xml
Normal file
31
pom.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ConcesionarioGUI-Swing</groupId>
|
||||
<artifactId>ConcesionarioGUI-Swing</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Httpclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,164 @@
|
||||
package org.lapaloma.gui.proyectos;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class AppProyectosLaPalomaSwing {
|
||||
|
||||
// Clase interna para representar el objetos con Clave y Valor (para curso y
|
||||
// proyecto)
|
||||
static class ClaseClaveValor {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public ClaseClaveValor(String nombre, String codigo) {
|
||||
this.nombre = nombre;
|
||||
this.codigo = codigo;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public String getCodigo() {
|
||||
return codigo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// Esto define cómo se mostrará en el JComboBox
|
||||
return nombre;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Crear la ventana principal
|
||||
JFrame frame = new JFrame("Selección de Curso y Proyecto");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
// Establecer el tamaño de la ventana a 600x400 píxeles
|
||||
frame.setSize(600, 400);
|
||||
|
||||
// Centrar la ventana en la pantalla
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
// Configurar el layout del frame
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
// Crear panel para los JComboBox (Curso y Proyecto)
|
||||
JPanel panelComboBoxes = new JPanel();
|
||||
panelComboBoxes.setLayout(new GridBagLayout()); // Usar GridBagLayout para mayor control de los márgenes
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
|
||||
// Crear los cursos con su nombre y código
|
||||
ArrayList<ClaseClaveValor> cursosAcademicos = new ArrayList<>();
|
||||
cursosAcademicos.add(new ClaseClaveValor("Curso 2022/2023", "2022-2023"));
|
||||
cursosAcademicos.add(new ClaseClaveValor("Curso 2023/2024", "2023-2024"));
|
||||
|
||||
// Crear JComboBox para cursos académicos usando los objetos Curso
|
||||
JComboBox<ClaseClaveValor> comboCursos = new JComboBox<>(cursosAcademicos.toArray(new ClaseClaveValor[0]));
|
||||
comboCursos.setPreferredSize(new Dimension(150, 25));
|
||||
|
||||
// Crear los proyectos con su nombre y código
|
||||
ArrayList<ClaseClaveValor> proyectos = new ArrayList<>();
|
||||
proyectos.add(new ClaseClaveValor("Hiperbaric", "1"));
|
||||
proyectos.add(new ClaseClaveValor("EcoMotors", "2"));
|
||||
proyectos.add(new ClaseClaveValor("Speedster", "3"));
|
||||
|
||||
// Crear JComboBox para proyectos usando los objetos Proyecto
|
||||
JComboBox<ClaseClaveValor> comboProyectos = new JComboBox<>(proyectos.toArray(new ClaseClaveValor[0]));
|
||||
comboProyectos.setPreferredSize(new Dimension(150, 25));
|
||||
|
||||
// Establecer los márgenes entre los componentes con GridBagConstraints
|
||||
gbc.insets = new Insets(15, 0, 15, 0); // Espacio de 15px entre filas
|
||||
|
||||
// Añadir componentes al panel con GridBagLayout
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
panelComboBoxes.add(new JLabel("Curso Académico: "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panelComboBoxes.add(comboCursos, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
panelComboBoxes.add(new JLabel(" Proyecto: "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
panelComboBoxes.add(comboProyectos, gbc);
|
||||
|
||||
// Crear panel para el botón y centrarlo
|
||||
JPanel panelBoton = new JPanel();
|
||||
panelBoton.setLayout(new FlowLayout(FlowLayout.CENTER)); // Centrar el botón
|
||||
|
||||
// Crear botón "Migrar a MongoDB"
|
||||
JButton botonMigrar = new JButton("Migrar a MongoDB");
|
||||
|
||||
// Añadir ActionListener al botón
|
||||
botonMigrar.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Obtener el curso y el proyecto seleccionados
|
||||
String codigoProyecto = ((ClaseClaveValor) comboProyectos.getSelectedItem()).getCodigo();
|
||||
String codigoCursoSeleccionado = ((ClaseClaveValor) comboCursos.getSelectedItem()).getCodigo();
|
||||
|
||||
migrarProyectoCursoMongoDB(codigoProyecto, codigoCursoSeleccionado);
|
||||
}
|
||||
});
|
||||
|
||||
// Añadir el botón al panel
|
||||
panelBoton.add(botonMigrar);
|
||||
|
||||
// Añadir los paneles al frame
|
||||
frame.add(panelComboBoxes, BorderLayout.CENTER); // Panel con los JComboBox en el centro
|
||||
frame.add(panelBoton, BorderLayout.SOUTH); // Panel con el botón en la parte inferior
|
||||
|
||||
// Hacer visible la ventana
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void migrarProyectoCursoMongoDB(String codigoProyecto, String codigoCurso) {
|
||||
// Define the endpoint URL (Replace with your actual URL)
|
||||
String urlPeticion = "https://proylapaloma.decieloytierra.es/api/ingresos/proyecto/" + codigoProyecto
|
||||
+ "/curso/" + codigoCurso;
|
||||
System.out.println(urlPeticion);
|
||||
|
||||
try {
|
||||
// Crear un cliente HTTP
|
||||
HttpClient client = java.net.http.HttpClient.newHttpClient();
|
||||
|
||||
// Crear una solicitud GET a la API
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(urlPeticion)).build();
|
||||
|
||||
// Enviar la solicitud y obtener la respuesta
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// Comprobar si la respuesta fue exitosa
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println(response.body());
|
||||
} else {
|
||||
System.out.println("Error al obtener los coches: " + response.statusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user