Skip to content

Commit

Permalink
Merge pull request #1091 from moosetechnology/import-from-folders
Browse files Browse the repository at this point in the history
Add a command to be able to parser, import and install java projects
  • Loading branch information
jecisc authored Jun 19, 2024
2 parents 0384751 + 0b52092 commit c785ec1
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 83 deletions.
4 changes: 1 addition & 3 deletions src/MooseIDE-Meta/MiImportCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Class {
{ #category : #converting }
MiImportCommand class >> addToSpCommandGroup: aSpCommandGroup forSpecContext: aPresenter [

{
MiImportFromFileCommand.
MiImportFromSTCommand } do: [ :cmd |
self allSubclasses do: [ :cmd |
aSpCommandGroup register: ((cmd forSpecContext: aPresenter)
iconName: cmd defaultIconName;
yourself) ].
Expand Down
6 changes: 5 additions & 1 deletion src/MooseIDE-Meta/MiImportModelDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ Class {

{ #category : #opening }
MiImportModelDialog class >> open [
^ self subclassResponsibility

<script>
^ self new
openDialog;
yourself
]

{ #category : #accessing }
Expand Down
111 changes: 49 additions & 62 deletions src/MooseIDE-Meta/MiImportModelFromFileDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ MiImportModelFromFileDialog class >> fullWindowExtent [
MiImportModelFromFileDialog class >> open [

<script>
^ self new
openDialog;
yourself
^ super open
]

{ #category : #accessing }
Expand All @@ -54,10 +52,7 @@ MiImportModelFromFileDialog class >> windowExtent [
{ #category : #action }
MiImportModelFromFileDialog >> closeEntitiesChoice [

self withWindowDo: [ :window |
window extent: self class windowExtent ].

self layout: self simpleLayout
self withWindowDo: [ :window | window extent: self class windowExtent ]
]

{ #category : #initialization }
Expand All @@ -67,6 +62,52 @@ MiImportModelFromFileDialog >> connectPresenters [
customEntitiesButton state ifTrue: [ self openEntitiesChoice ] ]
]

{ #category : #initialization }
MiImportModelFromFileDialog >> defaultLayout [

| spacing size labelWidth |
spacing := 10.
size := 25.
labelWidth := 120.
^ SpBoxLayout newTopToBottom
spacing: spacing;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'File path:' width: labelWidth;
add: filePathInput;
add: filePathButton width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Model type:' width: labelWidth;
add: mooseModelDroplist;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Model name:' width: labelWidth;
add: modelNameInput;
add: self newNullPresenter width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Root folder (optional):' width: labelWidth;
add: rootFolderInput;
add: rootFolderButton width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Entity types:' width: labelWidth;
add: allEntitiesButton;
add: customEntitiesButton;
yourself)
height: size;
yourself
]

{ #category : #private }
MiImportModelFromFileDialog >> getModelFile [

Expand Down Expand Up @@ -186,12 +227,6 @@ MiImportModelFromFileDialog >> initializeFilePathWidgets [
icon: (self iconNamed: #open)
]

{ #category : #initialization }
MiImportModelFromFileDialog >> initializeLayout [

self layout: self simpleLayout
]

{ #category : #initialization }
MiImportModelFromFileDialog >> initializeMooseModelDroplist [

Expand All @@ -218,9 +253,7 @@ MiImportModelFromFileDialog >> initializePresenters [
action: [ self getRootFolder ];
icon: (self iconNamed: #open).

self initializeEntitiesSelectionWidgets.

self initializeLayout
self initializeEntitiesSelectionWidgets
]

{ #category : #'metamodel-guess' }
Expand Down Expand Up @@ -292,52 +325,6 @@ MiImportModelFromFileDialog >> privateImportModel [
^ model
]

{ #category : #initialization }
MiImportModelFromFileDialog >> simpleLayout [

| spacing size labelWidth |
spacing := 10.
size := 25.
labelWidth := 120.
^ SpBoxLayout newTopToBottom
spacing: spacing;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'File path:' width: labelWidth;
add: filePathInput;
add: filePathButton width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Model type:' width: labelWidth;
add: mooseModelDroplist;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Model name:' width: labelWidth;
add: modelNameInput;
add: self newNullPresenter width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Root folder (optional):' width: labelWidth;
add: rootFolderInput;
add: rootFolderButton width: size;
yourself)
height: size;
add: (SpBoxLayout newLeftToRight
spacing: spacing;
add: 'Entity types:' width: labelWidth;
add: allEntitiesButton;
add: customEntitiesButton;
yourself)
height: size;
yourself
]

{ #category : #private }
MiImportModelFromFileDialog >> updateForModelFile: aFile [
"updates all fileds in the presenter according to new modelFile"
Expand Down
121 changes: 121 additions & 0 deletions src/MooseIDE-Meta/MiImportModelFromFoldersDialog.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"
I am a presenter that will allow the user to select one or multiple folders and that will generate a json file for each one. Then I'll import those files in the model browser.
For now, I only work with Java and the latest version of VerveineJ. In the future we could add other languages.
"
Class {
#name : #MiImportModelFromFoldersDialog,
#superclass : #MiImportModelDialog,
#instVars : [
'description',
'foldersList',
'addFolderButton',
'addFoldersButton'
],
#category : #'MooseIDE-Meta-Import'
}

{ #category : #opening }
MiImportModelFromFoldersDialog class >> open [

<script>
^ super open
]

{ #category : #specs }
MiImportModelFromFoldersDialog class >> title [

^ 'Parse and import models from folders'
]

{ #category : #accessing }
MiImportModelFromFoldersDialog class >> windowExtent [

^ 600 @ 500
]

{ #category : #initialization }
MiImportModelFromFoldersDialog >> connectPresenters [

super connectPresenters.
self flag: #todo. "In the future UIManager should be removed to use the spec selection tool but it is not possible since we still run on Pharo 11"
addFolderButton action: [
(UIManager default chooseDirectory: 'Select a project folder to add.') ifNotNil: [ :folder |
foldersList items add: folder.
foldersList refresh ] ].
addFoldersButton action: [
(UIManager default chooseDirectory: 'Select a folder contaninig only project folders to add.') ifNotNil: [ :folder |
foldersList items addAll: folder directories.
foldersList refresh ] ]
]

{ #category : #layout }
MiImportModelFromFoldersDialog >> defaultLayout [

^ SpBoxLayout newTopToBottom
spacing: 3;
add: description;
add: foldersList;
add: (SpBoxLayout newLeftToRight
add: addFolderButton expand: false;
add: addFoldersButton expand: false;
yourself)
expand: false;
yourself
]

{ #category : #action }
MiImportModelFromFoldersDialog >> importModel [

^ self privateImportModel
]

{ #category : #initialization }
MiImportModelFromFoldersDialog >> initializePresenters [

super initializePresenters.
description := self newText.
foldersList := self newList.
addFolderButton := self newButton.
addFoldersButton := self newButton.

description
text: self userDescription;
beNotEditable.

foldersList items: OrderedCollection new.

addFolderButton
label: 'Add Folder';
iconName: #add.
addFoldersButton
label: 'Add Folders';
iconName: #add
]

{ #category : #action }
MiImportModelFromFoldersDialog >> privateImportModel [

^ MiMooseModelsWrapper models: (FamixJavaFoldersImporter importFolders: self selectedFolders)
]

{ #category : #accessing }
MiImportModelFromFoldersDialog >> selectedFolders [

^ foldersList items
]

{ #category : #accessing }
MiImportModelFromFoldersDialog >> userDescription [

^ 'I am in interface to easily parse projects and import the resulting models into Moose.
For now I am only working for Java projects. This might change in the future depending on the needs Moose users have.
Bellow, you can select folders containing each a project to parse with the latest version of VerveineJ. If you wish to use your own VerveineJ version, a setting is available.'
]

{ #category : #action }
MiImportModelFromFoldersDialog >> validateImportForm [

self selectedFolders ifEmpty: [ self error: 'Please select at least one folder.' ].
self selectedFolders do: [ :folder | folder ifAbsent: [ self error: 'Selected folder does not exist.' ] ]
]
34 changes: 17 additions & 17 deletions src/MooseIDE-Meta/MiImportModelFromSmalltalkDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ Class {
#category : #'MooseIDE-Meta-Import'
}

{ #category : #layout }
MiImportModelFromSmalltalkDialog class >> defaultLayout [

^ SpBoxLayout newTopToBottom
spacing: 10;
add: (SpBoxLayout newLeftToRight
add: 'Model name: ' width: 100;
add: #modelNameField;
yourself)
height: self inputTextHeight;
add: 'Select packages: ' height: self inputTextHeight;
add: #packagesSelector;
add: #advancedSettingsButton height: self buttonHeight;
yourself
]

{ #category : #accessing }
MiImportModelFromSmalltalkDialog class >> fullWindowExtent [

Expand All @@ -45,7 +29,7 @@ MiImportModelFromSmalltalkDialog class >> fullWindowExtent [
MiImportModelFromSmalltalkDialog class >> open [

<script>
^ self new openDialog
^ super open
]

{ #category : #specs }
Expand Down Expand Up @@ -97,6 +81,22 @@ MiImportModelFromSmalltalkDialog >> candidateClass [
^ invocationStrategyDroplist selectedItem
]

{ #category : #layout }
MiImportModelFromSmalltalkDialog >> defaultLayout [

^ SpBoxLayout newTopToBottom
spacing: 10;
add: (SpBoxLayout newLeftToRight
add: 'Model name: ' width: 100;
add: modelNameField;
yourself)
height: self class inputTextHeight;
add: 'Select packages: ' height: self class inputTextHeight;
add: packagesSelector;
add: advancedSettingsButton height: self class buttonHeight;
yourself
]

{ #category : #'advanced settings' }
MiImportModelFromSmalltalkDialog >> hideAdvancedSettings [

Expand Down
40 changes: 40 additions & 0 deletions src/MooseIDE-Meta/MiMooseModelsWrapper.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"
Most model importers of Moose IDE are importing one model and the browser got planned like this.
But it is possible to have an importer importing multiple models. I am here to make it compatible to import one or mulitple models.
"
Class {
#name : #MiMooseModelsWrapper,
#superclass : #Object,
#instVars : [
'models'
],
#category : #'MooseIDE-Meta-Import'
}

{ #category : #accessing }
MiMooseModelsWrapper class >> models: aCollection [

^ self new
models: aCollection;
yourself
]

{ #category : #initialization }
MiMooseModelsWrapper >> initialize [

super initialize.
models := OrderedCollection new
]

{ #category : #actions }
MiMooseModelsWrapper >> install [

models do: [ :model | model install ]
]

{ #category : #accessing }
MiMooseModelsWrapper >> models: aCollection [

models := aCollection
]
Loading

0 comments on commit c785ec1

Please sign in to comment.