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