1 /*******************************************************************************
\r
2 * Copyright (c) 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.properties.widgets.sensitivity;
\r
14 import org.eclipse.jface.bindings.keys.KeyStroke;
\r
15 import org.eclipse.jface.bindings.keys.ParseException;
\r
16 import org.eclipse.jface.fieldassist.ContentProposalAdapter;
\r
17 import org.eclipse.jface.fieldassist.IContentProposal;
\r
18 import org.eclipse.jface.fieldassist.IContentProposalListener;
\r
19 import org.eclipse.jface.fieldassist.IContentProposalListener2;
\r
20 import org.eclipse.jface.fieldassist.TextContentAdapter;
\r
21 import org.eclipse.swt.widgets.Control;
\r
22 import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;
\r
23 import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;
\r
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
25 import org.simantics.databoard.Bindings;
\r
26 import org.simantics.db.ReadGraph;
\r
27 import org.simantics.db.Resource;
\r
28 import org.simantics.db.WriteGraph;
\r
29 import org.simantics.db.exception.DatabaseException;
\r
30 import org.simantics.jfreechart.chart.properties.VariableProposalProvider;
\r
32 public class VariableNameModifier extends TextModifyListenerImpl<Resource> {
\r
34 private boolean active;
\r
35 private Control control;
\r
36 private String variableNameRelationUri;
\r
37 private String indexUri;
\r
39 private char[] alphaNumericCharacters = {
\r
40 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö',
\r
41 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö',
\r
42 '1','2','3','4','5','6','7','8','9','0','.','_'};
\r
45 public VariableNameModifier(Control control, WidgetSupport support, String variableNameRelationUri, String indexUri) {
\r
46 this.variableNameRelationUri = variableNameRelationUri;
\r
47 this.indexUri = indexUri;
\r
49 this.control = control;
\r
52 KeyStroke keyStroke = null;
\r
54 keyStroke = KeyStroke.getInstance("Ctrl+Space");
\r
55 } catch (ParseException e1) {
\r
56 e1.printStackTrace();
\r
59 //SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support);
\r
60 VariableProposalProvider scpp = new VariableProposalProvider(control, support);
\r
61 scpp.setFiltering(true);
\r
63 ContentProposalAdapter adapter = new ContentProposalAdapter(
\r
64 control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters);
\r
65 adapter.setAutoActivationDelay(0);
\r
66 adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
\r
67 adapter.addContentProposalListener(new IContentProposalListener2() {
\r
70 public void proposalPopupOpened(ContentProposalAdapter adapter) {
\r
71 if(VariableNameModifier.this != null)
\r
72 VariableNameModifier.this.deactivate();
\r
76 public void proposalPopupClosed(ContentProposalAdapter adapter) {
\r
77 if(VariableNameModifier.this != null)
\r
78 VariableNameModifier.this.activate();
\r
82 adapter.addContentProposalListener(new IContentProposalListener() {
\r
85 public void proposalAccepted(IContentProposal proposal) {
\r
86 if(VariableNameModifier.this.control != null && !VariableNameModifier.this.control.isDisposed())
\r
87 VariableNameModifier.this.modifyText(new TrackedModifyEvent(VariableNameModifier.this.control, proposal.getContent()));
\r
96 public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException {
\r
98 graph.claimLiteral(resource, getVariableNameRelation(graph), text, Bindings.STRING);
\r
99 graph.deny(resource, getIndexRelation(graph));
\r
101 System.out.println("NÄHÄÄ");
\r
105 private Resource getVariableNameRelation(ReadGraph graph) throws DatabaseException {
\r
106 return graph.getResource(variableNameRelationUri);
\r
109 private Resource getIndexRelation(ReadGraph graph) throws DatabaseException {
\r
110 return graph.getResource(indexUri);
\r
113 public void deactivate() {
\r
117 public void activate() {
\r