-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core Editor: Implement viewer for data sources
- Loading branch information
1 parent
80a87ef
commit 39cfe79
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/DataSourceViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.shade.decima.ui.data.viewer.binary; | ||
|
||
import com.shade.decima.model.app.Project; | ||
import com.shade.decima.model.rtti.RTTICoreFile; | ||
import com.shade.decima.model.rtti.RTTIType; | ||
import com.shade.decima.model.rtti.objects.RTTIObject; | ||
import com.shade.decima.model.rtti.path.RTTIPath; | ||
import com.shade.decima.model.rtti.types.java.HwDataSource; | ||
import com.shade.decima.ui.data.ValueController; | ||
import com.shade.decima.ui.data.ValueViewer; | ||
import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; | ||
import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; | ||
import com.shade.decima.ui.data.registry.ValueViewerRegistration; | ||
import com.shade.platform.ui.editors.Editor; | ||
import com.shade.util.NotNull; | ||
import com.shade.util.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
@ValueViewerRegistration({ | ||
@Selector(type = @Type(type = HwDataSource.class)) | ||
}) | ||
public class DataSourceViewer implements ValueViewer { | ||
@NotNull | ||
@Override | ||
public JComponent createComponent() { | ||
return new BinaryViewerPanel(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public void refresh(@NotNull JComponent component, @NotNull ValueController<?> controller) { | ||
final var panel = (BinaryViewerPanel) component; | ||
panel.setController(new ProxyValueController((ValueController<RTTIObject>) controller)); | ||
} | ||
|
||
private record ProxyValueController(@NotNull ValueController<RTTIObject> controller) implements ValueController<byte[]> { | ||
@NotNull | ||
@Override | ||
public RTTIType<byte[]> getValueType() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public RTTIPath getValuePath() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getValueLabel() { | ||
return controller.getValueLabel(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Editor getEditor() { | ||
return controller.getEditor(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Project getProject() { | ||
return controller.getProject(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public RTTICoreFile getCoreFile() { | ||
return controller.getCoreFile(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public byte[] getValue() { | ||
final Project project = controller.getProject(); | ||
final HwDataSource dataSource = controller.getValue().cast(); | ||
|
||
try { | ||
return dataSource.getData(project.getPackfileManager()); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} | ||
} |