]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message.ui/src/org/simantics/message/ui/test/TestResourceStatusHandler.java
de7468d8e7dd9b06ea3678c565738fc1a5898246
[simantics/platform.git] / bundles / org.simantics.message.ui / src / org / simantics / message / ui / test / TestResourceStatusHandler.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.message.ui.test;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.ui.handlers.HandlerUtil;
19 import org.simantics.Simantics;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.message.DetailStatus;
23 import org.simantics.message.IDetailStatus;
24 import org.simantics.message.ILogger;
25 import org.simantics.message.MessageService;
26 import org.simantics.message.ReferenceSerializationException;
27 import org.simantics.message.ui.Activator;
28 import org.simantics.message.util.MessageUtil;
29 import org.simantics.ui.utils.ResourceAdaptionUtils;
30
31 /**
32  * @author Tuukka Lehtonen
33  */
34 public class TestResourceStatusHandler extends AbstractHandler {
35
36     @Override
37     public Object execute(ExecutionEvent event) throws ExecutionException {
38         Resource[] rs = ResourceAdaptionUtils.toResources(HandlerUtil.getCurrentSelection(event));
39         ILogger log = MessageService.getDefault();
40     
41         Session s = Simantics.peekSession();
42         if (s == null)
43             return null;
44
45         try {
46             int code = 0;
47             for (Resource r : rs) {
48                 log.log(new DetailStatus(IDetailStatus.DEBUG, Activator.PLUGIN_ID, code++,
49                         "Logged reference to selected resource",
50                         NLS.bind(Messages.Test_message, MessageUtil.resource(s, r, "this link")),
51                         null));
52             }
53         } catch (ReferenceSerializationException e) {
54             e.printStackTrace();
55         }
56         
57         return null;
58     }
59
60 }