Permalink
Browse files

[#126] Add custom metrics for DSE

Moved the custom metrics to a new mapping package fragment

Task-Url: http://github.com/roberthilbrich/assist-public/issues/126
  • Loading branch information...
RobertHilbrich committed Jul 11, 2018
1 parent b19aba5 commit d6dd85a38b5b76b86d53510f143e48df7402f00f
@@ -11,11 +11,9 @@
@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
ASSISTClasspathContainer c = new ASSISTClasspathContainer();
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { c },
null);
}
}
@@ -13,18 +13,14 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class ASSISTClasspathContainerPage extends WizardPage
implements IClasspathContainerPage, IClasspathContainerPageExtension {
public class ASSISTClasspathContainerPage extends WizardPage implements IClasspathContainerPage, IClasspathContainerPageExtension {
private IClasspathEntry selection;
private IJavaProject project;
private IClasspathEntry[] currentEntries;
public ASSISTClasspathContainerPage() {
super("PageOne");
setTitle("ASSIST Classpath Container");
setDescription("This container adds all necessary libraries for ASSIST projects");
}
@@ -41,22 +37,16 @@ public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
composite.setLayout(layout);
setControl(composite);
Label lblClickOnFinish = new Label(composite, SWT.NONE);
lblClickOnFinish.setText("Nothing to configure.");
}
@Override
public boolean finish() {
IClasspathEntry[] newEntries = new IClasspathEntry[currentEntries.length + 1];
System.arraycopy(currentEntries, 0, newEntries, 0, currentEntries.length);
newEntries[newEntries.length - 1] = JavaCore
.newContainerEntry(new Path("ch.hilbri.assist.gui.classpathContainer"));
newEntries[newEntries.length - 1] = JavaCore.newContainerEntry(new Path("ch.hilbri.assist.gui.classpathContainer"));
try {
project.setRawClasspath(newEntries, null);
@@ -76,5 +66,4 @@ public IClasspathEntry getSelection() {
public void setSelection(IClasspathEntry containerEntry) {
selection = containerEntry;
}
}
@@ -57,7 +57,6 @@ public boolean performFinish() {
try {
project.create(null);
project.open(null);
} catch (Exception e) { e.printStackTrace(); }
// Because we need a java project, we have to set the Java nature to the created project:
@@ -121,12 +120,12 @@ public boolean performFinish() {
cpEntries[4] = JavaRuntime.getDefaultJREContainerEntry();
javaProject.setRawClasspath(cpEntries, null);
} catch (Exception e) { e.printStackTrace(); }
// Create packages
try {
javaProject.getPackageFragmentRoot(mappingSourceFolder).createPackageFragment("metrics", false, null);
javaProject.getPackageFragmentRoot(dseSourceFolder).createPackageFragment("metrics.dse", false, null);
javaProject.getPackageFragmentRoot(mappingSourceFolder).createPackageFragment("metrics.mapping", false, null);
} catch (Exception e) {
e.printStackTrace();
}
@@ -15,53 +15,54 @@
public class NewMetricWizardPage extends NewTypeWizardPage {
public NewMetricWizardPage() {
super(true, "NewMetricWizardPage");
}
/**
* The wizard managing this wizard page must call this method
* during initialization with a corresponding selection.
*/
public void init(IStructuredSelection selection) {
IJavaElement jelem = getInitialJavaElement(selection);
initContainerPage(jelem);
initTypePage(jelem);
doStatusUpdate();
}
public NewMetricWizardPage() {
super(true, "NewMetricWizardPage");
}
/**
* The wizard managing this wizard page must call this method during
* initialization with a corresponding selection.
*/
public void init(IStructuredSelection selection) {
IJavaElement jelem = getInitialJavaElement(selection);
initContainerPage(jelem);
initTypePage(jelem);
doStatusUpdate();
}
/*
* Will find out the proper folder where to store the new metric
*
* --> needed to override default implementation in order to make sure that the metrics
* will be added to the mapping sub folder
*
* (non-Javadoc)
* @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#initContainerPage(org.eclipse.jdt.core.IJavaElement)
*/
/*
* Will find out the proper folder where to store the new metric
*
* --> needed to override default implementation in order to make sure that the
* metrics will be added to the mapping sub folder
*
* (non-Javadoc)
*
* @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#initContainerPage(org.
* eclipse.jdt.core.IJavaElement)
*/
@Override
protected void initContainerPage(IJavaElement elem) {
IPackageFragmentRoot initRoot= null;
IPackageFragmentRoot initRoot = null;
if (elem != null) {
initRoot= JavaModelUtil.getPackageFragmentRoot(elem);
initRoot = JavaModelUtil.getPackageFragmentRoot(elem);
try {
if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
IJavaProject jproject= elem.getJavaProject();
IJavaProject jproject = elem.getJavaProject();
if (jproject != null) {
initRoot= null;
if (jproject.exists()) {
IPackageFragmentRoot[] roots= jproject.getPackageFragmentRoots();
for (int i= 0; i < roots.length; i++) {
if ((roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) &&
roots[i].getElementName().equals("Mapping")) {
initRoot= roots[i];
break;
}
initRoot = null;
if (jproject.exists()) {
IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if ((roots[i].getKind() == IPackageFragmentRoot.K_SOURCE)
&& roots[i].getElementName().equals("Mapping")) {
initRoot = roots[i];
break;
}
}
}
if (initRoot == null) {
initRoot= jproject.getPackageFragmentRoot(jproject.getResource());
initRoot = jproject.getPackageFragmentRoot(jproject.getResource());
}
}
}
@@ -71,34 +72,30 @@ protected void initContainerPage(IJavaElement elem) {
}
setPackageFragmentRoot(initRoot, true);
}
private void doStatusUpdate() {
// define the components for which a status is desired
IStatus[] status= new IStatus[] {
fContainerStatus,
isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
};
updateStatus(status);
}
private void doStatusUpdate() {
// define the components for which a status is desired
IStatus[] status = new IStatus[] { fContainerStatus,
isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus, };
updateStatus(status);
}
protected void handleFieldChanged(String fieldName) {
super.handleFieldChanged(fieldName);
doStatusUpdate();
}
protected void handleFieldChanged(String fieldName) {
super.handleFieldChanged(fieldName);
doStatusUpdate();
}
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite= new Composite(parent, SWT.NONE);
int nColumns= 4;
GridLayout layout= new GridLayout();
layout.numColumns= nColumns;
composite.setLayout(layout);
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
int nColumns = 4;
GridLayout layout = new GridLayout();
layout.numColumns = nColumns;
composite.setLayout(layout);
// Create the standard input fields
createTypeNameControls(composite, nColumns);
createContainerControls(composite, nColumns);
setControl(composite);
}
// Create the standard input fields
createTypeNameControls(composite, nColumns);
createContainerControls(composite, nColumns);
setControl(composite);
}
}

0 comments on commit d6dd85a

Please sign in to comment.