/*
 * Copyright 2006-2020 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 * USA
 */

package io.github.mzmine.parameters.parametertypes;

import java.util.Arrays;
import io.github.mzmine.util.javafx.DraggableListCell;
import javafx.collections.FXCollections;
import javafx.scene.control.ListView;

/**
 * A modified ListView that can reorder items by dragging with mouse
 *
 */
public class OrderComponent<ValueType> extends ListView<ValueType> {

  public OrderComponent() {

    // for some reason, plain JList does not have a border (at least on Mac)
    // Border border = BorderFactory.createEtchedBorder();
    // setBorder(border);

    setCellFactory(param -> new DraggableListCell<ValueType>());

    // Adjust the size of the component
    setPrefWidth(150);
  }

  public void setValues(ValueType newValues[]) {
    setItems(FXCollections.observableArrayList(Arrays.asList(newValues)));
  }

  @SuppressWarnings("unchecked")
  public ValueType[] getValues() {
    return (ValueType[]) getItems().toArray();
  }


}

@@ -834,33 +834,8 @@
 s;%0A%0A
-import java.util.Arrays;%0A
 impo
@@ -885,16 +885,41 @@
 stCell;%0A
+import java.util.Arrays;%0A
 import j
@@ -1386,20 +1386,230 @@
 ell%3C
-ValueType%3E()
+%3E() %7B%0A      @Override%0A      protected void updateItem(ValueType item, boolean empty) %7B%0A        super.updateItem(item, empty);%0A        if(!empty && item != null) %7B%0A          setText(item.toString());%0A        %7D%0A      %7D%0A    %7D
 );%0A%0A

fix order component not showing item text