use of net.viperfish.journal.framework.OperationWithResult in project vsDiaryWriter by shilongdai.
the class JournalWindow method open.
/**
* Open the window.
*
* @wbp.parser.entryPoint
*/
public void open() {
display = Display.getDefault();
shell = new Shell();
shell.setImage(SWTResourceManager.getImage(JournalWindow.class, "/logo.ico"));
shell.setSize(495, 480);
shell.setText("vsDiary - 6.0.0");
shell.setLayout(new GridLayout(8, false));
errorReporter = new ExceptionDisplayer(shell);
e.addObserver(errorReporter);
searchText = new Text(shell, SWT.BORDER);
searchText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 8, 1));
operationBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
operationBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 8, 1));
newJournal = new ToolItem(operationBar, SWT.NONE);
newJournal.setText(messages.getString("action.add"));
deleteJournal = new ToolItem(operationBar, SWT.NONE);
deleteJournal.setText(messages.getString("action.delete"));
recentLabel = new Label(shell, SWT.NONE);
recentLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
recentLabel.setText(messages.getString("label.dateRange"));
lowerBound = new DateTime(shell, SWT.DROP_DOWN);
Label lblTo = new Label(shell, SWT.NONE);
lblTo.setText(messages.getString("label.dateRangeTo"));
upperBoound = new DateTime(shell, SWT.DROP_DOWN);
search = new SearchJournal();
lowerBound.addSelectionListener(search.createSelectAdapter());
upperBoound.addSelectionListener(search.createSelectAdapter());
searchText.addModifyListener(search.createModifyAdapter());
newJournal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
newJournal();
}
});
deleteJournal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
deleteJournal();
}
});
Menu mainMenu = new Menu(shell, SWT.BAR);
shell.setMenuBar(mainMenu);
MenuItem fileMenu = new MenuItem(mainMenu, SWT.CASCADE);
fileMenu.setText(messages.getString("menu.file"));
Menu menu = new Menu(fileMenu);
fileMenu.setMenu(menu);
MenuItem newEntryMenu = new MenuItem(menu, SWT.NONE);
newEntryMenu.setText(messages.getString("menu.new"));
newEntryMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
newJournal();
}
});
MenuItem exportMenu = new MenuItem(menu, SWT.NONE);
exportMenu.setText(messages.getString("menu.export"));
exportMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
FileDialog exportSelector = new FileDialog(shell);
exportSelector.setOverwrite(true);
exportSelector.setText("Enter a location to export");
exportSelector.open();
if (exportSelector.getFileName() == null || exportSelector.getFileName().length() == 0) {
return;
}
String toExport = new File(exportSelector.getFilterPath(), exportSelector.getFileName()).getAbsolutePath();
if (toExport != null) {
JournalWindow.this.e.submit(f.getExportEntriesOperation(toExport));
}
}
});
MenuItem mntmImport = new MenuItem(menu, SWT.NONE);
mntmImport.setText(messages.getString("menu.import"));
MenuItem exit = new MenuItem(menu, SWT.NONE);
exit.setText(messages.getString("menu.exit"));
exit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
shell.dispose();
}
});
mntmImport.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
FileDialog selecter = new FileDialog(shell);
selecter.setText("Select the file to import");
selecter.open();
if (selecter.getFileName() == null || selecter.getFileName().length() == 0) {
return;
}
String selected = new File(selecter.getFilterPath(), selecter.getFileName()).getAbsolutePath();
if (selected == null || selected.length() == 0) {
return;
}
JournalWindow.this.e.submit(f.getImportEntriesOperation(selected));
search.displayAll();
searchText.setText("");
}
});
MenuItem editMenu = new MenuItem(mainMenu, SWT.CASCADE);
editMenu.setText(messages.getString("menu.edit"));
Menu menu_1 = new Menu(editMenu);
editMenu.setMenu(menu_1);
MenuItem deleteEntryMenu = new MenuItem(menu_1, SWT.NONE);
deleteEntryMenu.setText(messages.getString("menu.delete"));
deleteEntryMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
deleteJournal();
}
});
MenuItem clearEntrieMenu = new MenuItem(menu_1, SWT.NONE);
clearEntrieMenu.setText(messages.getString("menu.clear"));
clearEntrieMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
boolean toClear = MessageDialog.openConfirm(shell, messages.getString("warning.confirm"), messages.getString("warning.clear"));
if (toClear) {
JournalWindow.this.e.submit(f.getClearEntriesOperation());
search.searchJournals();
}
}
});
MenuItem showAllMenu = new MenuItem(menu_1, SWT.NONE);
showAllMenu.setText(messages.getString("menu.showAll"));
showAllMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
search.displayAll();
}
});
MenuItem preferenceMenu = new MenuItem(mainMenu, SWT.CASCADE);
preferenceMenu.setText(messages.getString("menu.settings"));
Menu settingMenu = new Menu(preferenceMenu);
preferenceMenu.setMenu(settingMenu);
MenuItem changeConfigMenu = new MenuItem(settingMenu, SWT.NONE);
changeConfigMenu.setText(messages.getString("menu.config"));
changeConfigMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
super.widgetSelected(arg0);
PreferenceDialog pd = new PreferenceDialog(shell, PreferenceGUIManager.getMger());
int result = pd.open();
if (result == Window.OK) {
JournalWindow.this.e.submit(StoreConfigurationBufferOperation.applyOperation());
}
}
});
MenuItem passwordMenu = new MenuItem(settingMenu, SWT.NONE);
passwordMenu.setText(messages.getString("menu.passwd"));
passwordMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
super.widgetSelected(arg0);
ChangePasswordPrompt prompt = new ChangePasswordPrompt();
prompt.open();
}
});
MenuItem helpMenu = new MenuItem(mainMenu, SWT.CASCADE);
helpMenu.setText(messages.getString("menu.help"));
Menu menu_2 = new Menu(helpMenu);
helpMenu.setMenu(menu_2);
MenuItem aboutMenu = new MenuItem(menu_2, SWT.NONE);
aboutMenu.setText(messages.getString("menu.help"));
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
pgTable = new PageableTable(shell, SWT.NONE, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, 10, PageResultContentProvider.getInstance(), null, ResultAndNavigationPageLinksRendererFactory.getFactory());
GridData gd_pgTable = new GridData(SWT.FILL, SWT.FILL, true, true);
gd_pgTable.horizontalSpan = 8;
pgTable.setLayoutData(gd_pgTable);
tableViewer = pgTable.getViewer();
searchResults = tableViewer.getTable();
searchResults.setLayoutData(new GridData(GridData.FILL_BOTH));
tableViewer.setContentProvider(new ArrayContentProvider());
searchResults.setHeaderVisible(true);
searchResults.setLinesVisible(true);
final TableViewerColumn titles = new TableViewerColumn(tableViewer, SWT.NONE);
titles.getColumn().setWidth(200);
titles.getColumn().setText(messages.getString("table.title"));
titles.getColumn().setResizable(true);
titles.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
JournalPointer j = (JournalPointer) element;
return j.getTitle();
}
});
final TableViewerColumn dates = new TableViewerColumn(tableViewer, SWT.NONE);
dates.getColumn().setWidth(200);
dates.getColumn().setResizable(true);
dates.getColumn().setText(messages.getString("table.date"));
dates.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
JournalPointer j = (JournalPointer) element;
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM);
return df.format(j.getDate());
}
});
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent arg0) {
StructuredSelection selected = (StructuredSelection) arg0.getSelection();
if (selected.isEmpty()) {
return;
}
JournalPointer pointer = (JournalPointer) selected.getFirstElement();
OperationWithResult<Journal> get = f.getGetEntryOperation(pointer.getId());
e.submit(get);
Journal result = new JournalEditor().open(get.getResult());
if (result == null) {
return;
}
e.submit(f.getEditContentOperation(result.getId(), result.getContent()));
e.submit(f.getEditSubjectOperation(result.getId(), result.getSubject()));
search.searchJournals();
}
});
aboutMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
MessageDialog.openInformation(shell, messages.getString("menu.about"), "This is an application to write secure and authenticated diary digitally. It is dedicated to Abigail Nunez.");
}
});
shell.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent arg0) {
// TODO Auto-generated method stub
super.controlResized(arg0);
Rectangle area = shell.getClientArea();
Point preferredSize = searchResults.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = area.width - searchResults.getBorderWidth() * 2;
if (preferredSize.y > area.height + searchResults.getHeaderHeight()) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = searchResults.getVerticalBar().getSize();
width -= vBarSize.x;
}
Point oldSize = searchResults.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
titles.getColumn().setWidth(width / 2);
dates.getColumn().setWidth(width - titles.getColumn().getWidth() - 25);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
titles.getColumn().setWidth(width / 2);
dates.getColumn().setWidth(width - titles.getColumn().getWidth() - 25);
}
}
});
search.displayAll();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
Aggregations