/
GenerateAntFileHandler.java
67 lines (51 loc) · 1.88 KB
/
GenerateAntFileHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.opcoach.genmodeladdon.handlers;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import com.opcoach.genmodeladdon.core.GenerateAntFileForCodeGeneration;
import com.opcoach.genmodeladdon.core.GenerateCommon;
import com.opcoach.genmodeladdon.core.genmodel.GMAGenModel;
import jakarta.inject.Named;
public class GenerateAntFileHandler extends GenerateParentHandler
{
@Execute
@Override
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell,
@Named(IServiceConstants.ACTIVE_SELECTION) GMAGenModel gm)
{
GenerateAntFileForCodeGeneration gen = new GenerateAntFileForCodeGeneration();
IProject proj = GenerateCommon.getProject(gm);
File f = gen.getAntFile(proj);
boolean createFile = true;
if (f.exists())
{
createFile = MessageDialog.openConfirm(parentShell, "This ant file exists",
"Do you really want to override this file " + GenerateAntFileForCodeGeneration.ANT_FILENAME + " ?");
}
if (createFile)
{
String modelName = GenerateCommon.getModelName(gm);
String modelPath = GenerateCommon.getModelPath(gm);
try
{
gen.generateAntFile(modelPath, modelName, proj);
} catch (IOException e)
{
MessageDialog.openWarning(
parentShell,
"Ant file could not be generated",
"It was not possible to generate the file : " + GenerateAntFileForCodeGeneration.ANT_FILENAME + "\n\n The reason is : \n\n"
+ e.getMessage());
} catch (CoreException e)
{
MessageDialog.openWarning(parentShell, "Could not refresh the workspace",
"It was not possible refresh the workspace. You should do it by hand");
}
}
}
}