Index: dlg/dlgIndex.cpp
===================================================================
--- dlg/dlgIndex.cpp	(revision 7503)
+++ dlg/dlgIndex.cpp	(working copy)
@@ -30,22 +30,18 @@
 #define txtWhere        CTRL_TEXT("txtWhere")
 #define txtFillFactor   CTRL_TEXT("txtFillFactor")
 
-#define btnAddCol       CTRL_BUTTON("btnAddCol")
-#define btnRemoveCol    CTRL_BUTTON("btnRemoveCol")
+#define chkDesc         CTRL_CHECKBOX("chkDesc")
+//#define rdbNulls        CTRL_RADIOBOX("rdbNulls")
+#define rdbNullsFirst   CTRL_RADIOBUTTON("rdbNullsFirst")
+#define rdbNullsLast    CTRL_RADIOBUTTON("rdbNullsLast")
 
 
-
 BEGIN_EVENT_TABLE(dlgIndexBase, dlgCollistProperty)
     EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
     EVT_COMBOBOX(XRCID("cbTablespace"),             dlgProperty::OnChange)
     EVT_TEXT(XRCID("txtFillFactor"),                dlgProperty::OnChange)
-    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndexBase::OnAddCol)
-    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndexBase::OnRemoveCol)
     EVT_LIST_ITEM_SELECTED(XRCID("lstColumns"),     dlgIndexBase::OnSelectListCol)
     EVT_COMBOBOX(XRCID("cbColumns"),                dlgIndexBase::OnSelectComboCol)
-#ifdef __WXMAC__
-    EVT_SIZE(                                       dlgIndexBase::OnChangeSize)
-#endif
 END_EVENT_TABLE();
 
 
@@ -60,8 +56,6 @@
 {
     index=node;
     wxASSERT(!table || table->GetMetaType() == PGM_TABLE);
-
-    lstColumns->CreateColumns(0, _("Columns"), wxT(""), 0);
 }
 
 
@@ -69,8 +63,6 @@
 : dlgCollistProperty(f, frame, resName, colList)
 {
     index=0;
-    
-    lstColumns->CreateColumns(0, _("Columns"), wxT(""), 0);
 }
 
 
@@ -82,7 +74,6 @@
 
 int dlgIndexBase::Go(bool modal)
 {
-    int returncode;
 
     if (index)
     {
@@ -90,10 +81,6 @@
         txtName->Disable();
         cbColumns->Disable();
 
-		wxArrayString colsArr = index->GetColumnList();
-		for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
-			lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
-
         if (txtFillFactor)
         {
             txtFillFactor->SetValue(index->GetFillFactor());
@@ -116,48 +103,9 @@
     btnAddCol->Disable();
     btnRemoveCol->Disable();
 
-    returncode = dlgCollistProperty::Go(modal);
-
-    #ifdef __WXMAC__
-    wxSizeEvent event(wxSize(GetSize().GetWidth() - 25, GetSize().GetHeight() + 200));
-    OnChangeSize(event);
-    #endif
-
-    return returncode;
+    return dlgCollistProperty::Go(modal);
 }
 
-
-void dlgIndexBase::OnAddCol(wxCommandEvent &ev)
-{
-    wxString col=cbColumns->GetValue();
-    if (!col.IsEmpty())
-    {
-        lstColumns->InsertItem(lstColumns->GetItemCount(), col, columnFactory.GetIconId());
-        cbColumns->Delete(cbColumns->GetCurrentSelection());
-        if (cbColumns->GetCount())
-            cbColumns->SetSelection(0);
-
-        CheckChange();
-        if (!cbColumns->GetCount())
-            btnAddCol->Disable();
-    }
-}
-
-
-void dlgIndexBase::OnRemoveCol(wxCommandEvent &ev)
-{
-    long pos=lstColumns->GetSelection();
-    if (pos >= 0)
-    {
-        wxString col=lstColumns->GetItemText(pos);
-        lstColumns->DeleteItem(pos);
-        cbColumns->Append(col);
-
-        CheckChange();
-        btnRemoveCol->Disable();
-    }
-}
-
 void dlgIndexBase::OnSelectListCol(wxListEvent &ev)
 {
     OnSelectCol();
@@ -185,19 +133,7 @@
         btnAddCol->Enable(false);
 }
 
-#ifdef __WXMAC__
-void dlgIndexBase::OnChangeSize(wxSizeEvent &ev)
-{
-	lstColumns->SetSize(wxDefaultCoord, wxDefaultCoord,
-	    ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
-    if (GetAutoLayout())
-    {
-        Layout();
-    }
-}
-#endif
 
-
 void dlgIndexBase::CheckChange()
 {
     if (index)
@@ -215,32 +151,23 @@
 }
 
 
-wxString dlgIndexBase::GetColumns()
-{
-    wxString sql;
-
-    int pos;
-    // iterate cols
-    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
-    {
-        if (pos)
-            sql += wxT(", ");
-
-        sql += qtIdent(lstColumns->GetItemText(pos));
-    }
-    return sql;
-}
-
-
 BEGIN_EVENT_TABLE(dlgIndex, dlgIndexBase)
-    EVT_TEXT(XRCID("cbTablespace"),                 dlgProperty::OnChange)
+    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndex::OnAddCol)
+    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndex::OnRemoveCol)
     EVT_CHECKBOX(XRCID("chkClustered"),             dlgProperty::OnChange)
+    EVT_CHECKBOX(XRCID("chkDesc"),                  dlgIndex::OnDescChange)
+#ifdef __WXMAC__
+    EVT_SIZE(                                       dlgIndex::OnChangeSize)
+#endif
 END_EVENT_TABLE();
 
         
 dlgIndex::dlgIndex(pgaFactory *f, frmMain *frame, pgIndex *index, pgTable *parentNode)
 : dlgIndexBase(f, frame, wxT("dlgIndex"), index, parentNode)
 {
+    lstColumns->AddColumn(_("Column name"), 90);
+    lstColumns->AddColumn(_("Order"), 40);
+    lstColumns->AddColumn(_("NULLs Order"), 50);
 }
 
 
@@ -272,6 +199,34 @@
 }
 
 
