Search in sources :

Example 16 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class OperationTest method testChangePassword.

@Test
public void testChangePassword() throws FailToSyncEntryException {
    cleanUp();
    addEntries(20, "testPassword");
    new ChangePasswordOperation("newPass").execute();
    Assert.assertEquals("newPass", mger.getPassword());
    for (Journal i : db.getAll()) {
        Assert.assertEquals("testPassword", i.getSubject());
        Assert.assertEquals("testPassword", i.getContent());
    }
    cleanUp();
}
Also used : Journal(net.viperfish.journal.framework.Journal) Test(org.junit.Test)

Example 17 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class OperationTest method testEditContentOperation.

@Test
public void testEditContentOperation() throws FailToSyncEntryException {
    cleanUp();
    Journal test = new Journal();
    test.setSubject("test");
    test.setDate(new Date());
    test.setContent("unedited");
    Journal result = db.addEntry(test);
    Long id = result.getId();
    new EditContentOperation(id, "edited").execute();
    result = db.getEntry(id);
    Assert.assertEquals("edited", result.getContent());
    cleanUp();
}
Also used : Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class JournalWindow method newJournal.

private void newJournal() {
    Journal result = new JournalEditor().open(new Journal());
    if (result == null) {
        return;
    }
    e.submit(f.getAddOperation(result));
    search.searchJournals();
}
Also used : Journal(net.viperfish.journal.framework.Journal)

Example 19 with Journal

use of net.viperfish.journal.framework.Journal 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();
        }
    }
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Rectangle(org.eclipse.swt.graphics.Rectangle) Journal(net.viperfish.journal.framework.Journal) DateTime(org.eclipse.swt.widgets.DateTime) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) JournalPointer(net.viperfish.journal.framework.JournalPointer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) PageableTable(org.eclipse.nebula.widgets.pagination.table.PageableTable) DateFormat(java.text.DateFormat) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) OperationWithResult(net.viperfish.journal.framework.OperationWithResult) ControlEvent(org.eclipse.swt.events.ControlEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 20 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class OperationTest method testAddEntryOperation.

@Test
public void testAddEntryOperation() {
    cleanUp();
    Journal toAdd = new Journal();
    toAdd.setContent("test");
    toAdd.setDate(new Date());
    toAdd.setSubject("test");
    new AddEntryOperation(toAdd).execute();
    toAdd.setId(0L);
    Journal get = db.getEntry(0L);
    Assert.assertEquals("test", get.getSubject());
    Assert.assertEquals("test", get.getContent());
    Assert.assertEquals(toAdd.getDate().getTime(), get.getDate().getTime());
    Assert.assertEquals(toAdd.getId(), get.getId());
    Assert.assertEquals(true, indexer.contains(0L));
    cleanUp();
}
Also used : Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Journal (net.viperfish.journal.framework.Journal)35 Test (org.junit.Test)13 Date (java.util.Date)8 File (java.io.File)7 JournalPointer (net.viperfish.journal.framework.JournalPointer)6 IOException (java.io.IOException)4 FailToSyncEntryException (net.viperfish.journal.framework.errors.FailToSyncEntryException)4 CipherException (net.viperfish.journal.framework.errors.CipherException)3 OperationErrorException (net.viperfish.journal.framework.errors.OperationErrorException)3 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 IOFile (net.viperfish.framework.file.IOFile)2 TextIOStreamHandler (net.viperfish.framework.file.TextIOStreamHandler)2 DatabaseTest (net.viperfish.journal.framework.DatabaseTest)2 FailToStoreCredentialException (net.viperfish.journal.framework.errors.FailToStoreCredentialException)2 ByteBuffer (java.nio.ByteBuffer)1 DateFormat (java.text.DateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 JsonGenerator (net.viperfish.framework.serialization.JsonGenerator)1