Why table's column names are not displayed here? - swing

I have a problem with seesaw table. When I try to make up and show a simple table, it shows without column names.
What I did:
At first, I must say that I am using [seesaw "1.4.2"].
Then:
;; Clojure 1.4.0
(require '[seesaw.core :as ss])
(ss/native!)
(def main-window
(-> (ss/frame
:title "Main window")
ss/pack!
(ss/config! :minimum-size [320 :by 240])
ss/show!))
(def display
#(ss/config! main-window
:content %))
(display
(ss/table
:id :dumb-table
:model [:columns
[:one :another]
:rows
[["1" "2"]
["3" "4"]]]))
(source: leprosorium.com)
Table appears, but without column names, which, I guess, must be "one" and "another". What went wrong here?
It happens also if I use exactly the same code as in official wiki: https://github.com/daveray/seesaw/wiki/Tables
Update:
I forgot to mention, I'm using JDK 1.7u10, maybe it makes sense.

I dont know how to use seesaw table. but in general you need to add JTable to JScrollPane. This is because JScrollPane makes column header available at the top even when you scroll the data. if you dont want to use JScrollPane then u need to add the column header manually to the container so they stay at the top. So try adding JScrollPane.
Let me know if i went wrong...:)

Well, I think you missed some thing, ( see reference )
(display
(ss/table
:id :dumb-table
:model [:columns
[{:key :one, :text "One~1"}
{:key :one, :text "The Other~2"}]
:rows
[["1" "2"]
["3" "4"]]]))

Related

How can I on-DOMCharacterDataModified with clojurescript regent

I'm currently trying to do :on-DOMCharacterDataModified so that I can see when a [:div] with {:contentEditable true} is edited.
How can I do this or should I be approaching this problem differently? I'm using this type of text input field so that I can highlight parts of the text input with different colors.
:on-input worked and then using (-> e .-target .-innerHTML) or (-> e .-target .-innerText) will get the new value.

Why does reagent not re-render my reagent-form on a state change

