]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/DebugHandler.java
5d8ec323f5659373b65d9247a91068118e50cdba
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / DebugHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.team.ui.handlers;
13
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.CommentMetadata;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.service.XSupport;
23 import org.simantics.team.Activator;
24 import org.simantics.ui.SimanticsUI;
25 import org.simantics.ui.workbench.handler.AbstractPreferenceHandler;
26
27 public class DebugHandler extends AbstractPreferenceHandler {
28     public DebugHandler() {
29         super(Activator.getDefault());
30     }
31     @Override
32     public Object execute(ExecutionEvent event) throws ExecutionException {
33 //        ISelection sel = HandlerUtil.getCurrentSelection(event);
34 //        IStructuredSelection ss = StructuredSelection.EMPTY;
35 //        if (sel instanceof IStructuredSelection)
36 //            ss = (IStructuredSelection) sel;
37         try {
38             Session s = SimanticsUI.getSession();
39             s.sync(new WriteRequest() {
40                 @Override
41                 public void perform(WriteGraph graph) throws DatabaseException {
42                     XSupport xs = graph.getService(XSupport.class);
43                     //Layer0 l0 = Layer0.getInstance(graph);
44                     Resource r = graph.newResource();
45                     String msg = "Corrupt cluster r=" + r; 
46                     System.out.println(msg);
47                     CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
48                     cm.add(msg);
49                     xs.corruptCluster(r);
50                     Resource rr = graph.newResource();
51                     msg = "Corrupt cluster rr=" + rr;
52                     System.out.println(msg);
53                     cm.add(msg);
54                     xs.corruptCluster(rr);
55                     graph.addMetadata(cm); // Add comment to change set.
56                     //graph.claim(l0.InstanceOf, l0.Inherits, l0.Entity);
57                 }
58             });
59         } catch (DatabaseException e) {
60             e.printStackTrace();
61         }  finally {
62         }
63         return null;
64     }
65 }