Skip to content

Commit

Permalink
added button save all
Browse files Browse the repository at this point in the history
  • Loading branch information
baslo2 committed Jul 15, 2024
1 parent d3d445c commit 3616dff
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/ru/taximaxim/treeviewer/ExtendedTreeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import ru.taximaxim.pgsqlblocks.modules.db.controller.DBController;
import ru.taximaxim.pgsqlblocks.xmlstore.ColumnLayoutsXmlStore;
import ru.taximaxim.treeviewer.dialog.ColumnConfigDialog;
import ru.taximaxim.treeviewer.dialog.SaveDialog;
import ru.taximaxim.treeviewer.filter.FilterChangeHandler;
import ru.taximaxim.treeviewer.filter.FilterComposite;
import ru.taximaxim.treeviewer.l10n.TreeViewer;
Expand Down Expand Up @@ -132,6 +133,17 @@ private void createToolItems() {
configColumnToolItem.setImage(ImageUtils.getImage(Images.TABLE));
configColumnToolItem.setToolTipText(Images.TABLE.getDescription(resourceBundle));
configColumnToolItem.addListener(SWT.Selection, event -> openConfigColumnDialog());

if (isBlockJournalTab) {
ToolItem saveJournals = new ToolItem(toolBar, SWT.PUSH);
saveJournals.setImage(ImageUtils.getImage(Images.SAVE_ALL));
saveJournals.setToolTipText(Images.SAVE_ALL.getDescription(resourceBundle));
saveJournals.addListener(SWT.Selection, event -> openSaveDialog());
}
}

private void openSaveDialog() {
new SaveDialog(resourceBundle, controller, getShell()).open();
}

private void openFilter() {
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/ru/taximaxim/treeviewer/dialog/SaveDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright 2017-2024 TAXTELECOM, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package ru.taximaxim.treeviewer.dialog;

import java.util.List;
import java.util.ResourceBundle;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import ru.taximaxim.pgsqlblocks.common.models.DBBlocksJournalProcess;
import ru.taximaxim.pgsqlblocks.modules.db.controller.DBController;
import ru.taximaxim.pgsqlblocks.utils.ImageUtils;
import ru.taximaxim.pgsqlblocks.utils.Images;
import ru.taximaxim.pgsqlblocks.utils.PathBuilder;
import ru.taximaxim.pgsqlblocks.xmlstore.DBBlocksXmlStore;

public class SaveDialog extends Dialog {

private final ResourceBundle bundle;
private final DBController controller;
private Text path;

public SaveDialog(ResourceBundle bundle, DBController controller, Shell parent) {
super(parent);
this.bundle = bundle;
this.controller = controller;
}

@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(bundle.getString("save_all"));
}

@Override
protected Control createDialogArea(Composite parent) {
Composite c = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(2, false);
layout.marginRight = 5;
layout.marginLeft = 10;
c.setLayout(layout);
path = new Text(c, SWT.BORDER);

path.setText(PathBuilder.getInstance().getBlocksJournalsDir().toString());
path.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));

Button btnDir = new Button(c, SWT.PUSH);
btnDir.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true));
btnDir.setImage(ImageUtils.getImage(Images.FOLDER));
btnDir.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText(bundle.getString("choose_dir"));
dialog.setFilterPath(PathBuilder.getInstance().getBlocksJournalsDir().toString());
String p = dialog.open();
if (p != null) {
path.setText(p);
}
}
});
return c;
}

@Override
protected void okPressed() {
List<DBBlocksJournalProcess> list = controller.getBlocksJournal().getProcesses();
String p = path.getText();
String fileName = p.substring(p.lastIndexOf('/') + 1);
if (!fileName.endsWith(".xml")) {
MessageBox m = new MessageBox(getShell());
m.setText("wrong file name");
m.setMessage("wrong file name \'" + fileName + "\'. file name must end by \'.xml\'");
m.open();
} else {
DBBlocksXmlStore store = new DBBlocksXmlStore(p);
store.writeObjects(list);
super.okPressed();
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/ru/taximaxim/treeviewer/l10n/TreeViewer_en.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected Object[][] getContents() {
{"all-filter-tooltip", "Filter by filters below using \"contains (~)\""},
{"columns", "Columns"},
{"default_action", "Empty"},
{"save_all", "Save all"},
{"choose_dir", "Choose directory"},
};
}
}
2 changes: 2 additions & 0 deletions src/main/java/ru/taximaxim/treeviewer/l10n/TreeViewer_ru.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected Object[][] getContents() {
{"all-filter-tooltip", "Фильтровать по всем фильтрам снизу используя условие \"содержит (~)\""},
{"columns", "Колонки"},
{"default_action", "Пусто"},
{"save_all", "Сохранить все"},
{"choose_dir", "Выберите директорию"},
};
}
}
3 changes: 2 additions & 1 deletion src/main/java/ru/taximaxim/treeviewer/utils/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum Images {
UPDATE("images/update_16.png", "update"),
CLEAN("images/clean_16.png", "clean"),
FILTER("images/filter.png", "filter"),
TABLE("images/table_16.png", "columns");
TABLE("images/table_16.png", "columns"),
SAVE_ALL("images/save_16.png", "save_all");

private String location;
private String description;
Expand Down

0 comments on commit 3616dff

Please sign in to comment.