提交 11d20176 编写于 作者: J jurgen

Add maven artifact as lib

上级 0eb859ed
......@@ -151,6 +151,11 @@ public class DriverFileDescriptor implements DBPDriverFile
return path.startsWith(FILE_SOURCE_MAVEN);
}
public boolean isMavenArtifactResolved() {
MavenArtifact artifact = getMavenArtifact();
return artifact != null && artifact.getActiveLocalVersion() != null;
}
private String getRepositoryPath() {
return path.substring(FILE_SOURCE_REPO.length());
}
......
......@@ -27,9 +27,9 @@ public class MavenArtifactReference
private static final String DEFAULT_MAVEN_VERSION = VERSION_PATTERN_RELEASE;
private final String groupId;
private final String artifactId;
private final String version;
private String groupId;
private String artifactId;
private String version;
public MavenArtifactReference(String groupId, String artifactId, String version) {
this.groupId = groupId;
......@@ -65,11 +65,33 @@ public class MavenArtifactReference
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getArtifactId() {
return artifactId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getPath() {
return groupId + ":" + artifactId + ":" + version;
}
@Override
public String toString() {
return getPath();
}
}
......@@ -292,6 +292,8 @@ public class DriverEditDialog extends HelpEnabledDialog
File localFile = lib.getLocalFile();
if (localFile != null && localFile.exists()) {
cell.setForeground(null);
} else if (lib.isMavenArtifact() && !lib.isMavenArtifactResolved()) {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
} else {
cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
}
......@@ -426,7 +428,11 @@ public class DriverEditDialog extends HelpEnabledDialog
{
EditMavenArtifactDialog fd = new EditMavenArtifactDialog(getShell(), null);
if (fd.open() == IDialogConstants.OK_ID) {
libList.add(new DriverFileDescriptor(
driver,
DBPDriverFile.FileType.jar,
DriverFileDescriptor.FILE_SOURCE_MAVEN + fd.getArtifact().getPath()));
changeLibContent();
}
}
});
......
......@@ -20,28 +20,34 @@ package org.jkiss.dbeaver.ui.dialogs.driver;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.registry.maven.MavenArtifact;
import java.util.StringTokenizer;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.registry.maven.MavenArtifactReference;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.CommonUtils;
/**
* EditMavenArtifactDialog
*/
class EditMavenArtifactDialog extends Dialog
{
private MavenArtifact artifact;
private MavenArtifactReference artifact;
private Text groupText;
private Text artifactText;
private Combo versionText;
public EditMavenArtifactDialog(Shell shell, MavenArtifact artifact)
public EditMavenArtifactDialog(Shell shell, MavenArtifactReference artifact)
{
super(shell);
this.artifact = artifact;
this.artifact = artifact == null ? new MavenArtifactReference("", "", MavenArtifactReference.VERSION_PATTERN_RELEASE) : artifact;
}
public MavenArtifactReference getArtifact() {
return artifact;
}
@Override
......@@ -53,40 +59,57 @@ class EditMavenArtifactDialog extends Dialog
@Override
protected Control createDialogArea(Composite parent)
{
getShell().setText(CoreMessages.dialog_view_classpath_title);
getShell().setText("Edit Maven Artifact");
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
group.setLayoutData(gd);
Composite composite = (Composite) super.createDialogArea(parent);
((GridLayout)composite.getLayout()).numColumns = 2;
{
ListViewer libsTable = new ListViewer(group, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
libsTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = 200;
String classPath = System.getProperty("java.class.path"); //$NON-NLS-1$
StringTokenizer st = new StringTokenizer(classPath, ";"); //$NON-NLS-1$
while (st.hasMoreTokens()) {
libsTable.getList().add(st.nextToken());
}
/*
for (DriverLibraryDescriptor lib : driver.getLibraries()) {
libsTable.getList().add(lib.getLocalFile().getPath());
groupText = UIUtils.createLabelText(composite, "Group Id", artifact.getGroupId());
groupText.setLayoutData(gd);
artifactText = UIUtils.createLabelText(composite, "Artifact Id", artifact.getArtifactId());
artifactText.setLayoutData(gd);
versionText = UIUtils.createLabelCombo(composite, "Version", SWT.DROP_DOWN | SWT.BORDER);
versionText.setLayoutData(gd);
versionText.setText(artifact.getVersion());
versionText.add(MavenArtifactReference.VERSION_PATTERN_RELEASE);
versionText.add(MavenArtifactReference.VERSION_PATTERN_LATEST);
ModifyListener ml = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateButtons();
}
*/
}
return group;
};
groupText.addModifyListener(ml);
artifactText.addModifyListener(ml);
versionText.addModifyListener(ml);
return composite;
}
@Override
protected void createButtonsForButtonBar(Composite parent)
{
createButton(
parent,
IDialogConstants.OK_ID,
IDialogConstants.OK_LABEL,
true);
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
updateButtons();
}
private void updateButtons() {
getButton(IDialogConstants.OK_ID).setEnabled(
!CommonUtils.isEmpty(groupText.getText()) &&
!CommonUtils.isEmpty(artifactText.getText()) &&
!CommonUtils.isEmpty(versionText.getText())
);
}
@Override
protected void okPressed() {
artifact.setGroupId(groupText.getText());
artifact.setArtifactId(artifactText.getText());
artifact.setVersion(versionText.getText());
super.okPressed();
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册