+wxString dlgIndex::GetColumns()
+{
+    wxString sql;
+
+    int pos;
+    // iterate cols
+    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
+    {
+        if (pos)
+            sql += wxT(", ");
+
+        sql += qtIdent(lstColumns->GetItemText(pos));
+
+        if (this->database->BackendMinimumVersion(8, 3))
+        {
+            wxString order = lstColumns->GetText(pos, 1);
+            if (!order.IsEmpty())
+                sql += wxT(" ") + order;
+
+            wxString nullsOrder = lstColumns->GetText(pos, 2);
+            if (!nullsOrder.IsEmpty())
+                sql += wxT(" NULLS ") + nullsOrder;
+        }
+    }
+    return sql;
+}
+
+
 int dlgIndex::Go(bool modal)
 {
     if (!connection->BackendMinimumVersion(7, 4))
@@ -280,7 +235,53 @@
     if (index)
     {
         // edit mode: view only
-        
+
+		wxArrayString colsArr = index->GetColumnList();
+        if (this->database->BackendMinimumVersion(8, 3))
+        {
+            wxString colDef, colRest, colName, descDef, nullsDef;
+            const wxString firstOrder = wxT(" NULLS FIRST"), lastOrder = wxT(" NULLS LAST"), descOrder = wxT(" DESC");
+
+            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
+            {
+                colDef = colsArr.Item(colIdx);
+
+                if (colDef.EndsWith(firstOrder.GetData(), &colRest))
+                {
+                    colDef = colRest;
+                    nullsDef = wxT("FIRST");
+                }
+                else if (colDef.EndsWith(lastOrder.GetData(), &colRest))
+                {
+                    colDef = colRest;
+                    nullsDef = wxT("LAST");
+                }
+                else
+                    nullsDef = wxT("");
+
+                if (colDef.EndsWith(descOrder.GetData(), &colRest))
+                {
+                    colDef = colRest;
+                    descDef = wxT("DESC");
+                    if (nullsDef.IsEmpty())
+                        nullsDef = wxT("FIRST");
+                }
+                else
+                {
+                    descDef = wxT("ASC");
+                    if (nullsDef.IsEmpty())
+                        nullsDef = wxT("LAST");
+                }
+
+			    lstColumns->InsertItem(colIdx, colDef, columnFactory.GetIconId());
+                lstColumns->SetItem(colIdx, 1, descDef);
+                lstColumns->SetItem(colIdx, 2, nullsDef);
+            }
+        }
+        else
+            for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
+			    lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
+
         cbType->Append(index->GetIndexType());
         chkUnique->SetValue(index->GetIsUnique());
         chkClustered->SetValue(index->GetIsClustered());
@@ -291,6 +292,9 @@
         chkUnique->Disable();
         chkConcurrent->Disable();
         PrepareTablespace(cbTablespace, index->GetTablespaceOid());
+        chkDesc->Disable();
+        rdbNullsFirst->Disable();
+        rdbNullsLast->Disable();
     }
     else
     {
@@ -312,14 +316,102 @@
         if (!this->database->BackendMinimumVersion(8, 2))
             chkConcurrent->Disable();
 
+        if (!this->database->BackendMinimumVersion(8, 3))
+        {
+            chkDesc->Disable();
+            rdbNullsFirst->Disable();
+            rdbNullsLast->Disable();
+        }
+
         // Add the default tablespace 
         cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
         cbTablespace->SetSelection(0);
     }
-    return dlgIndexBase::Go(modal);
+
+    int returnCode = dlgIndexBase::Go(modal);
+
+    #ifdef __WXMAC__
+    wxSizeEvent event(wxSize(GetSize().GetWidth() - 25, GetSize().GetHeight() + 200));
+    OnChangeSize(event);
+    #endif
+
+    return returnCode;
 }
