Skip to content

Commit 666f75a

Browse files
committed
finished main functions
1 parent 2efd122 commit 666f75a

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>edu.upvictoria.poo</groupId>
4141
<artifactId>ExceptionFramework</artifactId>
42-
<version>1.1</version>
42+
<version>1.2</version>
4343
</dependency>
4444
<dependency>
4545
<groupId>org.controlsfx</groupId>

src/main/java/edu/upvictoria/javasqlide/App.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public void start(Stage stage) {
1515
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("main.fxml"));
1616

1717
Scene scene = new Scene(fxmlLoader.load(), 1280, 800);
18-
stage.setTitle("Java SQL Developer");
1918
scene.getStylesheets().add(Objects.requireNonNull(App.class.getResource("/edu/upvictoria/javasqlide/sql-keywords.css")).toExternalForm());
19+
20+
stage.setTitle("Java SQL Developer");
2021
stage.setScene(scene);
2122
stage.show();
2223
} catch (Exception e){

src/main/java/edu/upvictoria/javasqlide/controllers/IDEController.java

+79-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package edu.upvictoria.javasqlide.controllers;
22

33
import edu.upvictoria.poo.Analyzer;
4+
import edu.upvictoria.poo.Reader;
45
import edu.upvictoria.poo.Column;
56
import edu.upvictoria.poo.Database;
67
import edu.upvictoria.poo.Table;
8+
import javafx.beans.property.SimpleStringProperty;
9+
import javafx.collections.FXCollections;
10+
import javafx.collections.ObservableList;
711
import javafx.event.ActionEvent;
812
import javafx.fxml.FXML;
913
import javafx.scene.control.*;
@@ -13,7 +17,6 @@
1317
import javafx.scene.input.KeyEvent;
1418
import javafx.stage.DirectoryChooser;
1519
import javafx.stage.FileChooser;
16-
import javafx.stage.Stage;
1720
import org.fxmisc.richtext.CodeArea;
1821
import org.fxmisc.richtext.LineNumberFactory;
1922
import org.fxmisc.richtext.model.StyleSpans;
@@ -24,15 +27,13 @@
2427
import java.nio.charset.StandardCharsets;
2528
import java.time.LocalDateTime;
2629
import java.time.format.DateTimeFormatter;
27-
import java.util.ArrayList;
28-
import java.util.Collection;
29-
import java.util.Collections;
30-
import java.util.Objects;
30+
import java.util.*;
3131
import java.util.regex.Matcher;
3232
import java.util.regex.Pattern;
3333

3434
public class IDEController {
3535
private final Analyzer analyzer = new Analyzer();
36+
private final Reader reader = new Reader();
3637
private File file = null;
3738

3839
@FXML
@@ -43,6 +44,8 @@ public class IDEController {
4344
private TextArea errorMessages;
4445
@FXML
4546
private CodeArea codeArea;
47+
@FXML
48+
private TableView<ArrayList<String>> tableView;
4649

4750
private static final String KEYWORD_PATTERN = "\\b(" + String.join("|", Analyzer.getKeywords()) + ")\\b";
4851
private static final String DATATYPES_PATTERN = "\\b(" + String.join("|", Analyzer.getDataTypes()) + ")\\b";
@@ -189,18 +192,86 @@ private void saveTextToFile(String content, File file) {
189192
}
190193

191194
@FXML
192-
protected void executeSelectedStatement(ActionEvent event) {
195+
protected void executeSelectedStatement() {
193196
String selection = codeArea.getSelectedText();
197+
selection = selection.trim();
198+
ArrayList<ArrayList<String>> printableTable = null;
194199

195200
try {
196-
analyzer.analyzeSyntax(selection);
201+
String line = reader.consoleReader(selection);
202+
printableTable = analyzer.analyzeSyntax(line);
197203
} catch (Exception e) {
198204
handleExceptions(e.getMessage());
199205
}
200206

201-
if(file != null) {
207+
if(file != null && analyzer.getDatabase().getDbFile() != null) {
202208
loadTree();
203209
}
210+
211+
if(printableTable != null) {
212+
createTable(printableTable);
213+
}
214+
}
215+
216+
@FXML
217+
protected void executeScript(){
218+
String script = codeArea.getText();
219+
220+
Pattern pattern = Pattern.compile("(?s).*?;");
221+
Matcher matcher = pattern.matcher(script);
222+
223+
ArrayList<String> statements = new ArrayList<>();
224+
while (matcher.find()) {
225+
statements.add(matcher.group().trim());
226+
}
227+
228+
System.out.println(statements);
229+
230+
for(String statement : statements) {
231+
try {
232+
String line = reader.consoleReader(statement);
233+
ArrayList<ArrayList<String>> printableTable = analyzer.analyzeSyntax(line);
234+
235+
if(file != null && analyzer.getDatabase().getDbFile() != null) {
236+
loadTree();
237+
}
238+
239+
if(printableTable != null) {
240+
createTable(printableTable);
241+
}
242+
} catch (Exception e) {
243+
System.out.println(statement);
244+
handleExceptions(e.getMessage());
245+
}
246+
}
247+
}
248+
249+
protected void createTable(ArrayList<ArrayList <String>> data){
250+
SingleSelectionModel<Tab> selectionModel = tabs.getSelectionModel();
251+
selectionModel.select(0);
252+
253+
tableView.getColumns().clear();
254+
tableView.getItems().clear();
255+
256+
ArrayList<String> columnNames = data.get(0);
257+
for (int i = 0; i < columnNames.size(); i++) {
258+
final int colIndex = i;
259+
TableColumn<ArrayList<String>, String> column = new TableColumn<>(columnNames.get(i));
260+
column.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get(colIndex)));
261+
tableView.getColumns().add(column);
262+
}
263+
264+
ObservableList<ArrayList<String>> rows = FXCollections.observableArrayList(data.subList(1, data.size()));
265+
tableView.setItems(rows);
266+
tableView.setVisible(true);
267+
}
268+
269+
@FXML
270+
protected void checkFileChanges(KeyEvent event) {
271+
String codeAreaText = codeArea.getText();
272+
String fileText = getFileContent(file);
273+
274+
204275
}
205276

206277
private StyleSpans<Collection<String>> computeHighlighting(String text) {

src/main/resources/edu/upvictoria/javasqlide/main.fxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<Cursor fx:constant="HAND"/>
4646
</cursor>
4747
</Button>
48-
<Button alignment="CENTER" mnemonicParsing="false" textAlignment="CENTER">
48+
<Button alignment="CENTER" mnemonicParsing="false" onAction="#executeScript" textAlignment="CENTER">
4949
<cursor>
5050
<Cursor fx:constant="HAND"/>
5151
</cursor>
@@ -63,11 +63,11 @@
6363
</Button>
6464
</ToolBar>
6565
<Pane prefHeight="450.0" prefWidth="1062.0">
66-
<CodeArea fx:id="codeArea" layoutX="3.0" layoutY="1.0" prefHeight="435.0" prefWidth="1055.0"/>
66+
<CodeArea fx:id="codeArea" onKeyPressed="#checkFileChanges" layoutX="3.0" layoutY="1.0" prefHeight="435.0" prefWidth="1055.0"/>
6767
</Pane>
6868
<TabPane fx:id="tabs" prefHeight="280.0" prefWidth="1062.0" tabClosingPolicy="UNAVAILABLE">
6969
<Tab text="Statement Output">
70-
<TableView prefHeight="138.0" prefWidth="1062.0" visible="false"/>
70+
<TableView fx:id="tableView" prefHeight="138.0" prefWidth="1062.0" visible="false"/>
7171
</Tab>
7272
<Tab text="Log">
7373
<TextArea fx:id="errorMessages" editable="false" prefHeight="200.0" prefWidth="200.0"/>

0 commit comments

Comments
 (0)