package consulo.java.manifest.editor.models;

import org.osmorc.manifest.lang.psi.Header;
import org.osmorc.manifest.lang.psi.ManifestFile;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;

/**
 * @author VISTALL
 * @since 13:40/05.05.13
 */
public class FileTableModel extends ListTableModel<Header> {
  private final ManifestFile myManifestFile;

  public FileTableModel(ManifestFile manifestFile) {
    super(new ColumnInfo.StringColumn(""));
    myManifestFile = manifestFile;
  }

  @Override
  public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
  }

  @Override
  public void setValueAt(final Object aValue, int rowIndex, int columnIndex) {
    final Header rowValue = getRowValue(rowIndex);
    if (rowValue == null) {
      return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        rowValue.setName((String)aValue);
      }
    });
  }

  @Override
  public int getRowCount() {
    return myManifestFile.getHeaders().length;
  }

  @Override
  public Header getRowValue(int row) {
    return myManifestFile.getHeaders()[row];
  }

  @Override
  public Object getValueAt(int rowIndex, int columnIndex) {
    final Header rowValue = getRowValue(rowIndex);
    if (rowValue == null) {
      return "null";
    }
    else {
      return rowValue.getName();
    }
  }
}

@@ -165,38 +165,34 @@
 api.
-application.ApplicationManager
+command.WriteCommandAction
 ;%0Aim
@@ -867,43 +867,26 @@
     
-ApplicationManager.getApplica
+WriteCommandAc
 tion
-()
 .run
@@ -894,15 +894,51 @@
 rite
-Action(
+CommandAction(myManifestFile.getProject(), 
 new 

fix exception