-       
 
+
+void dlgIndex::OnAddCol(wxCommandEvent &ev)
+{
+    wxString colName=cbColumns->GetValue();
+
+    if (!colName.IsEmpty())
+    {
+        long colIndex = lstColumns->InsertItem(lstColumns->GetItemCount(), colName, columnFactory.GetIconId());
+
+        if (this->database->BackendMinimumVersion(8, 3))
+        {
+            if (chkDesc->GetValue())
+            {
+                lstColumns->SetItem(colIndex, 1, wxT("DESC"));
+
+                if (rdbNullsLast->GetValue())
+                    lstColumns->SetItem(colIndex, 2, wxT("LAST"));
+                else
+                    lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
+            }
+            else
+            {
+                lstColumns->SetItem(colIndex, 1, wxT("ASC"));
+
+                if (rdbNullsFirst->GetValue())
+                    lstColumns->SetItem(colIndex, 2, wxT("FIRST"));
+                else
+                    lstColumns->SetItem(colIndex, 2, wxT("LAST"));
+            }
+
+            // back to default value
+            chkDesc->SetValue(false);
+            rdbNullsFirst->SetValue(false);
+            rdbNullsLast->SetValue(false);
+        }
+
+        cbColumns->Delete(cbColumns->GetCurrentSelection());
+        if (cbColumns->GetCount())
+            cbColumns->SetSelection(0);
+
+        CheckChange();
+        if (!cbColumns->GetCount())
+            btnAddCol->Disable();
+    }
+}
+
+
+void dlgIndex::OnRemoveCol(wxCommandEvent &ev)
+{
+    long pos=lstColumns->GetSelection();
+    if (pos >= 0)
+    {
+        wxString colName=lstColumns->GetItemText(pos);
+
+        lstColumns->DeleteItem(pos);
+        cbColumns->Append(colName);
+
+        CheckChange();
+        btnRemoveCol->Disable();
+    }
+}
+
+#ifdef __WXMAC__
+void dlgIndex::OnChangeSize(wxSizeEvent &ev)
+{
+	lstColumns->SetSize(wxDefaultCoord, wxDefaultCoord,
+	    ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 700);
+    if (GetAutoLayout())
+    {
+        Layout();
+    }
+}
+#endif
+
 wxString dlgIndex::GetSql()
 {
     wxString sql;
@@ -392,3 +484,17 @@
     return obj;
 }
 
+void dlgIndex::OnDescChange(wxCommandEvent &ev)
+{
+    if (rdbNullsFirst->GetValue() || rdbNullsLast->GetValue())
+        return;
+
+    if (chkDesc->GetValue())
+    {
+        rdbNullsFirst->SetValue(true);
+    }
+    else
+    {
+        rdbNullsLast->SetValue(true);
+    }
+}
\ No newline at end of file
Index: dlg/dlgIndexConstraint.cpp
===================================================================
--- dlg/dlgIndexConstraint.cpp	(revision 7503)
+++ dlg/dlgIndexConstraint.cpp	(working copy)
@@ -23,22 +23,48 @@
 #include "schema/pgIndexConstraint.h"
 
 
-
 #define cbTablespace    CTRL_COMBOBOX("cbTablespace")
 
+BEGIN_EVENT_TABLE(dlgIndexConstraint, dlgIndexBase)
+    EVT_BUTTON(XRCID("btnAddCol"),                  dlgIndexConstraint::OnAddCol)
+    EVT_BUTTON(XRCID("btnRemoveCol"),               dlgIndexConstraint::OnRemoveCol)
+#ifdef __WXMAC__
+    EVT_SIZE(                                       dlgIndexConstraint::OnChangeSize)
+#endif
+END_EVENT_TABLE();
 
