Пример #1
0
 def _listenSelection(self):
   thebrowser = self.browser
   from org.modelio.api.modelio import Modelio
   from org.modelio.api.app.navigation import INavigationListener
   class SelectionListener(INavigationListener):
     #def navigateTo(self):
     #  thebrowser.setText("selection is "+str(target.getName()))
     pass
   Modelio.getInstance().getNavigationService().addNavigationListener(SelectionListener())
Пример #2
0
    def _listenSelection(self):
        thebrowser = self.browser
        from org.modelio.api.modelio import Modelio
        from org.modelio.api.app.navigation import INavigationListener

        class SelectionListener(INavigationListener):
            #def navigateTo(self):
            #  thebrowser.setText("selection is "+str(target.getName()))
            pass

        Modelio.getInstance().getNavigationService().addNavigationListener(
            SelectionListener())
Пример #3
0
def startup():
    print "The CoExplorer is starting ..."

    #---- add the "lib" directory to the path
    # The code below compute this path and put it in the variable SCRIPT_LIBRARY_DIRECTORY.
    # Feel free to change it if necessary. Currently the "lib" directory is search within
    # the directory of this very file, but if you may want to change its location you can
    # uncomment the line defining SCRIPT_LIBRARY_DIRECTORY with an absolute path
    try:
        from org.modelio.api.modelio import Modelio
        orgVersion = True
    except:
        orgVersion = False
    import os
    import sys
    WORKSPACE_DIRECTORY = Modelio.getInstance().getContext().getWorkspacePath(
    ).toString()
    if orgVersion:
        MACROS_DIRECTORY = os.path.join(WORKSPACE_DIRECTORY, 'macros')
    else:
        MACROS_DIRECTORY = os.path.join(WORKSPACE_DIRECTORY, '.config',
                                        'macros')
    SCRIPT_LIBRARY_DIRECTORY = os.path.join(MACROS_DIRECTORY, 'lib')
    # Uncomment this line and adjust it if you want to put the "lib" directory somewhere else
    # SCRIPT_LIBRARY_DIRECTORY = "C:\\MODELIO3-WORKSPACE\\macros\\lib"
    sys.path.extend([MACROS_DIRECTORY, SCRIPT_LIBRARY_DIRECTORY])
    print "   Current workspace is " + WORKSPACE_DIRECTORY
    print "   " + MACROS_DIRECTORY + " added to script path"
    print "   " + SCRIPT_LIBRARY_DIRECTORY + " added to script path"
Пример #4
0
def startup():
  print "The CoExplorer is starting ..."

  #---- add the "lib" directory to the path
  # The code below compute this path and put it in the variable SCRIPT_LIBRARY_DIRECTORY. 
  # Feel free to change it if necessary. Currently the "lib" directory is search within
  # the directory of this very file, but if you may want to change its location you can
  # uncomment the line defining SCRIPT_LIBRARY_DIRECTORY with an absolute path
  try:
    from org.modelio.api.modelio import Modelio
    orgVersion = True
  except:
    orgVersion = False
  import os
  import sys 
  WORKSPACE_DIRECTORY=Modelio.getInstance().getContext().getWorkspacePath().toString()
  if orgVersion:
    MACROS_DIRECTORY=os.path.join(WORKSPACE_DIRECTORY,'macros')
  else:
    MACROS_DIRECTORY=os.path.join(WORKSPACE_DIRECTORY,'.config','macros')
  SCRIPT_LIBRARY_DIRECTORY=os.path.join(MACROS_DIRECTORY,'lib')
  # Uncomment this line and adjust it if you want to put the "lib" directory somewhere else
  # SCRIPT_LIBRARY_DIRECTORY = "C:\\MODELIO3-WORKSPACE\\macros\\lib"
  sys.path.extend([MACROS_DIRECTORY,SCRIPT_LIBRARY_DIRECTORY])
  print "   Current workspace is "+WORKSPACE_DIRECTORY
  print "   "+MACROS_DIRECTORY+" added to script path"
  print "   "+SCRIPT_LIBRARY_DIRECTORY+" added to script path"
Пример #5
0
def getImageFromType(metaclass):
  """ return the image corresponding to a metaclass or None if no image is available
  """
  try:
    return Modelio.getInstance().getImageService().getMetaclassImage(metaclass)
  except:
    return NAVIGATOR_IMAGE_PROVIDER.getImageFromType(metaclass)