I need to create a form containing a select field where the options depend on the currently available mail accounts. I retrieve these mail accounts in a API request after the page has loaded.
The following function creates the form with the select element.
(defn create-options [mail-accounts]
(for [m mail-accounts]
[:option {:key (keyword (str (:id m)))
:value (:id m)}
(:name m)]))
(defn render-mail-account-select [mail-accounts]
(let [form-state (r/atom {})]
(fn [mail-accounts]
(let [form [:form.mailing-form.form-horizontal
(into [:select.form-control {:field :list :id :mail-account}]
(create-options mail-accounts))]]
(pprint form)
[bind-fields form form-state]))))
The pprint gives me the following output:
;; Before the mail-accounts are loaded
[:select.form-control {:field :list, :id :mail-account}]
;; After the state update containing the mail accounts
[:select.form-control
{:field :list, :id :mail-account}
[:option {:key :24, :value 24} "First mail account name"]
[:option {:key :25, :value 25} "Second mail account name"]]
My problem is that the select on my page stays empty as if the select does not get re-rendered.
Addendum
I think I forgot to add some code:
I am wrapping this form in a KIOO component where I dereference my state atom.
(defsnippet choose-account-panel "html/static-panel.html" [:div.panel]
[]
{[:h4.panel-title] (content "3. Mail Account wählen")
[:div.panel-body] (content [render-mail-account-select (:mail-accounts #state)])})
This component then calls my render-mail-account-select function and should re-render the form properly.
You need to dereference a Ratom for Reagent to know which functions need to be called again when that Ratom changes. That dereferencing needs to happen within the anonymous function inside render-mail-account-select, or one of the functions that it calls. I can’t see any dereferencing happening here?
See the docs here for more details on Reagent’s rendering.
As already pointed out, your render function must reference something in your state atom in order to know when it needs to be re-rendered. However, if you also want your displayed form to have a 'default' value selected, you also need to set your state atom.
The bind-fields call will associate your form with the state atom. If there is nothing in the state atom, the form will be 'blank' i.e. none of the elements selected. If this is what you want, then that should be fine. However, if you want a value selected, then you should put that value in the atom. For example, if you wanted the first item to be already selected, then put :24 into the state atom i.e.
(swap! form-state assoc :mail-account :24)
Note that I'm not sure your option definition is correct. The docs seem to indicate that you only need the :key attribute with the value (as a keyword) in that attribute. I've not looked at the source to confirm this, but none of the examples use a :value attribute as well.
If you do the swap at the beginning of your render function, then the state atom will have been referenced and your component should re-render each time it is called with new arguments. When I say 'render function', in this case, I mean the anonymous function, not the outer one which creates the state atom.

Rails form_for setting options and setting selected option

Another simple question i'm sure so sorry in advance but i cant seem to find a solution to what i am trying to do.
I have form with a select field (vehicle_size) that i want to populate with all existing options that are currently in the database for records that have vehicle_size set. I also want to set the selected option to whatever the option in the database is currently set to (if set) but i guess the problem that i am having is the reason that this value isn't being set already.
I currently have this code:
<%= f.select(:vehicle_size, #models.index_by {|m| m.vehicle_size}, :selected => :vehicle_size) %>
which is populating the select options correctly but in my new and edit pages (both using this form) the select menu is blank even though currently all records are be set to one of the existing options (vehicle_size may actually be blank for some records in future).
If i then select an option from the menu and save the record the vehicle_size option has a strange value. something along the lines of :
#<Model:0x007fd13e6c3790>
I'm pretty sure i'm using index_by in the wrong way so some pointers on what i'm missing would be great.
The parameters of f.select are: attribute_name,option_tags,options.
option_tags is supposed to be a string of html option tags.
There are some helpers to construct such a string from i.e. an array of values, a collection etc.: options_for_select, options_from_selection_for_select.
You have to use one of these helpers.
You can get the existing vehicle_sizees with:
Model.pluck(:vehicle_size).uniq
so your select could look like:
<%= f.select :vehicle_size, options_for_select(Model.pluck(:vehicle_size).uniq,#model.vehicle_size) %>
See the Rails Guide on form helpers.

Selection function comments while expanding in Lisp modes

I'm using a keyboard shortcut bound to:
er/expand-region, which is an interactive Lisp function in `expand-region-core.el'.
to expand the region.
For example when I want to select a function and move it around.
My problem is that if I want to select any function like, say:
;; some comment related to the function
(defn foo [x]
...)
I cannot "expand" to include ";; some comment". As soon as I expand more than the function (without the comment) it expends the full buffer.
While I'd like it to first expand to include the function and the comment and then the full buffer.
It's bothering me so much that I'm temporarily doing this as a workaround:
(defn foo [x]
;; some comment
...)
How can I modify er/expand-region (or another function) so that after expanding to the full function it expands the comments right above the function before expanding to the whole buffer?
From Magnar Sveen, the creator of the package expand-region, taken from his github:
Example:
Let's say you want expand-region to also mark paragraphs and pages in
text-mode. Incidentally Emacs already comes with mark-paragraph and
mark-page. To add it to the try-list, do this:
(defun er/add-text-mode-expansions () (make-variable-buffer-local
'er/try-expand-list) (setq er/try-expand-list (append
er/try-expand-list
'(mark-paragraph
mark-page))))
(add-hook 'text-mode-hook 'er/add-text-mode-expansions)
Add that to
its own file, and add it to the expand-region.el-file, where it says
"Mode-specific expansions"
Warning: Badly written expansions might slow down expand-region
dramatically. Remember to exit quickly before you start traversing the
entire document looking for constructs to mark.
I would say you could add "er/mark-paragraph" to the expand-region list, that should do it.
Following user Dualinity's advice, I added the following to clojure-mode-expansions.el (can be done for other modes than Clojure of course) :
;; added this line at the beginning of the file
(require 'org-mode-expansions)
Then I added the line er/mark-paragraph to the expand list inside the er/add-clojure-mode-expansions method:
(defun er/add-clojure-mode-expansions ()
"Adds clojure-specific expansions for buffers in clojure-mode"
(set (make-local-variable 'er/try-expand-list) (append
er/try-expand-list
'(er/mark-clj-word
er/mark-clj-regexp-literal
er/mark-paragraph ; added this line
er/mark-clj-function-literal))))
I restarted Emacs (not too sure as to what was needed to be sure it was taken into account so I restarted the whole thing).
And that's it: now expanding selects "outer" function comments too.

Is it possible to get the selection order of items from a dropdown box generated using collection_select?

Question: Is it possible to get the selection order of items from a dropdown box generated using collection_select?
I am doing the following in a simple form:
<%= f.collection_select(:category_ids, Category.all, :id, :name, {}, html_options = {:multiple => true} ) %>
With this I can get an array of selected Categories, however they are arranged in a top-down order (as they appear in the list).
For example, say I have the following categories:
Red
Green
Blue
Orange
If I pick Green, Orange, Red I would like to get a return array of [2, 4, 1] but I get [1, 2, 4] instead.
I found this post that mentions it's a HTML standard thing for them to be ordered this way. Is there a way around this?
Order of selection in html select multiple?
Of course, there is a word-around. Use a user-action-sensitive language like JavaScript. In such case, use a data structure like associative array, where selection of an option updates the corresponding element and deselection invalidates the element in array.