+
 dlgIndexConstraint::dlgIndexConstraint(pgaFactory *f, frmMain *frame, const wxString &resName, pgIndexBase *index, pgTable *parentNode)
 : dlgIndexBase(f, frame, resName, index, parentNode)
 {
+    lstColumns->CreateColumns(0, _("Columns"), wxT(""), 0);
 }
 
 
 dlgIndexConstraint::dlgIndexConstraint(pgaFactory *f, frmMain *frame, const wxString &resName, ctlListView *colList)
 : dlgIndexBase(f, frame, resName, colList)
 {
+    lstColumns->CreateColumns(0, _("Columns"), wxT(""), 0);
 }
 
 
+wxString dlgIndexConstraint::GetColumns()
+{
+    wxString sql;
+
+    int pos;
+    // iterate cols
+    for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++)
+    {
+        if (pos)
+            sql += wxT(", ");
+
+        sql += qtIdent(lstColumns->GetItemText(pos));
+    }
+    return sql;
+}
+
+
 int dlgIndexConstraint::Go(bool modal)
 {
     PrepareTablespace(cbTablespace);
@@ -47,6 +73,10 @@
     {
         pgIndexConstraint *idc=(pgIndexConstraint*)index;
 
+        wxArrayString colsArr = index->GetColumnList();
+        for (int colIdx=0,colsCount=colsArr.Count(); colIdx<colsCount; colIdx++)
+            lstColumns->InsertItem(colIdx, colsArr.Item(colIdx), columnFactory.GetIconId());
+
         if (idc->GetTablespaceOid() != 0)
             cbTablespace->SetKey(idc->GetTablespaceOid());
         cbTablespace->Enable(connection->BackendMinimumVersion(8, 0));
@@ -65,10 +95,61 @@
         cbTablespace->SetSelection(0);
     }
 
-    return dlgIndexBase::Go(modal);
+    int returnCode = dlgIndexBase::Go(modal);
+
+    #ifdef __WXMAC__
+    wxSizeEvent event(wxSize(GetSize().GetWidth() - 25, GetSize().GetHeight() + 200));
+    OnChangeSize(event);
+    #endif
+
+    return returnCode;
 }
 
 
+void dlgIndexConstraint::OnAddCol(wxCommandEvent &ev)
+{
+    wxString col=cbColumns->GetValue();
+    if (!col.IsEmpty())
+    {
+        lstColumns->InsertItem(lstColumns->GetItemCount(), col, columnFactory.GetIconId());
+        cbColumns->Delete(cbColumns->GetCurrentSelection());
+        if (cbColumns->GetCount())
+            cbColumns->SetSelection(0);
+
+        CheckChange();
+        if (!cbColumns->GetCount())
+            btnAddCol->Disable();
+    }
+}
+
+
+void dlgIndexConstraint::OnRemoveCol(wxCommandEvent &ev)
+{
+    long pos=lstColumns->GetSelection();
+    if (pos >= 0)
+    {
+        wxString col=lstColumns->GetItemText(pos);
+        lstColumns->DeleteItem(pos);
+        cbColumns->Append(col);
+
+        CheckChange();
+        btnRemoveCol->Disable();
+    }
+}
+
+#ifdef __WXMAC__
+void dlgIndexConstraint::OnChangeSize(wxSizeEvent &ev)
+{
+    lstColumns->SetSize(wxDefaultCoord, wxDefaultCoord,
+        ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
+    if (GetAutoLayout())
+    {
+        Layout();
+    }
+}
+#endif
+
+
 wxString dlgIndexConstraint::GetDefinition()
 {
     wxString sql;
Index: include/dlg/dlgIndex.h
===================================================================
--- include/dlg/dlgIndex.h	(revision 7503)
+++ include/dlg/dlgIndex.h	(working copy)
@@ -19,6 +19,9 @@
 class pgIndex;
 class pgIndexBase;
 
+#define btnAddCol       CTRL_BUTTON("btnAddCol")
+#define btnRemoveCol    CTRL_BUTTON("btnRemoveCol")
+
 class dlgIndexBase : public dlgCollistProperty
 {
 public:
@@ -30,20 +33,12 @@
     void OnSelectCol();
     void CheckChange();
     pgObject *GetObject();
-    wxString GetColumns();
     int Go(bool modal);
 
 protected:
     pgIndexBase *index;
 
 private:
-#ifdef __WXMAC__
-    void OnChangeSize(wxSizeEvent &ev);
-#endif
-
-    void OnAddCol(wxCommandEvent &ev);
-    void OnRemoveCol(wxCommandEvent &ev);
-
     DECLARE_EVENT_TABLE()
 };
 
@@ -55,10 +50,19 @@
 
     int Go(bool modal);
     void CheckChange();
+    wxString GetColumns();
     wxString GetSql();
     pgObject *CreateObject(pgCollection *collection);
 
 private:
+#ifdef __WXMAC__
+    void OnChangeSize(wxSizeEvent &ev);
+#endif
+
+    void OnDescChange(wxCommandEvent &ev);
+    void OnAddCol(wxCommandEvent &ev);
+    void OnRemoveCol(wxCommandEvent &ev);
+
     DECLARE_EVENT_TABLE()
 };
 
Index: include/dlg/dlgIndexConstraint.h
===================================================================
--- include/dlg/dlgIndexConstraint.h	(revision 7503)
+++ include/dlg/dlgIndexConstraint.h	(working copy)
@@ -34,9 +34,19 @@
 
     int Go(bool modal);
     wxString GetDefinition();
+    wxString GetColumns();
     wxString GetSql();
     wxString GetHelpPage() const { return wxT("pg/sql-altertable"); }
 
+private:
+#ifdef __WXMAC__
+    void OnChangeSize(wxSizeEvent &ev);
+#endif
+
+    void OnAddCol(wxCommandEvent &ev);
+    void OnRemoveCol(wxCommandEvent &ev);
+
+    DECLARE_EVENT_TABLE()
 };
 
 