Пример #6
0
def search(metaclasses, regexp, options):
  print "Searching ..."
  rawResults = HashSet()
  session = Modelio.getInstance().getModelingSession()
  
  #--- (1) Add all instances of selected metaclasses 
  for metaclass in metaclasses:
    print "  searching for instance of metaclass ",metaclass.getSimpleName()," ... ",
    metaclassInstances = session.findByClass(metaclass)
    print unicode(len(metaclassInstances)),"elements found"
    rawResults.addAll(metaclassInstances)
  # remove predefined types
  predefTypes = Modelio.getInstance().getModelingSession().getModel().getUmlTypes().getBOOLEAN().getOwner()
  rawResults.remove(predefTypes)
  rawResults.remove(predefTypes.getOwner())
  print "  ==>",unicode(len(rawResults)),"elements found (primitive types excluded)"
  
  #--- (2) Check for name matching
  filteredResults = []
  try:
    if options[0] == 1:
      p = Pattern.compile(regexp)
      for result in rawResults:
        name = result.getName()
        if (p.matcher(name).matches()):
          filteredResults.append(result)
    else:
      for result in rawResults:
        if result.getName().find(regexp) != -1:
          filteredResults.append(result)
  except PatternSyntaxException:
    messageBox("The entered regular expression: '"+regexp+"' has a syntax error.")
  except IllegalArgumentException:
    messageBox("Illegal Argument Exception.")
  print "  "+unicode(len(filteredResults))+" elements selected after name filtering"
  
  #--- (3) sort results by name
  filteredResults.sort(key=lambda x:x.getName())
  return filteredResults
Пример #7
0
    def __registerModelioProperties(cls):

        def getModelioHome():
            # noinspection PyUnresolvedReferences
            eclipse_home = sys.registry.getProperty('eclipse.home.location')
            import urlparse
            import urllib
            return urllib.url2pathname(urlparse.urlsplit(eclipse_home).path)

        def getModelioImportFile():
            return pymodelio.core.misc.findFile(
                'initengine.py',cls.MODELIO_HOME)

        def getJythonJarFile():
            return pymodelio.core.misc.findFile('jython.jar',cls.MODELIO_HOME)


        # noinspection PyUnresolvedReferences
        from org.modelio.api.modelio import Modelio
        context = Modelio.getInstance().getContext()
        workspaceDir = context.getWorkspacePath().toString()
        cls.MODELIO_WORKSPACE = workspaceDir
        version = context.getVersion().toString()
        cls.MODELIO_VERSION_FULL= version
        cls.MODELIO_VERSION_SIMPLE = ".".join(version.split(".")[0:2])
        cls.MODELIO_HOME = getModelioHome()
        cls.MODELIO_IMPORT_FILE = getModelioImportFile()
        cls.MODELIO_JYTHON_JAR_FILE = getJythonJarFile()
        cls.MODELIO_WEB = 'http://modelio.org'
        cls.MODELIO_WEB_USER_MANUALS = \
            'http://modelio.org/documentation/user-manuals.html'
        cls.MODELIO_WEB_DOC_ROOT = "http://modelio.org/documentation"
        cls.MODELIO_WEB_DOC_JAVADOC = \
            cls.MODELIO_WEB_DOC_ROOT+'/javadoc-' + cls.MODELIO_VERSION_SIMPLE
        cls.MODELIO_WEB_DOC_METAMODEL =\
            cls.MODELIO_WEB_DOC_ROOT+'/metamodel-'+cls.MODELIO_VERSION_SIMPLE
Пример #8
0
def setSelection(elementOrElements):
    """ Change the current selection with an element or a list of elements
  """
    Modelio.getInstance().getNavigationService().fireNavigate(
        elementOrElements)
Пример #9
0
def theEditionService():
    """ The edition service
  """
    return Modelio.getInstance().getEditionService()
Пример #10
0
def theDiagramService():
    return Modelio.getInstance().getDiagramService()
Пример #11
0
def setSelection(elementOrElements):
  """ Change the current selection with an element or a list of elements
  """
  Modelio.getInstance().getNavigationService().fireNavigate(elementOrElements)
Пример #12
0
def theDiagramService():
  return Modelio.getInstance().getDiagramService()
