2017-11-12

32: Let's Create a Spread Sheet Cell Editor

<The previous article in this series | The table of contents of this series | The next article in this series>

Main Body START

We Created a Spread Sheet Cell Editor

About: UNO (Universal Network Objects)

About: LibreOffice

About: Apache OpenOffice

About: Java Programming Language

The Use of Our Cell Editor

Here are -Hypothesizer and -Rebutter sitting in front of a computer screen in a room on a brook among some mountains on the Bias planet.

-Hypothesizer

As we know how to implement GUIs in our UNO Extensions, we will create a cell editor. A cell editor is an editor that edits the contents of any spread sheet cell.

-Rebutter

So, our cell editor is to spread sheet cells as usual editors are to files.

-Hypothesizer

Yes. As it is cumbersome to handle long texts inside cells, such a cell editor will be handy when our cells have long texts. You know, a long text doesn't fit even in the pop-up window that is shown by our double-clicking the cell.

-Rebutter

Will we have such long texts in our cells?

-Hypothesizer

Well, . . . I think we can. I mean, if we can handily handle long texts on spread sheets, we can use spread sheets in wider use. That is, we can use spread sheets in any case in which want to organize and handle data in a grid: a long text doesn't need to be fully visible inside the small box of a cell.

-Rebutter

Isn't saying "in any case" an exaggeration?

-Hypothesizer

At this stage, it may, but we could expand our cell editor to make it handle, say images.

-Rebutter

Well, we should say just "wider use" at this stage.

The Design of Our Cell Editor

The same with the previous scene.

-Rebutter

What features will our cell editor have?

-Hypothesizer

We can show the contents of the cell in a wide area, can scroll the text, can see line numbers, can search any specified phrase in the text, can replace any specified phrase in the text with another any specified phrase, can jump to the top or the bottom of the text, can do copying, cutting, pasting, undoing, and redoing, can select the whole of the text, can go to the upper, the lower, the left, or the right cell, . . .

-Rebutter

Are we going to let multiple cell editor windows be shown at the same time?

-Hypothesizer

Well, . . . I thought we would let only one cell editor window be shown at a time: many cell editor windows could clutter the screen . . .

-Rebutter

Two cell editors wouldn't do much harm. I think, it isn't rare that we want to show two cell editor windows at a time, like when we compare the contents of two cells.

-Hypothesizer

Well, if you say so . . .

-Rebutter

On the other hand, we don't have to open a new cell editor window just because we want to edit another cell, do we?

-Hypothesizer

Like I said, we can go to neighboring cells in the existing cell editor window.

-Rebutter

Only neighboring cells?

-Hypothesizer

Well, . . . of course we will also have to able to jump to an arbitrary cell. . . . We will implement a reconnect button, which reconnects the cell editor window to the current cell on the spread sheet.

-Rebutter

Please elaborate on the relationship between the current cell on the spread sheet and the cell that a cell editor window is connected to.

-Hypothesizer

When a cell editor window is newly opened, the cell editor window is connected to the current cell on the spread sheet. Just selecting another cell on the spread sheet doesn't make the cell editor window reconnect to the new current cell. Doing certain operations on the cell editor window make the cell editor reconnect to another cell.

-Rebutter

By certain operations you mean, say clicking a 'Go to the Right Cell' or the reconnect button?

-Hypothesizer

Yes. Clicking a 'Save' button saves the contents to the connected cell, which isn't necessarily the current cell on the spread sheet.

-Rebutter

Can't you let a cell editor window automatically reconnect to the current cell on the spread sheet as the cell selection on the spread sheet is changed?

-Hypothesizer

That would be meaningless when multiple cell editor windows are shown: all the cell editor window would connect to the same cell.

-Rebutter

I didn't tell you to make all the cell editor windows reconnect to the current cell on the spread sheet without question.

-Hypothesizer

Um? . . . Ah, we can implement a check box that specifies whether the cell editor window should automatically reconnect to the current cell on the spread sheet . . .

Well, I would be able to do so, but . . . I would like to put off that feature to the future. I mean, we have to investigate how best we can detect changes of the selection of cells.

-Rebutter

All right.

