13d1d069cbacb42b79f6280e34f2311f867ffefd
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / NextSequenceAction.java
1 package com.quantum.actions;
2
3 import org.eclipse.ui.IViewPart;
4
5 import com.quantum.Messages;
6 import com.quantum.QuantumPlugin;
7 import com.quantum.adapters.DatabaseAdapter;
8 import com.quantum.model.Bookmark;
9 import com.quantum.sql.SQLResults;
10 import com.quantum.view.ViewHelper;
11 import com.quantum.view.bookmark.EntityNode;
12 import com.quantum.view.tableview.TableView;
13
14 public class NextSequenceAction extends BaseSequenceAction {
15     
16     /**
17      * @param text
18      * @param view
19      */
20     public NextSequenceAction(IViewPart view) {
21         super(Messages.getString(NextSequenceAction.class.getName() + ".text"), view);
22         setImageDescriptor(QuantumPlugin.getImageDescriptor("append.gif"));    
23     }
24     
25         public void run() {
26                 EntityNode sequence = getEntityNode();
27                 String name = null;
28                 if (sequence.isSequence()) {
29                         Bookmark bookmark = sequence.getBookmark();
30                         DatabaseAdapter adapter = bookmark.getAdapter();
31                         if (adapter == null) return;
32                         name = sequence.getName();
33                         String query = adapter.getNextValue(name, sequence.getEntity().getSchema());
34                         
35                         SQLResults results = ViewHelper.tryGetResults(view, getConnection(), query);
36                         if (results != null && ! results.isError()) 
37                                 TableView.getInstance().loadQuery(bookmark, results);
38                 }
39         }
40 }