Пример #13
0
def isFragmentDeployed(name):
    for f in Modelio.getInstance().getMetamodelService().getMetamodel(
    ).getFragments():
        if name == f.getName():
            return True
    return False
Пример #14
0
 def selectionChanged(self, event):
   selection = event.getSelection()
   element = selection.getFirstElement()
   print element
   if (element != None):
     Modelio.getInstance().getNavigationService().fireNavigate(element)
Пример #15
0
  from org.modelio.api.meta import IMetamodelService
  from org.modelio.metamodel.uml.infrastructure import ModelElement
  MODELELEMENT_METACLASS = ModelElement
  from org.modelio.metamodel.uml.infrastructure import ModelTree
  MODELTREE_METACLASS = ModelTree
  from org.modelio.metamodel.uml.statik import NameSpace
  NAMESPACE_METACLASS = NameSpace  
else:
  from com.modeliosoft.modelio.api.ui.text import TextWrapperForIElement
  from com.modeliosoft.modelio.api.meta import IMetamodelService
  from com.modeliosoft.modelio.api.model.uml.statik import IModelTree
  MODELELEMENT_METACLASS = IModelElement
  MODELTREE_METACLASS = IModelTree
  NAMESPACE_METACLASS = INameSpace
  
METAMODEL_SERVICE = Modelio.getInstance().getMetamodelService()
IMAGE_SERVICE = Modelio.getInstance().getImageService()


def getMetaclassFromElement(element):
  if orgVersion:
    name = element.getMClass().getName()
  else:
    name = element.metaclassName
  return METAMODEL_SERVICE.getMetaclass(name)

def getMetaclassImageFromMetaclass(metaclass):
  return IMAGE_SERVICE.getMetaclassImage(metaclass)

def getMetaclassImageFromElement(element):
  metaclass = getMetaclassFromElement(element)
Пример #16
0
# important as these modules instrument java classes
# noinspection PyUnresolvedReferences
import pyalaocl.modelio # DO NOT REMOVE

# noinspection PyUnresolvedReferences
from org.eclipse.core.runtime import IAdaptable




# noinspection PyUnresolvedReferences
from org.modelio.metamodel.uml.infrastructure import Element as ModelioElement
# noinspection PyUnresolvedReferences
from org.modelio.api.modelio import Modelio

MODELIO = Modelio.getInstance()
METAMODEL_SERVICE = MODELIO.getMetamodelService()
MODELING_SESSION = MODELIO.getModelingSession()

# useful for python introspection
def _isPythonBuiltin(name):
    return name.startswith('__') and name.endswith('__')


def getMetaclassFromName(metaclassName):
    """ get the Modelio Metaclass inheriting from ModelioElement and
       corresponding to the given name of a metaclass.
       Return None if the name provided is not the name of a metaclass
    """
    return METAMODEL_SERVICE.getMetaclass(metaclassName)
                + ")), Internal_Events => ((Type => regular, name => O_"
                + streamName
                + ", Timing_Requirements => (Type => Hard_Global_Deadline, Deadline => "
                + getRequestStreamDeadline(port)
                + ", Referenced_Event => E_"
                + streamName
                + "))), Event_Handlers => ((Type => Activity, Input_Event => E_"
                + streamName
                + ", Output_Event => O_"
                + streamName
                + ", Activity_Operation => "
                + getProgramInstName(programInst)
                + "_Call, Activity_Server => "
                + getProgramInstName(programInst)
                + "_SS)));"
            )

from org.modelio.api.modelio import Modelio

jdesigner = Modelio.getInstance().getModuleService().getPeerModule("JavaDesigner")

# generate app context file
javaConfiguration = jdesigner.getConfiguration()
genPath = javaConfiguration.getParameterValue("GenerationPath").replace(
    u"$(Project)", javaConfiguration.getProjectSpacePath().toString()
)

f = open(genPath + "/mast.txt", "w")
f.write(text)
f.close()
Пример #18
0
def theSession():
    """ Return the current session.
      () -> IModelingSession 
  """
    return Modelio.getInstance().getModelingSession()
except NameError:
    input_path = '/media/sf_Dropbox/Projects/JUNIPER/WP5/libdag/xml/taskset.xml'

import subprocess
try:
    output = subprocess.check_output([dag_path, input_path])