I wonder whether the cell editor window shouldn't be able to set the contents to a cell that isn't the connected cell . . .

-Hypothesizer

Um? Why won't we reconnect to the cell to which we want to set the contents?

-Rebutter

That will clear the contents of the previously-connected cell on the cell editor window, won't it?

-Hypothesizer

Ah, so, you want to copy the value of a cell to another cell . . .

-Rebutter

I don't particularly want to do so. I just thought that there might be such necessity, in general.

-Hypothesizer

OK. We will implement that feature. Maybe, our cell editor should be able to set the selected text on the cell editor window to the current cell on the spread sheet. If nothing is selected on the cell editor window, the whole text will be set to the current cell on the spread sheet.

-Hypothesizer

At this stage, the outward appearance of our cell editor is this.

-Hypothesizer shows an image of the cell editor on the computer screen.

-Rebutter

. . . It seems difficult to identify which button is of which function . . .

-Hypothesizer

I know. I don't particularly boast that the appearance is slick. Usually, buttons have icons, but I didn't take time to draw appropriate icons. . . . Well, maybe, we would put icons on those buttons, in future.

-Rebutter

There is a button whose caption is 'Go to ...' . . .. Go to where? Where would I be taken to, if I dare to push such an enigmatic button? And there is another button of the same caption beneath it . . .

-Hypothesizer

Ah, I brutally cut short long explanations of buttons. It's a temporary measure before we put on icons. . . . Anyway, hover the mouse cursor over the buttons, and see the tool tips.

-Rebutter

Well, then, I will have to wait until I see the real window.

The Implementation of Our Cell Editor

The same with the previous scene.

-Hypothesizer

As for the implementation, there is nothing to say in respect to UNO: how to read from and write to spread sheet cells are already dealt with; the rest is about just Java, especially Swing, programming. As for some observations we had in the implementation process, we would note them in the series, 'Java Tips'.

-Rebutter

All right.

-Hypothesizer

Our program is here. That is the project we used in the preceding article. How to use the zip file is written there.

-Rebutter

You have replaced the dummy window in the preceding article with the one you have created in this article.

-Hypothesizer

Let's build the projects, and test the cell editor.

-Hypothesizer runs the gradle command, which finishes successfully. -Hypothesizer opens the 'TestSpreadSheetsDocumentForExecutingTests.ods' spread sheets document file. -Hypothesizer clicks the 'Show Test Control Panel' button; a tiny dialog box shows adjacent to the left border of the current LibreOffice frame. -Hypothesizer clicks the 'Edit Cell' button; a cell editor window opens.

-Rebutter

Well, it showed.

-Hypothesizer

Of course . . .

-Rebutter does some operations on the cell editor window.

-Rebutter

Hmm . . .

-Hypothesizer

What?

-Rebutter

When the cell editor window is connected to a date type cell and I edit and save the contents of a legal date, it is saved as a date.

-Hypothesizer

Yes. That is my intention.

-Rebutter

But when I edit and save the contents of an illegal date, for example '2017-13-01', it is saved as a string.

-Hypothesizer

Ah, as we can't convert the text to a date, it is inevitable.

-Rebutter

Warning may be kinder than brutally changing it to a string cell.

-Hypothesizer

Well, it may.

-Rebutter

And when I save a number text, for example '123', to an empty cell, it is saved as a string value.

-Hypothesizer

Well, it is. Any empty cell is treated as a string cell . . .

Hmm, as I have intended our cell editor basically for editing long texts, wanting to save contents as date cells, number cells, etc, wasn't in my expectations, much. Certainly, our cell editor can edit cells that have already date values, etc, with the cell types preserved, but making an empty cell, say a number cell wasn't in my scope. . . . Well, we will improve the cell editor in that respect in future.

-Rebutter

This is just a first version; we can improve it gradually.

By the way, what is this button that has the tool tip of 'Save Compressed'?

-Hypothesizer

That is a button that will save the contents text to the cell with the contents compressed. You know, when a cell has a very long text, LibreOffice program instance can slow down, greatly.

-Rebutter

The button is disabled. Whey will it be enabled?

-Hypothesizer

In future. It isn't implemented yet.

Main Body END

<The previous article in this series | The table of contents of this series | The next article in this series>