Index: ui/dlgIndex.xrc
===================================================================
--- ui/dlgIndex.xrc	(revision 7503)
+++ ui/dlgIndex.xrc	(working copy)
@@ -172,6 +172,7 @@
             <object class="wxPanel" name="pnlColumns">
               <object class="wxFlexGridSizer">
                 <cols>1</cols>
+                <rows>4</rows>
                 <growablecols>0</growablecols>
                 <growablerows>0</growablerows>
                 <object class="sizeritem">
@@ -183,15 +184,85 @@
                 </object>
                 <object class="sizeritem">
                   <object class="wxFlexGridSizer">
-                    <cols>5</cols>
-                    <growablecols>0</growablecols>
+                    <cols>2</cols>
+                    <rows>2</rows>
+                    <vgap>5</vgap>
+                    <hgap>5</hgap>
+                    <growablecols>1</growablecols>
+                    <growablerows>0</growablerows>
                     <object class="sizeritem">
+                      <object class="wxStaticText" name="stColumns">
+                        <label>Column</label>
+                      </object>
+                      <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                      <border>4</border>
+                    </object>
+                    <object class="sizeritem">
                       <object class="wxComboBox" name="cbColumns">
                         <content/>
                         <style>wxCB_READONLY|wxCB_DROPDOWN</style>
                       </object>
-                      <flag>wxGROW|wxALIGN_CENTRE_VERTICAL</flag>
+                      <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                      <border>4</border>
                     </object>
+                    <object class="sizeritem">
+                      <object class="wxStaticText" name="stDesc">
+                        <label>DESC</label>
+                      </object>
+                      <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                      <border>4</border>
+                    </object>
+                    <object class="sizeritem">
+                      <object class="wxFlexGridSizer">
+                        <cols>4</cols>
+                        <rows>1</rows>
+                        <object class="sizeritem">
+                          <object class="wxCheckBox" name="chkDesc">
+                            <label></label>
+                          </object>
+                          <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT</flag>
+                          <border>4</border>
+                        </object>
+                        <object class="spacer">
+                          <size>15,3d</size>
+                        </object>
+                        <object class="sizeritem">
+                          <object class="wxStaticText" name="stNulls">
+                            <label>NULLS</label>
+                          </object>
+                          <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                          <border>4</border>
+                        </object>
+                        <object class="sizeritem">
+                          <object class="wxFlexGridSizer">
+                            <cols>2</cols>
+                            <object class="sizeritem">
+                              <object class="wxRadioButton" name="rdbNullsFirst">
+                                <label>FIRST</label>
+                                <style>wxRB_GROUP</style>
+                              </object>
+                            </object>
+                            <object class="sizeritem">
+                              <object class="wxRadioButton" name="rdbNullsLast">
+                                <label>LAST</label>
+                              </object>
+                            </object>
+                          </object>
+                          <flag>wxTOP</flag>
+                          <border>5</border>
+                        </object>
+                      </object>
+                      <flag>wxEXPAND|wxALL</flag>
+                      <border>4</border>
+                    </object>
+                  </object>
+                  <flag>wxEXPAND|wxALL</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxFlexGridSizer">
+                    <cols>4</cols>
+                    <growablecols>0</growablecols>
                     <object class="spacer">
                       <size>3,3d</size>
                     </object>