except CalledProcessError as e:
    output = e.output
    
    from org.eclipse.swt.widgets import MessageBox
    from org.eclipse.swt.widgets import Display
    from org.eclipse.swt import SWT
    
    m = MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_ERROR|SWT.OK)
    m.setText("JuniperIDE")
    m.setMessage("Error running Schedulability analyser!")
    m.open()
    
from tempfile import NamedTemporaryFile
output_file = NamedTemporaryFile(delete=False)
output_file.write(output)
output_file.close()

from org.modelio.api.modelio import Modelio
from org.modelio.api.editor import EditorType
from java.io import File
Modelio.getInstance().getEditionService().openEditor(selectedElements.get(0), File(output_file.name), EditorType.TXTEditor, True)

import os
os.remove(output_file.name)
Пример #20
0
def getModelioSimpleVersion():
    v = Modelio.getInstance().getContext().getVersion()
    return '%s.%s' % (v.getMajorVersion(),v.getMinorVersion())
Пример #21
0
 def _theSession():
     return Modelio.getInstance().getModelingSession()
Пример #22
0
def theEditionService():  
  """ The edition service
  """
  return Modelio.getInstance().getEditionService()
Пример #23
0
def theDiagramService():
    """
    https://www.modelio.org/documentation/javadoc-3.3/index.html?overview-summary.html
    """
    return Modelio.getInstance().getDiagramService()
Пример #24
0
def theSession():
  """ Return the current session.
      () -> IModelingSession 
  """
  return Modelio.getInstance().getModelingSession()
Пример #25
0
      
def getFullName(element):
  """ Return full qualified name of an element
  """
  name = element.getName()
  if (isinstance(element,ModelioModelTree)):
    owner = element.getOwner()
    if (owner is not None):
      name = getFullName(owner) + "." + name
  elif (isinstance(element, ModelioElement)):
    owner = element.getCompositionOwner()
    if (owner is not None):
      name = getFullName(owner) + "." + name
  return name

DIAGRAM_SERVICE = Modelio.getInstance().getDiagramService()
ALL_DIAGRAMS = Modelio.getInstance().getModelingSession().findByClass(ModelioAbstractDiagram)
ALL_DIAGRAM_HANDLES = map(DIAGRAM_SERVICE.getDiagramHandle,ALL_DIAGRAMS)

def getDisplayingDiagrams(element):
  """ Return all diagrams displaying the element in a graphical form
  """
  selectedDiagrams = []
  for diagramHandle in ALL_DIAGRAM_HANDLES:
    graphicElements = diagramHandle.getDiagramGraphics(element)
    if len(graphicElements)!=0:
      selectedDiagrams.append(diagramHandle.getDiagram())
  return selectedDiagrams

def getDiagramSignature(diagram):
  return getFullName(diagram)+" : "+getMetaClassName(diagram)
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This module contains some helper functions in manipulating UML and JavaDesigner modules

from org.modelio.api.modelio import Modelio
modelingSession = Modelio.getInstance().getModelingSession()
#
# Manipulating tag values
#

def getTagValues(el, tagName):
    lists = [y.getActual() for y in el.getTag() if y.getDefinition().getName() == tagName]
    values = [x.getValue() for list in lists for x in list]
    return values

def getTagValue(el, tagName, default=None):
    list = getTagValues(el, tagName)
    if len(list)>0:
        return list[0]
    else:
        return default
Пример #27
0
# check if this is modelio 3 because the API has changed
try:
  from org.modelio.api.modelio import Modelio
  orgVersion = True
except:
  from com.modeliosoft.modelio.api.modelio import Modelio
  orgVersion = False
from org.eclipse.core.runtime import IAdaptable
from misc import reject,excluding,exists,isEmpty,notEmpty,isList,forAll,isString
from misc import HtmlWindow,TreeWindow,ImageProvider
from misc import getWebPage




MODELIO = Modelio.getInstance()
METAMODEL_SERVICE = MODELIO.getMetamodelService()
MODELING_SESSION  = MODELIO.getModelingSession()

if orgVersion:
  from org.modelio.metamodel.uml.infrastructure import Element as ModelioElement
else:
  from com.modeliosoft.modelio.api.model.uml.infrastructure import IElement as ModelioElement

# useful for python introspection
def _isPythonBuiltin(name): 
  return name.startswith('__') and name.endswith('__')

def getMetaclassFromName(metaclassname):
  """ get the Modelio Metaclass inheriting from ModelioElement and 
     corresponding to the given name of a metaclass.