• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / MooseIDE / 15922823259

27 Jun 2025 09:19AM UTC coverage: 66.79% (-0.2%) from 66.982%
15922823259

push

github

web-flow
Do not use fixed pharo versions

19810 of 29660 relevant lines covered (66.79%)

1.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.3
/src/MooseIDE-Meta/MiImportModelFromFileDialog.class.st
1
Class {
2
        #name : #MiImportModelFromFileDialog,
3
        #superclass : #MiImportModelDialog,
4
        #instVars : [
5
                'mooseModelDroplist',
6
                'filePathInput',
7
                'filePathButton',
8
                'modelNameInput',
9
                'rootFolderInput',
10
                'rootFolderButton',
11
                'modelFile',
12
                'importingContext',
13
                'customEntities',
14
                'customEntitiesButton',
15
                'allEntitiesButton'
16
        ],
17
        #category : #'MooseIDE-Meta-Import'
18
}
19

20
{ #category : #accessing }
21
MiImportModelFromFileDialog class >> defaultDirectory [
2✔
22

2✔
23
        ^ FileLocator home
2✔
24
]
2✔
25

26
{ #category : #accessing }
27
MiImportModelFromFileDialog class >> fullWindowExtent [
×
28

×
29
        ^ self windowExtent + (0 @ MiImportingContextPresenter windowExtent y)
×
30
]
×
31

32
{ #category : #opening }
33
MiImportModelFromFileDialog class >> open [
×
34

×
35
        <script>
×
36
        ^ super open
×
37
]
×
38

39
{ #category : #accessing }
40
MiImportModelFromFileDialog class >> title [
×
41

×
42
        ^ 'Import model from file'
×
43
]
×
44

45
{ #category : #accessing }
46
MiImportModelFromFileDialog class >> windowExtent [
×
47

×
48
        ^ 600 @ 250
×
49
]
×
50

51
{ #category : #action }
52
MiImportModelFromFileDialog >> closeEntitiesChoice [
2✔
53

2✔
54
        self layout: self defaultLayout.
2✔
55

2✔
56
        self withWindowDo: [ :window |
2✔
57
                window resize: self class windowExtent ]
2✔
58
]
2✔
59

60
{ #category : #initialization }
61
MiImportModelFromFileDialog >> connectPresenters [
2✔
62

2✔
63
        mooseModelDroplist whenSelectionChangedDo: [ 
2✔
64
                customEntitiesButton state ifTrue: [ self openEntitiesChoice ] ]
2✔
65
]
2✔
66

67
{ #category : #initialization }
68
MiImportModelFromFileDialog >> defaultLayout [
2✔
69

2✔
70
        | spacing size labelWidth |
2✔
71
        spacing := 10.
2✔
72
        size := 25.
2✔
73
        labelWidth := 120.
2✔
74
        ^ SpBoxLayout newTopToBottom
2✔
75
                  spacing: spacing;
2✔
76
                  add: (SpBoxLayout newLeftToRight
2✔
77
                                   spacing: spacing;
2✔
78
                                   add: 'File path:' width: labelWidth;
2✔
79
                                   add: filePathInput;
2✔
80
                                   add: filePathButton width: size;
2✔
81
                                   yourself)
2✔
82
                  height: size;
2✔
83
                  add: (SpBoxLayout newLeftToRight
2✔
84
                                   spacing: spacing;
2✔
85
                                   add: 'Model type:' width: labelWidth;
2✔
86
                                   add: mooseModelDroplist;
2✔
87
                                   yourself)
2✔
88
                  height: size;
2✔
89
                  add: (SpBoxLayout newLeftToRight
2✔
90
                                   spacing: spacing;
2✔
91
                                   add: 'Model name:' width: labelWidth;
2✔
92
                                   add: modelNameInput;
2✔
93
                                   add: self newNullPresenter width: size;
2✔
94
                                   yourself)
2✔
95
                  height: size;
2✔
96
                  add: (SpBoxLayout newLeftToRight
2✔
97
                                   spacing: spacing;
2✔
98
                                   add: 'Root folder (optional):' width: labelWidth;
2✔
99
                                   add: rootFolderInput;
2✔
100
                                   add: rootFolderButton width: size;
2✔
101
                                   yourself)
2✔
102
                  height: size;
2✔
103
                  add: (SpBoxLayout newLeftToRight
2✔
104
                                   spacing: spacing;
2✔
105
                                   add: 'Entity types:' width: labelWidth;
2✔
106
                                   add: allEntitiesButton;
2✔
107
                                   add: customEntitiesButton;
2✔
108
                                   yourself)
2✔
109
                  height: size;
2✔
110
                  yourself
2✔
111
]
2✔
112

113
{ #category : #private }
114
MiImportModelFromFileDialog >> getModelFile [
×
115

×
116
        | chosenFile |
×
117
        chosenFile := UIManager default
×
118
                              chooseExistingFileReference:
×
119
                              'Select your model source file'
×
120
                              extensions: FamixAbstractFileImporter knownExtensions
×
121
                              path:
×
122
                                      (modelFile
×
123
                                               ifNil: [ self class defaultDirectory ]
×
124
                                               ifNotNil: [
×
125
                                                       modelFile isFile
×
126
                                                               ifTrue: [ modelFile parent ]
×
127
                                                               ifFalse: [ modelFile ] ]).
×
128

×
129
        chosenFile ifNil: [ ^ self ].
×
130

×
131
        self tryUpdatingForModelFile:  chosenFile
×
132
]
×
133

134
{ #category : #private }
135
MiImportModelFromFileDialog >> getRootFolder [
×
136

×
137
        | chosenDirectory |
×
138
        chosenDirectory := UIManager default
×
139
                                   chooseDirectory:
×
140
                                   'Select your model root directory'
×
141
                                   path: (rootFolderInput text ifEmpty: [
×
142
                                                            modelFile
×
143
                                                                    ifNotNil: [ modelFile parent ]
×
144
                                                                    ifNil: [ self class defaultDirectory ] ])
×
145
                                                   asFileReference.
×
146

×
147
        chosenDirectory ifNotNil: [
×
148
                rootFolderInput text: chosenDirectory asFileReference pathString ]
×
149
]
×
150

151
{ #category : #action }
152
MiImportModelFromFileDialog >> handleDropFile: aFileReference [
2✔
153

2✔
154
        self tryUpdatingForModelFile: aFileReference
2✔
155
]
2✔
156

157
{ #category : #action }
158
MiImportModelFromFileDialog >> handleDropFileAndImport: aFileReference [
2✔
159

2✔
160
        self handleDropFile: aFileReference.
2✔
161

2✔
162
        self importModelThenCloseDialogWindow
2✔
163
]
2✔
164

165
{ #category : #action }
166
MiImportModelFromFileDialog >> importModel [
2✔
167

2✔
168
        | rootFolder mooseModel |
2✔
169

2✔
170
        "If rootFolderInput isEmpty, rootFolder will be nil. That is expected."
2✔
171
        rootFolderInput text ifNotEmpty: [ 
2✔
172
                rootFolder := rootFolderInput text asFileReference.
2✔
173
                rootFolder isDirectory ifFalse: [ 
2✔
174
                        self error: 'Your root folder path is incorrect' ] ].
2✔
175

2✔
176
        mooseModel := super importModel.
2✔
177
        mooseModel ifNotNil: [ mooseModel rootFolder: rootFolder ].
2✔
178
        ^ mooseModel
2✔
179
]
2✔
180

181
{ #category : #private }
182
MiImportModelFromFileDialog >> importerForFile [
2✔
183

2✔
184
        ^ (FamixAbstractFileImporter importerFor: modelFile) ifNil: [ 
2✔
185
                  self error: 'No importer found for this input file' ]
2✔
186
]
2✔
187

188
{ #category : #initialization }
189
MiImportModelFromFileDialog >> initializeEntitiesSelectionWidgets [
2✔
190

2✔
191
        allEntitiesButton := self newRadioButton
2✔
192
                                     label: 'All Entities';
2✔
193
                                     whenActivatedDo: [ 
2✔
194
                                             importingContext importMaximum ];
2✔
195
                                     yourself.
2✔
196

2✔
197
        customEntitiesButton := self newRadioButton
2✔
198
                                        label: 'Custom Entities';
2✔
199
                                        whenActivatedDo: [ self openEntitiesChoice ];
2✔
200
                                        whenDeactivatedDo: [ 
2✔
201
                                                self closeEntitiesChoice ];
2✔
202
                                        yourself.
2✔
203

2✔
204
        allEntitiesButton associatedRadioButtons: { customEntitiesButton }
2✔
205
]
2✔
206

207
{ #category : #initialization }
208
MiImportModelFromFileDialog >> initializeFilePathWidgets [
2✔
209

2✔
210
        filePathInput := self newTextInput
2✔
211
                                 placeholder:
2✔
212
                                         self class defaultDirectory asFileReference
2✔
213
                                                 pathString;
2✔
214
                                 whenSubmitDo: [ :modelPath |
2✔
215
                                         self newFilePathInput: modelPath ];
2✔
216
                                 help:
2✔
217
                                         'Tip: to choose a file in the directory of this Pharo image, type ''local/path/to/myFile.mse''';
2✔
218
                                 yourself.
2✔
219

2✔
220
        filePathInput eventHandler whenFocusLostDo: [
2✔
221
                self newFilePathInput: filePathInput text ].
2✔
222

2✔
223
        filePathButton := self newButton
2✔
224
                                  action: [ self getModelFile ];
2✔
225
                                  icon: (self iconNamed: #open)
2✔
226
]
2✔
227

228
{ #category : #initialization }
229
MiImportModelFromFileDialog >> initializeMooseModelDroplist [
2✔
230

2✔
231
        mooseModelDroplist := self newDropList
2✔
232
                                      items: MooseModel possibleModelsToImportFromFiles;
2✔
233
                                      whenSelectedItemChangedDo: [ :mooseModelClass |
2✔
234
                                              importingContext := mooseModelClass importingContextClass new
2✔
235
                                                                          importMaximum;
2✔
236
                                                                          yourself ];
2✔
237
                                      selectItem: FamixStModel;
2✔
238
                                      yourself
2✔
239
]
2✔
240

241
{ #category : #initialization }
242
MiImportModelFromFileDialog >> initializePresenters [
2✔
243

2✔
244
        super initializePresenters.
2✔
245
        self initializeMooseModelDroplist.
2✔
246
        self initializeFilePathWidgets.
2✔
247

2✔
248
        modelNameInput := self newTextInput placeholder: 'MooseModel'.
2✔
249
        rootFolderInput := self newTextInput.
2✔
250
        rootFolderButton := self newButton
2✔
251
                                    action: [ self getRootFolder ];
2✔
252
                                    icon: (self iconNamed: #open).
2✔
253

2✔
254
        self initializeEntitiesSelectionWidgets
2✔
255
]
2✔
256

257
{ #category : #'metamodel-guess' }
258
MiImportModelFromFileDialog >> metaModelForFile [
2✔
259

2✔
260
        mooseModelDroplist selectItem: (self importerForFile
2✔
261
                         findPossibleModelClassIn: mooseModelDroplist items
2✔
262
                         forFile: modelFile)
2✔
263
]
2✔
264

265
{ #category : #'instance creation' }
266
MiImportModelFromFileDialog >> newFilePathInput: aString [
×
267

×
268
        | file |
×
269
        aString ifEmpty: [ ^ self ].
×
270

×
271
        file := aString asFileReference.
×
272
        file isFile ifFalse: [ ^ self ].
×
273

×
274
        self tryUpdatingForModelFile: file
×
275
]
×
276

277
{ #category : #action }
278
MiImportModelFromFileDialog >> openEntitiesChoice [
×
279

×
280
        customEntities := self
×
281
                                  instantiate: MiImportingContextPresenter
×
282
                                  on: importingContext.
×
283

×
284
        self withWindowDo: [ :window | "The double #window is a patch for a spec bug. August 2024"
×
285
                window resize: self class fullWindowExtent ].
×
286

×
287
        self layout: (self defaultLayout
×
288
                         add: customEntities;
×
289
                         yourself).
×
290

×
291
        "Add style AFTER #layout: or it will be applied to all sub-layouts"
×
292
        customEntities addStyle: 'mooseContainer'
×
293
]
×
294

295
{ #category : #action }
296
MiImportModelFromFileDialog >> privateImportModel [
2✔
297

2✔
298
        | model importer |
2✔
299
        importer := self importerForFile.
2✔
300

2✔
301
        model := mooseModelDroplist selectedItem new.
2✔
302

2✔
303
        importer new
2✔
304
                model: model;
2✔
305
                inputFile: modelFile;
2✔
306
                runFilteredBy: importingContext.
2✔
307

2✔
308
        model name: (modelNameInput text ifEmpty: [ 'MooseModel' ]).
2✔
309

2✔
310
        ^ model
2✔
311
]
2✔
312

313
{ #category : #private }
314
MiImportModelFromFileDialog >> tryUpdatingForModelFile: aFile [
2✔
315

2✔
316
        [ self updateForModelFile: aFile ]
2✔
317
                on: Error
2✔
318
                do: [ :err |
2✔
319
                        err freeze.
2✔
320
                        MiImportErrorDialog new
2✔
321
                                label: 'Error: ' , err messageText;
2✔
322
                                onCancel: [ err debug ];
2✔
323
                                openDialog ]
2✔
324
]
2✔
325

326
{ #category : #private }
327
MiImportModelFromFileDialog >> updateForModelFile: aFile [
2✔
328
        "updates all fileds in the presenter according to new modelFile"
2✔
329

2✔
330
        modelFile := aFile.
2✔
331

2✔
332
        filePathInput text: modelFile asFileReference pathString.
2✔
333
        modelNameInput text: modelFile basenameWithoutExtension.
2✔
334
        rootFolderInput text: modelFile asFileReference parent pathString.
2✔
335

2✔
336
        self metaModelForFile
2✔
337
]
2✔
338

339
{ #category : #private }
340
MiImportModelFromFileDialog >> validateImportForm [
2✔
341
        "checks that required fields are properly filled in"
2✔
342
        filePathInput text ifEmpty: [ Error signal: 'Please choose an input file' ].
2✔
343
        filePathInput text asFileReference exists ifFalse: [ Error signal: 'File path not found' ].
2✔
344
        modelNameInput text ifEmpty: [ Error signal: 'Please name the model' ].
2✔
345
        rootFolderInput text asFileReference isDirectory ifFalse: [ Error signal: 'Root folder path is not a directory' ].
2✔
346
]
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc